PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
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 #include "./tw_node.h"
27 
28 #include <limits>
29 #include <string>
30 
31 #include "./../../common/src/pgr_assert.h"
32 
33 #include "./pgr_pickDeliver.h"
34 
35 namespace pgrouting {
36 namespace vrp {
37 
38 
39 double
40 Tw_node::travel_time_to(const Node &other) const {
41  pgassert(problem->speed() > 0);
42  return distance(other) / problem->speed();
43 }
44 
45 
46 /*
47  * I -> J = (*this)
48  */
49 double
51  if (m_type == kStart) return (std::numeric_limits<double>::max)();
52  return I.opens() + I.service_time() + I.travel_time_to(*this);
53 }
54 
55 double
57  if (m_type == kStart) return (std::numeric_limits<double>::max)();
58  return I.closes() + I.service_time() + I.travel_time_to(*this);
59 }
60 
61 
62 
63 
64 bool
66  /*
67  * I /-> kStart
68  */
69  if (m_type == kStart) return false;
70  /*
71  * kEnd /-> (*this)
72  */
73  if (I.m_type == kEnd) return false;
74 
76 }
77 
78 bool
80  return
84 }
85 
86 bool
88  return
92 }
93 
94 bool
96  return
99 }
100 
101 bool
103  return
106 }
107 
108 
109 std::string Tw_node::type_str() const {
110  switch (type()) {
111  case kStart: return "START"; break;
112  case kEnd: return "END"; break;
113  case kDump: return "DUMP"; break;
114  case kLoad: return "LOAD"; break;
115  case kPickup: return "PICKUP"; break;
116  case kDelivery: return "DELIVERY"; break;
117  default: return "UNKNOWN";
118  }
119 }
120 
121 bool
123  return
124  m_type == kStart
125  && (0 <= opens())
126  && (opens() < closes())
127  && (service_time() >= 0)
128  && (demand() == 0);
129 }
130 
131 bool
133  return m_type == kPickup
134  && (0 <= opens())
135  && (opens() < closes())
136  && (service_time() >= 0)
137  && (demand() > 0);
138 }
139 
140 
141 bool
143  return m_type == kDelivery
144  && (0 <= opens())
145  && (opens() < closes())
146  && (service_time() >= 0)
147  && (demand() < 0);
148 }
149 
150 
151 bool
153  return m_type == kDump
154  && (0 <= opens())
155  && (opens() < closes())
156  && (service_time() >= 0)
157  && (demand() <= 0);
158 }
159 
160 
161 bool
163  return m_type == kLoad
164  && (0 <= opens())
165  && (opens() < closes())
166  && (service_time() >= 0)
167  && (demand() >= 0);
168 }
169 
170 
171 bool
173  return m_type == kEnd
174  && (0 <= opens())
175  && (opens() < closes())
176  && (service_time() >= 0)
177  && (demand() == 0);
178 }
179 
180 
181 bool
182 Tw_node::operator ==(const Tw_node &rhs) const {
183  if (&rhs == this) return true;
184  return (static_cast<Node>(*this) == static_cast<Node>(rhs));
185 }
186 
187 
188 
189 bool Tw_node::is_valid() const {
190  switch (type()) {
191  case kStart:
192  return is_start();
193  break;
194 
195  case kEnd:
196  return is_end();
197  break;
198 
199  case kDump:
200  return is_dump();
201  break;
202 
203  case kDelivery:
204  return is_delivery();
205  break;
206 
207  case kPickup:
208  return is_pickup();
209  break;
210 
211  case kLoad:
212  return is_load();
213  break;
214 
215  default:
216  return false;
217  break;
218  }
219 
220  return false;
221 }
222 
223 
225  size_t id,
226  Customer_t data,
227  NodeType type,
228  const Pgr_pickDeliver *p_problem) :
229  Node(id, data.id, data.x, data.y),
230  m_opens(data.Etime),
231  m_closes(data.Ltime),
232  m_service_time(data.Stime),
233  m_demand(data.demand),
234  m_type(type),
235  problem(p_problem) {
236  }
237 
238 
240  size_t id,
241  int64_t original_id,
242  double x,
243  double y,
244  double opens,
245  double closes,
246  double service_time,
247  double demand,
248  NodeType type,
249  const Pgr_pickDeliver *p_problem) :
250  Node(id, original_id, x, y),
251  m_opens(opens),
252  m_closes(closes),
253  m_service_time(service_time),
254  m_demand(demand),
255  m_type(type),
256  problem(p_problem) {
257  }
258 
259 
261 std::ostream& operator << (std::ostream &log, const Tw_node &n) {
262  log << static_cast<const Node&>(n)
263  << "[opens = " << n.m_opens
264  << "\tcloses = " << n.m_closes
265  << "\tservice = " << n.m_service_time
266  << "\tdemand = " << n.m_demand
267  << "\ttype = " << n.type_str()
268  << "]";
269  if (n.is_pickup() || n.is_delivery()) {
270  log << "->" << n.m_otherid << "\n";
271  } else {
272  log << "\n";
273  }
274  return log;
275 }
276 
277 } // namespace vrp
278 } // namespace pgrouting
279 
double m_opens
opening time of the node
Definition: tw_node.h:289
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
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 distance(const Node &other) const
Definition: node.cpp:49
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 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
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
NodeType m_type
The demand for the Node.
Definition: tw_node.h:294
size_t m_otherid
the other's internal id
Definition: tw_node.h:293
std::ostream & operator<<(std::ostream &log, const Node &node)
Definition: node.cpp:41