PGROUTING  2.5
tw_node.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: tw_node.h
4 
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
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 
28 #ifndef INCLUDE_VRP_TW_NODE_H_
29 #define INCLUDE_VRP_TW_NODE_H_
30 #pragma once
31 
32 #include <string>
33 
36 #include "cpp_common/pgr_assert.h"
37 #include "cpp_common/identifier.h"
38 
39 #include "vrp/pd_problem.h"
40 #include "vrp/node.h"
41 
42 namespace pgrouting {
43 namespace vrp {
44 
45 
57 class Tw_node : public Identifier, public PD_problem {
58  public:
59  typedef enum {
60  kStart = 0,
66  } NodeType;
67 
68 
70 
73  inline int64_t order() const {return m_order;}
74 
76  inline double opens() const {return m_opens;}
77 
79  inline double closes() const {return m_closes;}
80 
82  inline double demand() const {return m_demand;}
83  inline void demand(double value) {m_demand = value;}
84 
86  inline double service_time() const {return m_service_time;}
87 
89  inline NodeType type() const {return m_type;}
90 
92  inline double window_length() const {return m_closes - m_opens;}
93 
95  double travel_time_to(const Tw_node &other, double speed) const;
96 
98 
108 
110 
118  bool is_start() const;
119 
120 
128  bool is_pickup() const;
129 
130 
138  bool is_delivery() const;
139 
140 
148  bool is_dump() const;
149 
150 
158  bool is_load() const;
159 
160 
168  bool is_end() const;
169 
170 
171  std::string type_str() const;
172 
177  friend std::ostream& operator<< (std::ostream &log, const Tw_node &node);
178 
182  bool operator ==(const Tw_node &rhs) const;
183 
184 
185 
187  inline bool is_early_arrival(double arrival_time) const {
188  return arrival_time < m_opens;
189  }
190 
192  inline bool is_late_arrival(double arrival_time) const {
193  return arrival_time > m_closes;
194  }
196  inline bool is_on_time(double arrival_time) const {
197  return !is_early_arrival(arrival_time)
198  && !is_late_arrival(arrival_time);
199  }
204 
210  double arrival_j_opens_i(const Tw_node &I, double speed) const;
211 
217  double arrival_j_closes_i(const Tw_node &I, double speed) const;
218 
219 
220  /*
221  * is possible to arrive to @b this after visiting @bother
222  * - departing as early as possible from @b other it can arrives to @b this
223  */
224  bool is_compatible_IJ(const Tw_node &I, double speed) const;
225 
226  /*
227  * is possible to arrive to @b this after visiting @bother
228  * - departing as late as possible from @b other it can arrives to @b this
229  */
230  bool is_partially_compatible_IJ(const Tw_node &I, double speed) const;
231 
232  /*
233  * is possible to arrive to @b this after visiting @bother
234  * - departing as late as possible from @b other it can arrives to @b this
235  */
236  bool is_tight_compatible_IJ(const Tw_node &I, double speed) const;
237 
238  /*
239  * is possible to arrive to @b this after visiting @b other
240  * - departing as late as possible from @b other it can arrives to @b this
241  */
243  const Tw_node &I,
244  double speed) const;
245 
246  /*
247  * is compatible to arrive to @b this after visiting @b other
248  * - is fully compatible
249  * - does not have a waiting time when arriving as earliest as possible after
250  */
251  bool is_waitTime_compatible_IJ(const Tw_node &I, double speed) const;
252 
253 
255 
256 
257 
258  Tw_node() = default;
259  Tw_node(const Tw_node &) = default;
260  Tw_node(
261  size_t id,
263  NodeType type);
264  Tw_node(
265  size_t id,
266  Vehicle_t data,
267  NodeType type);
268 
269  protected:
270  bool is_valid() const;
271 
272  private:
273  int64_t m_order;
274  double m_opens;
275  double m_closes;
276  double m_service_time; // /< time it takes to be served
277  double m_demand;
278  NodeType m_type;
279 };
280 
281 } // namespace vrp
282 } // namespace pgrouting
283 
284 #endif // INCLUDE_VRP_TW_NODE_H_
double m_opens
opening time of the node
Definition: tw_node.h:274
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:82
bool is_load() const
is_Load
Definition: tw_node.cpp:172
bool is_valid() const
Definition: tw_node.cpp:203
bool is_early_arrival(double arrival_time) const
True when arrivalTime is before it opens.
Definition: tw_node.h:187
bool is_on_time(double arrival_time) const
True when arrivalTime in the time window.
Definition: tw_node.h:196
bool is_end() const
is_end
Definition: tw_node.cpp:182
double m_demand
The demand for the Node.
Definition: tw_node.h:277
int64_t order() const
@ {
Definition: tw_node.h:73
bool operator==(const Tw_node &rhs) const
Definition: tw_node.cpp:192
bool is_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:73
bool is_partially_waitTime_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:103
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:86
double m_closes
closing time of the node
Definition: tw_node.h:275
dump site, empties truck
Definition: tw_node.h:63
double window_length() const
Returns the length of time between the opening and closing.
Definition: tw_node.h:92
double opens() const
Returns the opening time.
Definition: tw_node.h:76
load site, fills the truck
Definition: tw_node.h:64
int64_t m_order
order to which it belongs
Definition: tw_node.h:273
bool is_late_arrival(double arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:192
bool is_waitTime_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:112
std::string type_str() const
Definition: tw_node.cpp:119
bool is_start() const
@ {
Definition: tw_node.cpp:132
bool is_tight_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:95
NodeType type() const
Returns the type of this node.
Definition: tw_node.h:89
bool is_partially_compatible_IJ(const Tw_node &I, double speed) const
Definition: tw_node.cpp:87
double closes() const
Returns the closing time.
Definition: tw_node.h:79
bool is_pickup() const
is_pickup
Definition: tw_node.cpp:142
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
Assertions Handling.
bool is_delivery() const
is_delivery
Definition: tw_node.cpp:152
bool is_dump() const
is_dump
Definition: tw_node.cpp:162
Extends the Node class to create a Node with time window attributes.
Definition: tw_node.h:57
NodeType m_type
The demand for the Node.
Definition: tw_node.h:278
double arrival_j_closes_i(const Tw_node &I, double speed) const
The actual arrival time at this node, given that: this node is visited directly after other node and ...
Definition: tw_node.cpp:64
double travel_time_to(const Tw_node &other, double speed) const
time = distance / speed.
Definition: tw_node.cpp:40
friend std::ostream & operator<<(std::ostream &log, const Tw_node &node)
Print the contents of a Twnode object.
Definition: tw_node.cpp:278
void demand(double value)
Definition: tw_node.h:83
double arrival_j_opens_i(const Tw_node &I, double speed) const
@ {
Definition: tw_node.cpp:58