PGROUTING  3.2
tw_node.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: tw_node.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/tw_node.h"
27 
28 #include <limits>
29 #include <string>
30 
31 #include "cpp_common/pgr_assert.h"
32 #include "vrp/pgr_pickDeliver.h"
33 
34 
35 namespace pgrouting {
36 namespace vrp {
37 
38 
39 double
40 Tw_node::travel_time_to(const Tw_node &to, double speed) const {
41  pgassert(speed != 0);
42  return distance(to) / speed;
43 }
44 
45 
46 /*
47  * I -> J = (*this)
48  */
49 double
50 Tw_node::arrival_j_opens_i(const Tw_node &I, double speed) const {
51  if (m_type == kStart) return (std::numeric_limits<double>::max)();
52  return I.opens() + I.service_time() + I.travel_time_to(*this, speed);
53 }
54 
55 
56 
57 
58 
59 bool
60 Tw_node::is_compatible_IJ(const Tw_node &I, double speed) const {
61  /*
62  * I /-> kStart
63  */
64  if (m_type == kStart) return false;
65  /*
66  * kEnd /-> (*this)
67  */
68  if (I.m_type == kEnd) return false;
69 
70  return !is_late_arrival(arrival_j_opens_i(I, speed));
71 }
72 
73 
74 
75 std::string Tw_node::type_str() const {
76  switch (type()) {
77  case kStart: return "START"; break;
78  case kEnd: return "END"; break;
79  case kDump: return "DUMP"; break;
80  case kLoad: return "LOAD"; break;
81  case kPickup: return "PICKUP"; break;
82  case kDelivery: return "DELIVERY"; break;
83  default: return "UNKNOWN";
84  }
85 }
86 
87 bool
89  return
90  m_type == kStart
91  && (opens() < closes())
92  && (service_time() >= 0)
93  && (demand() == 0);
94 }
95 
96 bool
98  return m_type == kPickup
99  && (opens() < closes())
100  && (service_time() >= 0)
101  && (demand() > 0);
102 }
103 
104 
105 bool
107  return m_type == kDelivery
108  && (opens() < closes())
109  && (service_time() >= 0)
110  && (demand() < 0);
111 }
112 
113 
114 bool
116  return m_type == kDump
117  && (opens() < closes())
118  && (service_time() >= 0)
119  && (demand() <= 0);
120 }
121 
122 
123 
124 
125 bool
127  return m_type == kEnd
128  && (opens() < closes())
129  && (service_time() >= 0)
130  && (demand() == 0);
131 }
132 
133 
134 bool
135 Tw_node::operator ==(const Tw_node &other) const {
136  if (&other == this) return true;
137  return m_order == other.m_order
138  && m_opens == other.m_opens
139  && m_closes == other.m_closes
140  && m_service_time == other.m_service_time
141  && m_demand == other.m_demand
142  && m_type == other.m_type
143  && id() == other.id()
144  && idx() == other.idx();
145 }
146 
147 
148 
149 
150 
152  size_t id,
154  NodeType type) :
155  Dnode(id, data.pick_node_id),
156  m_order(data.id),
157  m_opens(data.pick_open_t),
158  m_closes(data.pick_close_t),
159  m_service_time(data.pick_service_t),
160  m_demand(data.demand),
161  m_type(type) {
162  if (m_type == kDelivery) {
164  m_opens = data.deliver_open_t;
165  m_closes = data.deliver_close_t;
167  m_demand *= -1;
168  }
169  }
170 
172  size_t id,
173  Vehicle_t data,
174  NodeType type) :
175  Dnode(id, data.start_node_id),
176  m_opens(data.start_open_t),
177  m_closes(data.start_close_t),
178  m_service_time(data.start_service_t),
179  m_demand(0),
180  m_type(type) {
181  if (m_type == kEnd) {
182  reset_id(data.end_node_id);
183  m_opens = data.end_open_t;
184  m_closes = data.end_close_t;
186  }
187  }
188 
189 
191 std::ostream& operator << (std::ostream &log, const Tw_node &n) {
192  log << n.id()
193  << "[opens = " << n.m_opens
194  << "\tcloses = " << n.m_closes
195  << "\tservice = " << n.m_service_time
196  << "\tdemand = " << n.m_demand
197  << "\ttype = " << n.type_str()
198  << "]"
199  << "\n";
200  return log;
201 }
202 
203 } // namespace vrp
204 } // namespace pgrouting
205 
pgrouting::vrp::Dnode
The Dnode class defines a the basic operations when data is a matrix.
Definition: dnode.h:48
pgr_pickDeliver.h
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
Vehicle_t::end_service_t
double end_service_t
Definition: vehicle_t.h:61
pgrouting::vrp::Dnode::distance
double distance(const Dnode &other) const
Definition: dnode.cpp:43
pgrouting::vrp::Tw_node::kDump
@ kDump
dump site, empties truck
Definition: tw_node.h:63
pgrouting::vrp::Tw_node::m_type
NodeType m_type
The demand for the Node.
Definition: tw_node.h:230
PickDeliveryOrders_t
Definition: pickDeliveryOrders_t.h:43
pgrouting::vrp::Tw_node::is_end
bool is_end() const
is_end
Definition: tw_node.cpp:126
Vehicle_t::end_close_t
double end_close_t
Definition: vehicle_t.h:60
pgrouting::vrp::Tw_node::kDelivery
@ kDelivery
delivery site
Definition: tw_node.h:62
pgrouting::vrp::Tw_node::kStart
@ kStart
starting site
Definition: tw_node.h:60
Vehicle_t::end_open_t
double end_open_t
Definition: vehicle_t.h:59
pgrouting::vrp::Tw_node::demand
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:82
pgrouting::vrp::operator<<
std::ostream & operator<<(std::ostream &log, const Swap_info &d)
Definition: book_keeping.cpp:47
pgrouting::vrp::Tw_node::m_opens
double m_opens
opening time of the node
Definition: tw_node.h:226
pgrouting::vrp::Tw_node::is_compatible_IJ
bool is_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:60
Vehicle_t
Definition: vehicle_t.h:40
pgrouting::vrp::Tw_node::type_str
std::string type_str() const
Definition: tw_node.cpp:75
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
tw_node.h
pgrouting::Identifier::idx
size_t idx() const
Definition: identifier.cpp:37
pgrouting::vrp::Tw_node::arrival_j_opens_i
double arrival_j_opens_i(const Tw_node &I, double speed) const
@ {
Definition: tw_node.cpp:50
pgrouting::vrp::Tw_node::is_pickup
bool is_pickup() const
is_pickup
Definition: tw_node.cpp:97
pgrouting::vrp::Tw_node::kEnd
@ kEnd
ending site
Definition: tw_node.h:65
Vehicle_t::end_node_id
int64_t end_node_id
Definition: vehicle_t.h:57
pgrouting::Identifier::id
int64_t id() const
Definition: identifier.cpp:42
PickDeliveryOrders_t::deliver_close_t
double deliver_close_t
Definition: pickDeliveryOrders_t.h:62
pgrouting::vrp::Tw_node::closes
double closes() const
Returns the closing time.
Definition: tw_node.h:79
pgrouting::vrp::Tw_node::is_delivery
bool is_delivery() const
is_delivery
Definition: tw_node.cpp:106
pgrouting::vrp::Tw_node::m_service_time
double m_service_time
Definition: tw_node.h:228
pgrouting::vrp::Tw_node::is_start
bool is_start() const
@ {
Definition: tw_node.cpp:88
pgrouting::vrp::Tw_node::Tw_node
Tw_node()=default
pgrouting::vrp::Tw_node::kLoad
@ kLoad
load site, fills the truck
Definition: tw_node.h:64
PickDeliveryOrders_t::deliver_service_t
double deliver_service_t
Definition: pickDeliveryOrders_t.h:63
pgr_assert.h
An assert functionality that uses C++ throw().
pgrouting::vrp::Tw_node::kPickup
@ kPickup
pickup site
Definition: tw_node.h:61
pgrouting::vrp::Tw_node::m_order
int64_t m_order
order to which it belongs
Definition: tw_node.h:225
pgrouting::vrp::Tw_node::m_closes
double m_closes
closing time of the node
Definition: tw_node.h:227
pgrouting::vrp::Tw_node
Extends the Node class to create a Node with time window attributes.
Definition: tw_node.h:57
PickDeliveryOrders_t::deliver_open_t
double deliver_open_t
Definition: pickDeliveryOrders_t.h:61
pgrouting::Identifier::reset_id
void reset_id(int64_t)
Definition: identifier.cpp:47
pgrouting::vrp::Tw_node::is_late_arrival
bool is_late_arrival(double arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:184
pgrouting::vrp::Tw_node::opens
double opens() const
Returns the opening time.
Definition: tw_node.h:76
pgrouting::vrp::Tw_node::service_time
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:86
pgrouting::vrp::Tw_node::operator==
bool operator==(const Tw_node &rhs) const
Definition: tw_node.cpp:135
PickDeliveryOrders_t::deliver_node_id
int64_t deliver_node_id
Definition: pickDeliveryOrders_t.h:59
pgrouting::vrp::Tw_node::is_dump
bool is_dump() const
is_dump
Definition: tw_node.cpp:115
pgrouting::vrp::Tw_node::type
NodeType type() const
Returns the type of this node.
Definition: tw_node.h:89
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::vrp::Tw_node::NodeType
NodeType
Definition: tw_node.h:59
pgrouting::vrp::Tw_node::m_demand
double m_demand
The demand for the Node.
Definition: tw_node.h:229