PGROUTING  3.2
order.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: order.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 
27 #include "vrp/order.h"
28 
29 
30 namespace pgrouting {
31 namespace vrp {
32 
33 
36  return m_compatibleI * I;
37 }
38 
41  return m_compatibleJ * J;
42 }
43 
44 
46  size_t p_idx, int64_t p_id,
47  const Vehicle_node &p_pickup,
48  const Vehicle_node &p_delivery) :
49  Identifier(p_idx, p_id),
50  m_pickup(p_pickup),
51  m_delivery(p_delivery) {
52  }
53 
54 std::ostream&
55 operator<< (std::ostream &log, const Order &order) {
56  log << "\n\nOrder "
57  << static_cast<Identifier>(order) << ": \n"
58  << "\tPickup: " << order.pickup() << "\n"
59  << "\tDelivery: " << order.delivery() << "\n\n"
60  << "\tTravel time: "
61  << order.pickup().travel_time_to(order.delivery(), 1);
62  log << "\nThere are | {I}| = "
63  << order.m_compatibleI.size()
64  << " -> order(" << order.idx()
65  << ") -> | {J}| = " << order.m_compatibleJ.size()
66  << "\n\n {";
67  for (const auto o : order.m_compatibleI) {
68  log << o << ", ";
69  }
70  log << "} -> " << order.idx() << " -> {";
71  for (const auto o : order.m_compatibleJ) {
72  log << o << ", ";
73  }
74  log << "}";
75 
76  return log;
77 }
78 
79 
80 
81 const Vehicle_node&
82 Order::delivery() const {
83  return m_delivery;
84 }
85 
86 
87 const Vehicle_node&
88 Order::pickup() const {
89  return m_pickup;
90 }
91 
92 
93 bool
94 Order::is_valid(double speed) const {
95  return
96  pickup().is_pickup()
97  && delivery().is_delivery()
98  /* IS P -> D */
99  && delivery().is_compatible_IJ(pickup(), speed);
100 }
101 
102 
103 /*
104  * Initializing the set of nodes that can be placed
105  * inmediately after \bthis node
106  *
107  * (*this) -> J
108  *
109  */
110 void
111 Order::set_compatibles(const Order J, double speed) {
112  if (J.idx() == idx()) return;
113  if (J.isCompatibleIJ(*this, speed)) {
114  /*
115  * this -> {J}
116  */
117  m_compatibleJ += J.idx();
118  }
119  if (this->isCompatibleIJ(J, speed)) {
120  /*
121  * {J} -> this
122  */
123  m_compatibleI += J.idx();
124  }
125 }
126 
127 
128 /*
129  * True when
130  *
131  * I -> (*this)
132  *
133  */
134 bool
135 Order::isCompatibleIJ(const Order &I, double speed) const {
136  /* this is true in all cases */
137  auto all_cases(
138  pickup().is_compatible_IJ(I.pickup(), speed)
139  && delivery().is_compatible_IJ(I.pickup(), speed));
140 
141  /* case other(P) other(D) this(P) this(D) */
142  auto case1(pickup().is_compatible_IJ(I.delivery(), speed)
143  && delivery().is_compatible_IJ(I.delivery(), speed));
144 
145  /* case other(P) this(P) other(D) this(D) */
146  auto case2(I.delivery().is_compatible_IJ(pickup(), speed)
147  && delivery().is_compatible_IJ(I.delivery(), speed));
148 
149  /* case other(P) this(P) this(D) other(D) */
150  auto case3(I.delivery().is_compatible_IJ(pickup(), speed)
151  && I.delivery().is_compatible_IJ(delivery(), speed));
152 
153  return all_cases && (case1 || case2 || case3);
154 }
155 
156 } // namespace vrp
157 } // namespace pgrouting
158 
pgrouting::vrp::Order::subsetI
Identifiers< size_t > subsetI(const Identifiers< size_t > &I) const
Definition: order.cpp:35
pgrouting::vrp::Order::is_valid
bool is_valid(double speed) const
validate a pickup/delivery order
Definition: order.cpp:94
pgrouting::vrp::Tw_node::travel_time_to
double travel_time_to(const Tw_node &other, double speed) const
time = distance / speed.
Definition: tw_node.cpp:40
pgrouting::vrp::Order::subsetJ
Identifiers< size_t > subsetJ(const Identifiers< size_t > &J) const
Get a subset of the orders that can be placed after this order.
Definition: order.cpp:40
pgrouting::vrp::Order::m_delivery
Vehicle_node m_delivery
The delivery node identifier.
Definition: order.h:151
pgrouting::vrp::Order::m_compatibleI
Identifiers< size_t > m_compatibleI
Stores all the orders that can be placed before this order.
Definition: order.h:182
pgrouting::vrp::Order::set_compatibles
void set_compatibles(const Order order, double speed)
Definition: order.cpp:111
pgrouting::vrp::Vehicle_node
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:48
pgrouting::vrp::operator<<
std::ostream & operator<<(std::ostream &log, const Swap_info &d)
Definition: book_keeping.cpp:47
pgrouting::vrp::Tw_node::is_compatible_IJ
bool is_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:60
pgrouting::Identifier::idx
size_t idx() const
Definition: identifier.cpp:37
Identifiers::size
size_t size() const
Definition: identifiers.hpp:78
pgrouting::vrp::Tw_node::is_pickup
bool is_pickup() const
is_pickup
Definition: tw_node.cpp:97
pgrouting::vrp::Order::m_pickup
Vehicle_node m_pickup
The pick up node identifier.
Definition: order.h:145
pgrouting::vrp::Tw_node::is_delivery
bool is_delivery() const
is_delivery
Definition: tw_node.cpp:106
pgrouting::vrp::Order::pickup
const Vehicle_node & pickup() const
The delivery node identifier.
Definition: order.cpp:88
pgrouting::vrp::Order::delivery
const Vehicle_node & delivery() const
The delivery node identifier.
Definition: order.cpp:82
pgrouting::vrp::Order
Definition: order.h:42
pgrouting::Identifier
Definition: identifier.h:39
order.h
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
Identifiers< size_t >
pgrouting::vrp::Order::m_compatibleJ
Identifiers< size_t > m_compatibleJ
Stores all the orders that can be placed after this order.
Definition: order.h:168
pgrouting::vrp::Order::isCompatibleIJ
bool isCompatibleIJ(const Order &I, double speed) const
Can order I be placed before this order?
Definition: order.cpp:135
pgrouting::vrp::Order::Order
Order(size_t p_id, int64_t p_idx, const Vehicle_node &p_pickup, const Vehicle_node &p_deliver)
Definition: order.cpp:45