PGROUTING  2.5
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
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 
27 #include "vrp/vehicle_node.h"
28 
29 
30 namespace pgrouting {
31 namespace vrp {
32 
33 
37 void
38 Vehicle_node::evaluate(double cargoLimit) {
39  if (is_start()) {
40  /* time */
41  m_travel_time = 0;
43  m_wait_time = 0;
45 
46  /* time aggregates */
48  m_tot_wait_time = 0;
50 
51  /* cargo aggregates */
52  m_cargo = demand();
53 
54  /* violation aggregates */
55  m_twvTot = m_cvTot = 0;
56  m_cvTot = has_cv(cargoLimit) ? 1 : 0;
57  m_delta_time = 0;
58  }
59 }
60 
61 
67 void
69  const Vehicle_node &pred,
70  double cargoLimit,
71  double speed) {
72  /* time */
73  m_travel_time = pred.travel_time_to(*this, speed);
76  opens() - m_arrival_time :
77  0;
79 
80  /* time aggregates */
84 
85  /* cargo aggregates */
86  if (is_dump() && pred.cargo() >= 0) {
87  demand(-pred.cargo());
88  }
89  m_cargo = pred.cargo() + demand();
90 
91  /* violations aggregates */
92 
93  m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot();
94  m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot();
96 }
97 
98 
99 
100 std::ostream&
101 operator << (std::ostream &log, const Vehicle_node &v) {
102  log << static_cast<const Tw_node&>(v)
103  << " twv = " << v.has_twv()
104  << ", twvTot = " << v.twvTot()
105  << ", cvTot = " << v.cvTot()
106  << ", cargo = " << v.cargo()
107  << ", travel_time = " << v.travel_time()
108  << ", arrival_time = " << v.arrival_time()
109  << ", wait_time = " << v.wait_time()
110  << ", service_time = " << v.service_time()
111  << ", departure_time = " << v.departure_time();
112  return log;
113 }
114 
115 
123  : Tw_node(node),
124  m_travel_time(0),
125  m_arrival_time(0),
126  m_wait_time(0),
127  m_departure_time(0),
128  m_delta_time(0),
129  m_cargo(0),
130  m_twvTot(0),
131  m_cvTot(0),
132  m_tot_wait_time(0),
134  m_tot_service_time(0) {
135  }
136 
137 
138 
139 bool
141  return is_late_arrival(m_arrival_time + delta_time);
142 }
143 
144 
150 double
152  const Vehicle_node &other,
153  double speed) const {
154  return other.arrival_time()
155  + other.service_time()
156  + other.travel_time_to(*this, speed);
157 }
158 
159 } // namespace vrp
160 } // namespace pgrouting
bool deltaGeneratesTWV(double delta_time) const
True when arrival_time + delta_time generates TWV.
bool has_cv(double cargoLimit) const
True when not violation.
Definition: vehicle_node.h:132
double m_tot_wait_time
Accumulated wait time.
Definition: vehicle_node.h:180
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:82
bool is_early_arrival(double arrival_time) const
True when arrivalTime is before it opens.
Definition: tw_node.h:187
double delta_time() const
delta_time = departure_time(this) - departure_time(previous)
Definition: vehicle_node.h:74
bool has_twv() const
True when at this node does not violate time windows.
Definition: vehicle_node.h:124
double m_tot_travel_time
Accumulated travel time.
Definition: vehicle_node.h:181
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:48
double m_delta_time
Departure time - last nodes departure time.
Definition: vehicle_node.h:170
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:86
double opens() const
Returns the opening time.
Definition: tw_node.h:76
double arrival_time() const
Truck&#39;s arrival_time to this node.
Definition: vehicle_node.h:65
static size_t pred(size_t i, size_t n)
Definition: pgr_tsp.cpp:64
double total_travel_time() const
_time spent moving between nodes by the truck
Definition: vehicle_node.h:99
int cvTot() const
Truck&#39;s total times it has violated cargo limits.
Definition: vehicle_node.h:90
double m_arrival_time
Arrival time at this node.
Definition: vehicle_node.h:167
bool is_late_arrival(double arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:192
double total_wait_time() const
_time spent by the truck waiting for nodes to open
Definition: vehicle_node.h:102
friend std::ostream & operator<<(std::ostream &log, const Vehicle_node &node)
@ {
bool is_start() const
@ {
Definition: tw_node.cpp:132
double cargo() const
Truck&#39;s total cargo after the node was served.
Definition: vehicle_node.h:93
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
double wait_time() const
Truck&#39;s wait_time at this node.
Definition: vehicle_node.h:68
int m_twvTot
Total count of TWV.
Definition: vehicle_node.h:178
double departure_time() const
Truck&#39;s departure_time from this node.
Definition: vehicle_node.h:71
bool is_dump() const
is_dump
Definition: tw_node.cpp:162
double arrival_i_arrives_j(const Vehicle_node &other, double speed) const
@ {
Extends the Node class to create a Node with time window attributes.
Definition: tw_node.h:57
Vehicle_node()
Construct from parameters.
Definition: vehicle_node.h:158
double travel_time() const
@ {
Definition: vehicle_node.h:62
double total_service_time() const
_time spent by the truck servicing the nodes
Definition: vehicle_node.h:105
void evaluate(double cargoLimit)
@ {
double m_wait_time
Wait time at this node when early arrival.
Definition: vehicle_node.h:168
double travel_time_to(const Tw_node &other, double speed) const
time = distance / speed.
Definition: tw_node.cpp:40
int m_cvTot
Total count of CV.
Definition: vehicle_node.h:179