PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
26 #pragma once
27 #include <string>
28 
29 #include "./../../common/src/pgr_types.h"
30 #include "./../../common/src/pgr_assert.h"
31 
32 #include "./node.h"
33 
34 namespace pgrouting {
35 namespace vrp {
36 
37  class Pgr_pickDeliver;
38 
50 class Tw_node: public Node {
51  public:
52  typedef enum {
53  kStart = 0, // /< starting site
54  kPickup, // /< pickup site
55  kDelivery, // /< delivery site
56  kDump, // /< dump site, empties truck
57  kLoad, // /< load site, fills the truck
59  } NodeType;
60 
61 
62  inline void set_Pid(size_t id) {
64  m_otherid = id;
65  }
66 
67  inline void set_Did(size_t id) {
69  m_otherid = id;
70  }
71 
72  inline size_t Did() const {
74  return m_otherid;
75  }
76 
77  inline size_t Pid() const {
79  return m_otherid;
80  }
81 
82 
84 
86 
88  inline double opens() const {return m_opens;}
89 
91  inline double closes() const {return m_closes;}
92 
94  inline double demand() const {return m_demand;}
95 
97  inline double service_time() const { return m_service_time;}
98 
100  inline NodeType type() const { return m_type;}
101 
103  inline double window_length() const {return m_closes - m_opens;}
104 
106  double travel_time_to(const Node &other) const;
107 
109 
119 
121 
129  bool is_start() const;
130 
131 
139  bool is_pickup() const;
140 
141 
149  bool is_delivery() const;
150 
151 
159  bool is_dump() const;
160 
161 
169  bool is_load() const;
170 
171 
179  bool is_end() const;
180 
181 
182  std::string type_str() const;
183 
185 
186 
187 
189  friend std::ostream& operator << (std::ostream &log, const Tw_node &node);
190 
191  bool operator ==(const Tw_node &rhs) const;
192 
193 
194 
196  inline bool is_early_arrival(double arrival_time) const {
197  return arrival_time < m_opens;
198  }
199 
201  inline bool is_late_arrival(double arrival_time) const {
202  return arrival_time > m_closes;
203  }
205  inline bool is_on_time(double arrival_time) const {
206  return !is_early_arrival(arrival_time)
207  && !is_late_arrival(arrival_time);
208  }
209 
210 
211 
212 
213 
215 
221  double arrival_j_opens_i(const Tw_node &I) const;
222 
228  double arrival_j_closes_i(const Tw_node &I) const;
229 
230 
231  /*
232  * is possible to arrive to \b this after visiting \bother
233  * - departing as early as possible from \b other it can arrives to \b this
234  */
235  bool is_compatible_IJ(const Tw_node &I) const;
236 
237  /*
238  * is possible to arrive to \b this after visiting \bother
239  * - departing as late as possible from \b other it can arrives to \b this
240  */
241  bool is_partially_compatible_IJ(const Tw_node &I) const;
242 
243  /*
244  * is possible to arrive to \b this after visiting \bother
245  * - departing as late as possible from \b other it can arrives to \b this
246  */
247  bool is_tight_compatible_IJ(const Tw_node &I) const;
248 
249  /*
250  * is possible to arrive to \b this after visiting \b other
251  * - departing as late as possible from \b other it can arrives to \b this
252  */
253  bool is_partially_waitTime_compatible_IJ(const Tw_node &I) const;
254 
255  /*
256  * is compatible to arrive to \b this after visiting \b other
257  * - is fully compatible
258  * - does not have a waiting time when arriving as earliest as possible after
259  */
260  bool is_waitTime_compatible_IJ(const Tw_node &I) const;
261 
262 
264 
265 
266 
267  Tw_node(const Tw_node &other) = default;
268  Tw_node(
269  size_t id,
270  Customer_t data,
271  NodeType type,
272  const Pgr_pickDeliver *problem);
273 
274  Tw_node(
275  size_t id,
276  int64_t p_original_id,
277  double x,
278  double y,
279  double opens,
280  double closes,
281  double service_time,
282  double demand,
283  NodeType type,
284  const Pgr_pickDeliver *problem);
285 
286  protected:
287  bool is_valid() const;
288 
289  double m_opens;
290  double m_closes;
291  double m_service_time; // /< time it takes to be served
292  double m_demand;
293  size_t m_otherid;
296 };
297 
298 } // namespace vrp
299 } // namespace pgrouting
double m_opens
opening time of the node
Definition: tw_node.h:289
void set_Did(size_t id)
Definition: tw_node.h:67
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:94
bool is_load() const
is_Load
Definition: tw_node.cpp:162
bool is_valid() const
Definition: tw_node.cpp:189
bool is_early_arrival(double arrival_time) const
True when arrivalTime is before it opens.
Definition: tw_node.h:196
bool is_on_time(double arrival_time) const
True when arrivalTime in the time window.
Definition: tw_node.h:205
double arrival_j_opens_i(const Tw_node &I) const
@ {
Definition: tw_node.cpp:50
bool is_end() const
is_end
Definition: tw_node.cpp:172
double m_demand
The demand for the Node.
Definition: tw_node.h:292
The Node class defines a point in 2D space with an id.
Definition: node.h:46
double arrival_j_closes_i(const Tw_node &I) const
The actual arrival time at this node, given that: this node is visited directly after other node and ...
Definition: tw_node.cpp:56
double travel_time_to(const Node &other) const
time = distance / speed.
Definition: tw_node.cpp:40
bool is_tight_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:87
bool operator==(const Tw_node &rhs) const
Definition: tw_node.cpp:182
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:97
double m_closes
closing time of the node
Definition: tw_node.h:290
double window_length() const
Returns the length of time between the opening and closing.
Definition: tw_node.h:103
double opens() const
@ {
Definition: tw_node.h:88
Tw_node(const Tw_node &other)=default
const Pgr_pickDeliver * problem
Definition: tw_node.h:295
PGDLLEXPORT Datum vrp(PG_FUNCTION_ARGS)
Definition: VRP.c:732
bool is_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:65
bool is_waitTime_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:102
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool is_late_arrival(double arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:201
bool is_partially_waitTime_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:95
std::string type_str() const
Definition: tw_node.cpp:109
bool is_start() const
@ {
Definition: tw_node.cpp:122
NodeType type() const
Returns the type of this node.
Definition: tw_node.h:100
bool is_partially_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:79
double closes() const
Returns the closing time.
Definition: tw_node.h:91
bool is_pickup() const
is_pickup
Definition: tw_node.cpp:132
void set_Pid(size_t id)
Definition: tw_node.h:62
bool is_delivery() const
is_delivery
Definition: tw_node.cpp:142
bool is_dump() const
is_dump
Definition: tw_node.cpp:152
Extends the Node class to create a Node with time window attributes.
Definition: tw_node.h:50
size_t id() const
@ {
Definition: node.h:51
size_t Pid() const
Definition: tw_node.h:77
NodeType m_type
The demand for the Node.
Definition: tw_node.h:294
size_t Did() const
Definition: tw_node.h:72
size_t m_otherid
the other's internal id
Definition: tw_node.h:293
friend std::ostream & operator<<(std::ostream &log, const Tw_node &node)
Print the contents of a Twnode object.
Definition: tw_node.cpp:261