PGROUTING  2.4
 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 #include "./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 
65 void
66 Vehicle_node::evaluate(const Vehicle_node &pred, double cargoLimit) {
67  /* time */
68  m_travel_time = pred.travel_time_to(*this);
71  opens() - m_arrival_time :
72  0;
74 
75  /* time aggregates */
79 
80  /* cargo aggregates */
81  if (is_dump() && pred.cargo() >= 0) {
82  m_demand = -pred.cargo();
83  }
84  m_cargo = pred.cargo() + demand();
85 
86  /* cargo aggregates */
87 
88  m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot();
89  m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot();
91 }
92 
93 
94 
95 std::ostream&
96 operator << (std::ostream &log, const Vehicle_node &v) {
97  log << static_cast<Tw_node>(v)
98  << " twv = " << v.has_twv()
99  << ", twvTot = " << v.twvTot()
100  << ", cvTot = " << v.cvTot()
101  << ", cargo = " << v.cargo()
102  << ", travel _time = " << v.travel_time()
103  << ", arrival _time = " << v.arrival_time()
104  << ", wait _time = " << v.wait_time()
105  << ", service _time = " << v.service_time()
106  << ", departure _time = " << v.departure_time();
107  return log;
108 }
109 
110 
118  : Tw_node(node),
119  m_travel_time(0),
120  m_arrival_time(0),
121  m_wait_time(0),
122  m_departure_time(0),
123  m_delta_time(0),
124  m_cargo(0),
125  m_twvTot(0),
126  m_cvTot(0),
127  m_tot_wait_time(0),
128  m_tot_travel_time(0),
129  m_tot_service_time(0) {
130  }
131 
132 
133 
134 bool
135 Vehicle_node::deltaGeneratesTWV(double delta_time) const {
136  return is_late_arrival(m_arrival_time + delta_time);
137 }
138 
139 
145 double
147  return other.arrival_time()
148  + other.service_time()
149  + other.travel_time_to(*this);
150 }
151 
152 } // namespace vrp
153 } // 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:65
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:732
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