vrpRouting  0.3
vehicle_node.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: vehicle_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 
27 #include "problem/vehicle_node.h"
28 #include "cpp_common/pgr_assert.h"
29 #include "c_types/solution_rt.h"
30 
31 
32 namespace vrprouting {
33 namespace problem {
34 
38 double
40  return static_cast<double>(travel_time());
41 }
42 
51 void
53  pgassert(is_start());
54  /* time */
55  m_travel_time = 0;
57  m_wait_time = 0;
59 
60  /* time aggregates */
62  m_tot_wait_time = 0;
64 
65  /* cargo aggregates */
66  m_cargo = demand();
67 
68  /* violation aggregates */
69  m_twvTot = m_cvTot = 0;
70  m_cvTot = has_cv(cargoLimit) ? 1 : 0;
71  m_delta_time = 0;
72 }
73 
74 
80 void
82  const Vehicle_node &pred,
83  PAmount cargoLimit,
84  Speed speed
85  ) {
86  /* time */
87  m_travel_time = pred.travel_time_to(*this, pred.departure_time(), speed);
90  opens() - m_arrival_time :
91  0;
93 
94  /* time aggregates */
98 
99  /* cargo aggregates */
100  if (is_dump() && pred.cargo() >= 0) {
101  demand(-pred.cargo());
102  }
103  m_cargo = pred.cargo() + demand();
104 
105  /* violations aggregates */
106 
107  m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot();
108  m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot();
110 }
111 
112 
118 std::ostream&
119 operator << (std::ostream &log, const Vehicle_node &v) {
120  log << static_cast<const Tw_node&>(v)
121  << " twv = " << v.has_twv()
122  << ", twvTot = " << v.twvTot()
123  << ", cvTot = " << v.cvTot()
124  << ", cargo = " << v.cargo()
125  << ", travel_time = " << v.travel_time()
126  << ", arrival_time = " << v.arrival_time()
127  << ", wait_time = " << v.wait_time()
128  << ", service_time = " << v.service_time()
129  << ", departure_time = " << v.departure_time();
130  return log;
131 }
132 
133 
142  : Tw_node(node),
143  m_travel_time(0),
144  m_arrival_time(0),
145  m_wait_time(0),
146  m_departure_time(0),
147  m_delta_time(0),
148  m_cargo(0),
149  m_twvTot(0),
150  m_cvTot(0),
151  m_tot_wait_time(0),
152  m_tot_travel_time(0),
153  m_tot_service_time(0) {
154  }
155 
156 
157 bool
160 }
161 
162 
171 bool
172 Vehicle_node::has_cv(PAmount cargoLimit) const {
173  return is_end() || is_start() ? m_cargo != 0
174  : m_cargo > cargoLimit || m_cargo < 0;
175 }
176 
177 
181 bool
184 }
185 
193 Vehicle_node::get_postgres_result(int vid, int64_t v_id, int stop_seq) const {
194  return Solution_rt{
195  vid,
196  v_id,
197  stop_seq,
198  /* order_id
199  * The order_id is invalid for stops type 0 and 5
200  */
201  (type() == 0 || type() == 5)? -1 : order(),
202  id(),
203  type(),
204  static_cast<int64_t>(cargo()),
205  static_cast<int64_t>(travel_time()),
206  static_cast<int64_t>(arrival_time()),
207  static_cast<int64_t>(wait_time()),
208  static_cast<int64_t>(arrival_time() + wait_time()),
209  static_cast<int64_t>(service_time()),
210  static_cast<int64_t>(departure_time()),
211  cvTot(),
212  twvTot()};
213 }
214 
215 } // namespace problem
216 } // namespace vrprouting
vrprouting::problem::Vehicle_node::arrival_time
TTimestamp arrival_time() const
Vehicle's arrival_time to this node.
Definition: vehicle_node.h:68
vrprouting::problem::Vehicle_node::get_postgres_result
Solution_rt get_postgres_result(int vid, int64_t v_id, int stop_seq) const
Definition: vehicle_node.cpp:193
vrprouting::problem::Vehicle_node::twvTot
int twvTot() const
Vehicle's total times it has violated time windows.
Definition: vehicle_node.h:80
vrprouting::problem::Vehicle_node::m_delta_time
TInterval m_delta_time
Departure time - last nodes departure time.
Definition: vehicle_node.h:157
vrprouting::problem::Vehicle_node::m_travel_time
TInterval m_travel_time
Travel time from last node.
Definition: vehicle_node.h:142
vrprouting::Identifier::id
int64_t id() const
get the original id
Definition: identifier.cpp:42
vehicle_node.h
vrprouting::problem::Tw_node::demand
Amount demand() const
Returns the demand associated with this node.
Definition: tw_node.h:163
vrprouting::problem::Vehicle_node::Vehicle_node
Vehicle_node()=delete
Construction without information is not allowed.
vrprouting::problem::Vehicle_node::has_twv
bool has_twv() const
does the node violates the time windows constraints?
Definition: vehicle_node.cpp:182
vrprouting::problem::Vehicle_node::total_service_time
TInterval total_service_time() const
_time spent by the truck servicing the nodes
Definition: vehicle_node.h:95
vrprouting::problem::operator<<
std::ostream & operator<<(std::ostream &log, const Order &order)
Prints:
Definition: order.cpp:77
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
vrprouting::problem::Tw_node::service_time
TInterval service_time() const
Returns the service time for this node.
Definition: tw_node.h:84
vrprouting::problem::Tw_node::is_dump
bool is_dump() const
Is the node a valid vehicle's dumping node.
Definition: tw_node.cpp:222
vrprouting::problem::Tw_node::type
auto type() const
Returns the type of this node.
Definition: tw_node.h:87
Speed
double Speed
Definition: typedefs.h:76
vrprouting::problem::Vehicle_node::delta_time
TInterval delta_time() const
delta_time = departure_time(this) - departure_time(previous)
Definition: vehicle_node.h:120
vrprouting::problem::Tw_node::is_late_arrival
bool is_late_arrival(TTimestamp arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:121
vrprouting::problem::Vehicle_node::total_wait_time
TInterval total_wait_time() const
_time spent by the truck waiting for nodes to open
Definition: vehicle_node.h:92
vrprouting::problem::Vehicle_node
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:49
vrprouting::problem::Vehicle_node::cvTot
int cvTot() const
Vehicle's total times it has violated cargo limits.
Definition: vehicle_node.h:83
vrprouting::problem::Vehicle_node::has_cv
bool has_cv(PAmount cargoLimit) const
does the node violates the capacity constraints?
Definition: vehicle_node.cpp:172
vrprouting::problem::Vehicle_node::m_tot_wait_time
TInterval m_tot_wait_time
Accumulated wait time.
Definition: vehicle_node.h:174
vrprouting::problem::Vehicle_node::departure_time
TTimestamp departure_time() const
Vehicle's departure_time from this node.
Definition: vehicle_node.h:74
vrprouting::problem::Vehicle_node::m_cargo
Amount m_cargo
Accumulated cargo.
Definition: vehicle_node.h:165
Solution_rt
Solution schedule when twv & cw are hard restrictions.
Definition: solution_rt.h:56
pgr_assert.h
An assert functionality that uses C++ throw().
vrprouting::problem::Vehicle_node::total_travel_time
TInterval total_travel_time() const
_time spent moving between nodes by the truck
Definition: vehicle_node.h:89
vrprouting::problem::Vehicle_node::travel_time
TInterval travel_time() const
Vehicle's travel_time from previous node to this node.
Definition: vehicle_node.h:65
vrprouting::problem::Vehicle_node::m_twvTot
int m_twvTot
Total count of TWV.
Definition: vehicle_node.h:168
vrprouting::problem::Vehicle_node::m_tot_travel_time
TInterval m_tot_travel_time
Accumulated travel time.
Definition: vehicle_node.h:177
vrprouting::problem::Vehicle_node::m_tot_service_time
TInterval m_tot_service_time
Accumulated service time.
Definition: vehicle_node.h:180
vrprouting::problem::Tw_node
Time window attributes of a node.
Definition: tw_node.h:54
vrprouting::problem::Tw_node::order
int64_t order() const
Returns the order to which it belongs.
Definition: tw_node.h:75
vrprouting::problem::Tw_node::is_end
bool is_end() const
Is the node a valid vehicle's ending node.
Definition: tw_node.cpp:245
vrprouting::problem::Vehicle_node::objective
double objective() const
the basic objective function for this node
Definition: vehicle_node.cpp:39
solution_rt.h
vrprouting::problem::Vehicle_node::m_wait_time
TInterval m_wait_time
Wait time at this node.
Definition: vehicle_node.h:151
vrprouting::problem::Vehicle_node::cargo
Amount cargo() const
Vehicle's total cargo after the node was served.
Definition: vehicle_node.h:86
vrprouting::problem::Vehicle_node::wait_time
TInterval wait_time() const
Vehicle's wait_time at this node.
Definition: vehicle_node.h:71
PAmount
uint32_t PAmount
Definition: typedefs.h:75
TInterval
int64_t TInterval
Definition: typedefs.h:72
vrprouting::problem::Tw_node::is_early_arrival
bool is_early_arrival(TTimestamp arrival_time) const
True when arrivalTime is before it opens.
Definition: tw_node.h:126
vrprouting::problem::Vehicle_node::m_arrival_time
TTimestamp m_arrival_time
Arrival time at this node.
Definition: vehicle_node.h:145
vrprouting::problem::Vehicle_node::m_departure_time
TTimestamp m_departure_time
Departure time from this node.
Definition: vehicle_node.h:154
vrprouting::problem::Tw_node::travel_time_to
TInterval travel_time_to(const Tw_node &, TTimestamp, Speed=1.0) const
travel time to other node.
Definition: tw_node.cpp:51
vrprouting::problem::Tw_node::opens
TTimestamp opens() const
Returns the opening time.
Definition: tw_node.h:78
vrprouting::problem::Vehicle_node::deltaGeneratesTWV
bool deltaGeneratesTWV(TInterval delta_time) const
True when arrival_time + delta_time generates TWV.
Definition: vehicle_node.cpp:158
vrprouting::problem::Tw_node::is_start
bool is_start() const
Is the node a valid vehicle's starting node.
Definition: tw_node.cpp:187
vrprouting::problem::Vehicle_node::evaluate
void evaluate(PAmount cargoLimit)
evaluate this node
Definition: vehicle_node.cpp:52
vrprouting
Definition: base_matrix.cpp:46
vrprouting::problem::Vehicle_node::m_cvTot
int m_cvTot
Total count of CV.
Definition: vehicle_node.h:171