pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
28 #include <cassert>
29 #include "./vehicle_node.h"
30 
31 namespace pgrouting {
32 namespace vrp {
33 
34 
38 void
39 Vehicle_node::evaluate(double cargoLimit) {
40  if (is_start()) {
41  /* time */
42  m_travel_time = 0;
44  m_wait_time = 0;
46 
47  /* time aggregates */
49  m_tot_wait_time = 0;
51 
52  /* cargo aggregates */
53  m_cargo = demand();
54 
55  /* violation aggregates */
56  m_twvTot = m_cvTot = 0;
57  m_cvTot = has_cv(cargoLimit) ? 1 : 0;
58  m_delta_time = 0;
59  }
60 }
61 
66 void
67 Vehicle_node::evaluate(const Vehicle_node &pred, double cargoLimit) {
68  /* time */
69  m_travel_time = pred.travel_time_to(*this);
72  opens() - m_arrival_time :
73  0;
75 
76  /* time aggregates */
80 
81  /* cargo aggregates */
82  if (is_dump() && pred.cargo() >= 0) {
83  m_demand = -pred.cargo();
84  }
85  m_cargo = pred.cargo() + demand();
86 
87  /* cargo aggregates */
88 
89  m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot();
90  m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot();
92 }
93 
94 
95 
96 std::ostream&
97 operator << (std::ostream &log, const Vehicle_node &v) {
98  log << static_cast<Tw_node>(v)
99  << " twv = " << v.has_twv()
100  << ", twvTot = " << v.twvTot()
101  << ", cvTot = " << v.cvTot()
102  << ", cargo = " << v.cargo()
103  << ", travel _time = " << v.travel_time()
104  << ", arrival _time = " << v.arrival_time()
105  << ", wait _time = " << v.wait_time()
106  << ", service _time = " << v.service_time()
107  << ", departure _time = " << v.departure_time();
108  return log;
109 }
110 
111 
119  : Tw_node(node),
120  m_travel_time(0),
121  m_arrival_time(0),
122  m_wait_time(0),
123  m_departure_time(0),
124  m_delta_time(0),
125  m_cargo(0),
126  m_twvTot(0),
127  m_cvTot(0),
128  m_tot_wait_time(0),
129  m_tot_travel_time(0),
130  m_tot_service_time(0) {
131  }
132 
133 
134 
135 bool
136 Vehicle_node::deltaGeneratesTWV(double delta_time) const {
137  return is_late_arrival(m_arrival_time + delta_time);
138 }
139 
140 
146 double
148  return other.arrival_time()
149  + other.service_time()
150  + other.travel_time_to(*this);
151 }
152 
153 } // namespace vrp
154 } // 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:130
double m_tot_wait_time
Accumulated wait time.
Definition: vehicle_node.h:175
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:94
bool is_early_arrival(double arrival_time) const
True when arrivalTime is before it opens.
Definition: tw_node.h:196
double m_demand
The demand for the Node.
Definition: tw_node.h:292
bool has_twv() const
True when at this node does not violate time windows.
Definition: vehicle_node.h:122
double m_tot_travel_time
Accumulated travel time.
Definition: vehicle_node.h:176
double travel_time_to(const Node &other) const
time = distance / speed.
Definition: tw_node.cpp:40
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:46
double m_delta_time
Departure time - last nodes departure time.
Definition: vehicle_node.h:165
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:97
double opens() const
@ {
Definition: tw_node.h:88
double arrival_time() const
Truck's arrival_time to this node.
Definition: vehicle_node.h:63
static size_t pred(size_t i, size_t n)
Definition: pgr_tsp.cpp:70
double total_travel_time() const
_time spent moving between nodes by the truck
Definition: vehicle_node.h:97
int cvTot() const
Truck's total times it has violated cargo limits.
Definition: vehicle_node.h:88
PGDLLEXPORT Datum vrp(PG_FUNCTION_ARGS)
Definition: VRP.c:730
double m_arrival_time
Arrival time at this node.
Definition: vehicle_node.h:162
bool is_late_arrival(double arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:201
double total_wait_time() const
_time spent by the truck waiting for nodes to open
Definition: vehicle_node.h:100
double arrival_i_arrives_j(const Vehicle_node &other) const
@ {
bool is_start() const
@ {
Definition: tw_node.cpp:122
double cargo() const
Truck's total cargo after the node was served.
Definition: vehicle_node.h:91
Vehicle_node(const Vehicle_node &node)=default
Construct from parameters.
double wait_time() const
Truck's wait_time at this node.
Definition: vehicle_node.h:66
int m_twvTot
Total count of TWV.
Definition: vehicle_node.h:173
double departure_time() const
Truck's departure_time from this node.
Definition: vehicle_node.h:69
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
double travel_time() const
@ {
Definition: vehicle_node.h:60
double total_service_time() const
_time spent by the truck servicing the nodes
Definition: vehicle_node.h:103
void evaluate(double cargoLimit)
@ {
double m_wait_time
Wait time at this node when early arrival.
Definition: vehicle_node.h:163
int m_cvTot
Total count of CV.
Definition: vehicle_node.h:174
std::ostream & operator<<(std::ostream &log, const Node &node)
Definition: node.cpp:41