-
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathpd_orders.cpp
More file actions
155 lines (122 loc) · 4.13 KB
/
Copy pathpd_orders.cpp
File metadata and controls
155 lines (122 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*PGR-GNU*****************************************************************
File: pd_orders.cpp
Copyright (c) 2016-2026 pgRouting developers
Mail: project@pgrouting.org
------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
#include "vrp/pd_orders.hpp"
#include <vector>
#include <memory>
#include <utility>
#include <string>
#include "vrp/pickDeliver.hpp"
#include "vrp/dnode.hpp"
namespace pgrouting {
namespace vrp {
Pgr_pickDeliver* PD_Orders::problem;
PD_Orders::PD_Orders(
const std::vector<Orders_t> &pd_orders
) {
build_orders(pd_orders);
}
void
PD_Orders:: add_order(
const Orders_t &order,
const Vehicle_node &pick,
const Vehicle_node &drop) {
/*
* add into an order
*/
m_orders.push_back(
Order(m_orders.size(), order.id,
pick,
drop));
}
void
PD_Orders::build_orders(
const std::vector<Orders_t> &pd_orders
) {
for (const auto &order : pd_orders) {
/*
* SAMPLE CORRECT INFORMATION
*
* id | demand | pick_x | pick_y | pick_open_t | pick_close_t | pick_service_t | deliver_x | deliver_y | deliver_open_t | deliver_open_t | deliver_close_t | deliver_service_t
* 1 | 10 | 35 | 69 | 448 | 505 | 90 | 45 | 68 | 912 | 967 | 90 | 35
*/
/*
* matrix version
*/
if (!problem->get_cost_matrix().has_id(order.pick_node_id)) {
throw std::make_pair(std::string("Unable to find node on matrix"), order.pick_node_id);
}
if (!problem->get_cost_matrix().has_id(order.deliver_node_id)) {
throw std::make_pair(std::string("Unable to find node on matrix"), order.deliver_node_id);
}
Vehicle_node pickup({problem->get_nodes().size(), order, Tw_node::NodeType::kPickup});
problem->add_node(pickup);
Vehicle_node delivery({problem->get_nodes().size(), order, Tw_node::NodeType::kDelivery});
problem->add_node(delivery);
add_order(order, pickup, delivery);
} // for (creating orders)
}
Order&
PD_Orders::operator[](size_t i) {
pgassert(i < m_orders.size());
return m_orders[i];
}
const Order&
PD_Orders::operator[](size_t i) const {
pgassert(i < m_orders.size());
return m_orders[i];
}
void
PD_Orders::set_compatibles(double speed) {
for (auto &I : m_orders) {
for (const auto &J : m_orders) {
I.set_compatibles(J, speed);
}
}
}
size_t
PD_Orders::find_best_J(
Identifiers<size_t> &within_this_set) const {
pgassert(!within_this_set.empty());
auto best_order = within_this_set.front();
size_t max_size = 0;
for (auto o : within_this_set) {
auto size_J = m_orders[o].subsetJ(within_this_set).size();
if (max_size < size_J) {
max_size = size_J;
best_order = o;
}
}
return best_order;
}
size_t
PD_Orders::find_best_I(
Identifiers<size_t> &within_this_set) const {
pgassert(!within_this_set.empty());
auto best_order = within_this_set.front();
size_t max_size = 0;
for (auto o : within_this_set) {
auto size_I = m_orders[o].subsetI(within_this_set).size();
if (max_size < size_I) {
max_size = size_I;
best_order = o;
}
}
return best_order;
}
} // namespace vrp
} // namespace pgrouting