PGROUTING  3.2
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 "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);
74  m_arrival_time = pred.departure_time() + travel_time();
76  opens() - m_arrival_time :
77  0;
79 
80  /* time aggregates */
81  m_tot_travel_time = pred.total_travel_time() + travel_time();
82  m_tot_wait_time = pred.total_wait_time() + wait_time();
83  m_tot_service_time = pred.total_service_time() + service_time();
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();
95  m_delta_time = departure_time() - pred.departure_time();
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),
133  m_tot_travel_time(0),
134  m_tot_service_time(0) {
135  }
136 
137 
138 
139 
140 } // namespace vrp
141 } // namespace pgrouting
pgrouting::vrp::Vehicle_node::m_tot_travel_time
double m_tot_travel_time
Accumulated travel time.
Definition: vehicle_node.h:170
pgrouting::vrp::Vehicle_node::m_departure_time
double m_departure_time
Definition: vehicle_node.h:158
pgrouting::vrp::Vehicle_node::m_twvTot
int m_twvTot
Total count of TWV.
Definition: vehicle_node.h:167
pgrouting::vrp::Vehicle_node::departure_time
double departure_time() const
Truck's departure_time from this node.
Definition: vehicle_node.h:71
pgrouting::vrp::Vehicle_node::m_travel_time
double m_travel_time
@ {
Definition: vehicle_node.h:155
pgrouting::vrp::Vehicle_node::m_cvTot
int m_cvTot
Total count of CV.
Definition: vehicle_node.h:168
vehicle_node.h
pgrouting::vrp::Vehicle_node
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:48
pgrouting::vrp::Vehicle_node::cvTot
int cvTot() const
Truck's total times it has violated cargo limits.
Definition: vehicle_node.h:90
pgrouting::vrp::Tw_node::demand
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:82
pgrouting::vrp::operator<<
std::ostream & operator<<(std::ostream &log, const Swap_info &d)
Definition: book_keeping.cpp:47
pgrouting::vrp::Vehicle_node::m_cargo
double m_cargo
@ {
Definition: vehicle_node.h:166
pgrouting::vrp::Vehicle_node::m_delta_time
double m_delta_time
Departure time - last nodes departure time.
Definition: vehicle_node.h:159
pgrouting::vrp::Tw_node::is_early_arrival
bool is_early_arrival(double arrival_time) const
True when arrivalTime is before it opens.
Definition: tw_node.h:179
pred
static size_t pred(size_t i, size_t n)
Definition: pgr_tsp.cpp:64
pgrouting::vrp::Vehicle_node::travel_time
double travel_time() const
@ {
Definition: vehicle_node.h:62
pgrouting::vrp::Tw_node::is_start
bool is_start() const
@ {
Definition: tw_node.cpp:88
pgrouting::vrp::Vehicle_node::has_cv
bool has_cv(double cargoLimit) const
True when not violation.
Definition: vehicle_node.h:130
pgrouting::vrp::Vehicle_node::twvTot
int twvTot() const
@ {
Definition: vehicle_node.h:87
pgrouting::vrp::Vehicle_node::m_wait_time
double m_wait_time
Wait time at this node when early arrival.
Definition: vehicle_node.h:157
pgrouting::vrp::Vehicle_node::evaluate
void evaluate(double cargoLimit)
@ {
Definition: vehicle_node.cpp:38
pgrouting::vrp::Tw_node
Extends the Node class to create a Node with time window attributes.
Definition: tw_node.h:57
pgrouting::vrp::Vehicle_node::m_arrival_time
double m_arrival_time
Arrival time at this node.
Definition: vehicle_node.h:156
pgrouting::vrp::Vehicle_node::m_tot_wait_time
double m_tot_wait_time
Accumulated wait time.
Definition: vehicle_node.h:169
pgrouting::vrp::Tw_node::opens
double opens() const
Returns the opening time.
Definition: tw_node.h:76
pgrouting::vrp::Tw_node::service_time
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:86
pgrouting::vrp::Vehicle_node::wait_time
double wait_time() const
Truck's wait_time at this node.
Definition: vehicle_node.h:68
pgrouting::vrp::Vehicle_node::Vehicle_node
Vehicle_node()=delete
Construct from parameters.
pgrouting::vrp::Vehicle_node::arrival_time
double arrival_time() const
Truck's arrival_time to this node.
Definition: vehicle_node.h:65
pgrouting::vrp::Tw_node::is_dump
bool is_dump() const
is_dump
Definition: tw_node.cpp:115
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::vrp::Vehicle_node::cargo
double cargo() const
Truck's total cargo after the node was served.
Definition: vehicle_node.h:93
pgrouting::vrp::Vehicle_node::has_twv
bool has_twv() const
True when at this node does not violate time windows.
Definition: vehicle_node.h:122
pgrouting::vrp::Vehicle_node::m_tot_service_time
double m_tot_service_time
Definition: vehicle_node.h:171