PGROUTING  3.2
pd_orders.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: solution.cpp
4 
5 Copyright (c) 2015 pgRouting developers
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
26 #include "vrp/pd_orders.h"
27 
28 #include <vector>
29 #include <memory>
30 #include <utility>
31 
32 #include "vrp/pgr_pickDeliver.h"
33 #include "vrp/dnode.h"
34 
35 namespace pgrouting {
36 namespace vrp {
37 
38 Pgr_pickDeliver* PD_Orders::problem;
39 
41  const std::vector<PickDeliveryOrders_t> &pd_orders
42  ) {
43  build_orders(pd_orders);
44 }
45 
46 
47 void
49  const PickDeliveryOrders_t &order,
50  const Vehicle_node &pick,
51  const Vehicle_node &drop) {
52 
53  /*
54  * add into an order
55  */
56  m_orders.push_back(
57  Order(m_orders.size(), order.id,
58  pick,
59  drop));
60 }
61 
62 
63 void
65  const std::vector<PickDeliveryOrders_t> &pd_orders
66  ) {
67 #if 0
68  ENTERING();
69 #endif
70  for (const auto &order : pd_orders) {
71  /*
72  * SAMPLE CORRECT INFORMATION
73  *
74  * 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
75  * 1 | 10 | 35 | 69 | 448 | 505 | 90 | 45 | 68 | 912 | 967 | 90 | 35
76  */
77 
78  /*
79  * matrix version
80  */
81 
82  if (!problem->get_cost_matrix().has_id(order.pick_node_id)) {
83  throw std::make_pair(std::string("Unable to find node on matrix"), order.pick_node_id);
84  }
85  if (!problem->get_cost_matrix().has_id(order.deliver_node_id)) {
86  throw std::make_pair(std::string("Unable to find node on matrix"), order.deliver_node_id);
87  }
88 
89  Vehicle_node pickup({problem->get_nodes().size(), order, Tw_node::NodeType::kPickup});
90  problem->add_node(pickup);
91  Vehicle_node delivery({problem->get_nodes().size(), order, Tw_node::NodeType::kDelivery});
92  problem->add_node(delivery);
93 
94  add_order(order, pickup, delivery);
95  } // for (creating orders)
96 
97 #if 0
98  EXITING();
99 #endif
100 }
101 
102 
103 Order&
105  pgassert(i < m_orders.size());
106  return m_orders[i];
107 }
108 
109 const Order&
110 PD_Orders::operator[](size_t i) const {
111  pgassert(i < m_orders.size());
112  return m_orders[i];
113 }
114 
115 void
117  for (auto &I : m_orders) {
118  for (const auto &J : m_orders) {
119  I.set_compatibles(J, speed);
120  }
121  }
122 }
123 
124 size_t
126  Identifiers<size_t> &within_this_set) const {
127  pgassert(!within_this_set.empty());
128  auto best_order = within_this_set.front();
129  size_t max_size = 0;
130 
131 
132  for (auto o : within_this_set) {
133  auto size_J = m_orders[o].subsetJ(within_this_set).size();
134  if (max_size < size_J) {
135  max_size = size_J;
136  best_order = o;
137  }
138  }
139  return best_order;
140 }
141 
142 
143 size_t
145  Identifiers<size_t> &within_this_set) const {
146  pgassert(!within_this_set.empty());
147  auto best_order = within_this_set.front();
148  size_t max_size = 0;
149 
150 
151  for (auto o : within_this_set) {
152  auto size_I = m_orders[o].subsetI(within_this_set).size();
153  if (max_size < size_I) {
154  max_size = size_I;
155  best_order = o;
156  }
157  }
158  return best_order;
159 }
160 
161 
162 } // namespace vrp
163 } // namespace pgrouting
pgr_pickDeliver.h
pgrouting::vrp::PD_Orders::m_orders
Orders m_orders
Definition: pd_orders.h:97
pgrouting::vrp::PD_Orders::size
size_t size() const
Definition: pd_orders.h:79
dnode.h
EXITING
#define EXITING(x)
Definition: pgr_messages.h:94
PickDeliveryOrders_t
Definition: pickDeliveryOrders_t.h:43
ENTERING
#define ENTERING(x)
Definition: pgr_messages.h:93
pgrouting::vrp::Vehicle_node
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:48
PickDeliveryOrders_t::id
int64_t id
Definition: pickDeliveryOrders_t.h:46
pgrouting::vrp::Pgr_pickDeliver::get_nodes
std::vector< Vehicle_node > get_nodes() const
Definition: pgr_pickDeliver.h:88
pd_orders.h
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::tsp::Dmatrix::has_id
bool has_id(int64_t id) const
original id -> true
Definition: Dmatrix.cpp:79
pgrouting::vrp::Pgr_pickDeliver::get_cost_matrix
pgrouting::tsp::Dmatrix get_cost_matrix() const
Definition: pgr_pickDeliver.h:92
pgrouting::vrp::PD_Orders::build_orders
void build_orders(const std::vector< PickDeliveryOrders_t > &pd_orders)
Definition: pd_orders.cpp:64
pgrouting::vrp::PD_Orders::find_best_J
size_t find_best_J(Identifiers< size_t > &within_this_set) const
Definition: pd_orders.cpp:125
pgrouting::vrp::PD_Orders::PD_Orders
PD_Orders()=default
Identifiers::empty
bool empty() const
Definition: identifiers.hpp:79
pgrouting::vrp::Order
Definition: order.h:42
pgrouting::vrp::PD_Orders::problem
static Pgr_pickDeliver * problem
The problem.
Definition: pd_orders.h:103
Identifiers::front
T front() const
Definition: identifiers.hpp:80
pgrouting::vrp::PD_Orders::add_order
void add_order(const PickDeliveryOrders_t &, const Vehicle_node &, const Vehicle_node &)
Definition: pd_orders.cpp:48
pgrouting::vrp::PD_Orders::set_compatibles
void set_compatibles(double speed)
Definition: pd_orders.cpp:116
pgrouting::vrp::PD_Orders::operator[]
Order & operator[](size_t o)
Definition: pd_orders.cpp:104
pgrouting::vrp::Pgr_pickDeliver::add_node
void add_node(const Vehicle_node &node)
Definition: pgr_pickDeliver.cpp:128
pgrouting::vrp::PD_Orders::find_best_I
size_t find_best_I(Identifiers< size_t > &within_this_set) const
Definition: pd_orders.cpp:144
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
Identifiers< size_t >