PGROUTING  3.2
vehicle.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: vehicle.h
4 
5 Copyright (c) 2016 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 
28 #ifndef INCLUDE_VRP_VEHICLE_H_
29 #define INCLUDE_VRP_VEHICLE_H_
30 #pragma once
31 
32 #include <deque>
33 #include <iostream>
34 #include <algorithm>
35 #include <string>
36 #include <tuple>
37 #include <utility>
38 #include <vector>
39 
40 
41 #include "cpp_common/identifier.h"
42 #include "vrp/vehicle_node.h"
44 
45 namespace pgrouting {
46 namespace vrp {
47 
48 class Pgr_pickDeliver;
49 
73 class Vehicle : public Identifier {
74  protected:
75  typedef size_t POS;
76  using difference_type = std::deque<Vehicle_node>::difference_type;
77  std::deque< Vehicle_node > m_path;
78 
79  friend class PD_problem;
80 
81  private:
82  double m_capacity;
83  double m_factor;
84  double m_speed;
85 
86  public:
87  /*
88  * (twv, cv, fleet_size, wait_time, duration)
89  */
90  typedef std::tuple< int, int, size_t, double, double > Cost;
91  std::vector<General_vehicle_orders_t>
92  get_postgres_result(int vid) const;
93 
94  Vehicle(const Vehicle &) = default;
95  Vehicle(
96  size_t idx,
97  int64_t id,
98  const Vehicle_node &starting_site,
99  const Vehicle_node &ending_site,
100  double p_capacity,
101  double p_speed,
102  double p_factor);
103 
104 
105  bool is_phony() const {return id() < 0;}
106  double speed() const;
107 
125  void invariant() const;
126 
127 
129 
136  void insert(POS pos, Vehicle_node node);
137 
138 
146  POS insert(std::pair<POS, POS> position_limits, const Vehicle_node &node);
147 
148 
149 
150 
151 
152 
162  void erase(const Vehicle_node &node);
163 
164 
165 
176  void erase(POS pos);
177 
185  bool empty() const;
186 
194  size_t size() const;
195 
196 
198  Cost cost() const;
199  bool cost_compare(const Cost&, const Cost&) const;
200 
201  double duration() const {
202  return m_path.back().departure_time();
203  }
204  double total_wait_time() const {
205  return m_path.back().total_wait_time();
206  }
207  double total_travel_time() const {
208  return m_path.back().total_travel_time();
209  }
210  double total_service_time() const {
211  return m_path.back().total_service_time();
212  }
213  int twvTot() const {
214  return m_path.back().twvTot();
215  }
216  int cvTot() const {
217  return m_path.back().cvTot();
218  }
219  bool has_twv() const {
220  return twvTot() != 0;
221  }
222  bool has_cv() const {
223  return cvTot() != 0;
224  }
225 
226  bool is_feasable() const {
227  return !(has_twv() || has_cv());
228  }
229 
230  bool is_ok() const;
231 
233  return m_path.front();
234  }
236  return m_path.back();
237  }
238  double capacity() const {return m_capacity;}
240 
241 
242 
254  void swap(POS i, POS j);
255 
256 
273 
276  void evaluate();
277 
283  void evaluate(POS from);
284 
286 
287 
288 
289 
291 
293  std::deque< Vehicle_node > path() const;
294 
296 
298 
300 
301  friend std::ostream& operator << (std::ostream &log, const Vehicle &v);
302 
303  std::string tau() const;
304 
305  friend bool operator<(const Vehicle &lhs, const Vehicle &rhs);
306 
308 
309 
310 
311  std::pair<POS, POS> position_limits(const Vehicle_node node) const;
312  std::pair<POS, POS> drop_position_limits(const Vehicle_node node) const;
313 
316 
318  static Pgr_messages& msg();
319 
320  private:
321  POS getDropPosLowLimit(const Vehicle_node &node) const;
322  POS getPosLowLimit(const Vehicle_node &node) const;
323  POS getPosHighLimit(const Vehicle_node &node) const;
324 };
325 
326 } // namespace vrp
327 } // namespace pgrouting
328 
329 #endif // INCLUDE_VRP_VEHICLE_H_
pgrouting::Pgr_messages
Definition: pgr_messages.h:39
pgrouting::vrp::Vehicle::m_path
std::deque< Vehicle_node > m_path
Definition: vehicle.h:77
pgrouting::vrp::Vehicle::getPosHighLimit
POS getPosHighLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:392
pgrouting::vrp::Vehicle::speed
double speed() const
Definition: vehicle.cpp:477
pgrouting::vrp::Vehicle::is_ok
bool is_ok() const
Definition: vehicle.cpp:410
pgrouting::vrp::Vehicle::cost
Cost cost() const
Definition: vehicle.cpp:175
pgrouting::vrp::Vehicle::m_capacity
double m_capacity
Definition: vehicle.h:82
pgrouting::vrp::Vehicle::cvTot
int cvTot() const
Definition: vehicle.h:216
pgrouting::vrp::Vehicle::get_postgres_result
std::vector< General_vehicle_orders_t > get_postgres_result(int vid) const
Definition: vehicle.cpp:144
pgrouting::vrp::Vehicle::duration
double duration() const
Definition: vehicle.h:201
general_vehicle_orders_t.h
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::size
size_t size() const
return number of nodes in the truck
Definition: vehicle.cpp:265
pgrouting::vrp::Vehicle::is_feasable
bool is_feasable() const
Definition: vehicle.h:226
pgrouting::vrp::Vehicle::getDropPosLowLimit
POS getDropPosLowLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:327
pgrouting::vrp::Vehicle::m_speed
double m_speed
Definition: vehicle.h:84
pgrouting::vrp::Vehicle::getPosLowLimit
POS getPosLowLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:360
pgrouting::Identifier::idx
size_t idx() const
Definition: identifier.cpp:37
pgrouting::vrp::Vehicle::operator<
friend bool operator<(const Vehicle &lhs, const Vehicle &rhs)
Definition: vehicle.cpp:502
pgrouting::vrp::Vehicle::has_cv
bool has_cv() const
Definition: vehicle.h:222
pgrouting::vrp::Vehicle::m_factor
double m_factor
Definition: vehicle.h:83
pgrouting::vrp::Vehicle::path
std::deque< Vehicle_node > path() const
@ {
Definition: vehicle.cpp:292
pgrouting::vrp::Vehicle
Vehicle with time windows.
Definition: vehicle.h:73
pgrouting::vrp::Vehicle::twvTot
int twvTot() const
Definition: vehicle.h:213
pgrouting::vrp::Vehicle::evaluate
void evaluate()
@ {
Definition: vehicle.cpp:250
pgrouting::vrp::Vehicle::POS
size_t POS
Definition: vehicle.h:75
pgrouting::vrp::Pgr_pickDeliver
Definition: pgr_pickDeliver.h:57
pgrouting::vrp::Vehicle::total_service_time
double total_service_time() const
Definition: vehicle.h:210
identifier.h
pgrouting::Identifier::id
int64_t id() const
Definition: identifier.cpp:42
pgrouting::vrp::Vehicle::end_site
Vehicle_node end_site() const
Definition: vehicle.h:235
pgrouting::vrp::Vehicle::capacity
double capacity() const
Definition: vehicle.h:238
pgrouting::vrp::Vehicle::difference_type
std::deque< Vehicle_node >::difference_type difference_type
Definition: vehicle.h:76
pgrouting::vrp::Vehicle::drop_position_limits
std::pair< POS, POS > drop_position_limits(const Vehicle_node node) const
Definition: vehicle.cpp:306
pgrouting::vrp::Vehicle::invariant
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:56
pgrouting::vrp::Vehicle::operator<<
friend std::ostream & operator<<(std::ostream &log, const Vehicle &v)
@ {
Definition: vehicle.cpp:484
pgrouting::vrp::Vehicle::is_phony
bool is_phony() const
Definition: vehicle.h:105
pgrouting::Identifier
Definition: identifier.h:39
pgrouting::vrp::Vehicle::total_travel_time
double total_travel_time() const
Definition: vehicle.h:207
pgrouting::vrp::Vehicle::position_limits
std::pair< POS, POS > position_limits(const Vehicle_node node) const
Definition: vehicle.cpp:299
pgrouting::vrp::Vehicle::total_wait_time
double total_wait_time() const
Definition: vehicle.h:204
pgrouting::vrp::Vehicle::empty
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:259
pgrouting::vrp::Vehicle::problem
static Pgr_pickDeliver * problem
Pointer to problem.
Definition: vehicle.h:315
pgrouting::vrp::Vehicle::has_twv
bool has_twv() const
Definition: vehicle.h:219
pgrouting::vrp::Vehicle::start_site
Vehicle_node start_site() const
Definition: vehicle.h:232
pgrouting::vrp::PD_problem
Definition: pd_problem.h:42
pgrouting::vrp::Vehicle::Vehicle
Vehicle(const Vehicle &)=default
pgrouting::vrp::Vehicle::cost_compare
bool cost_compare(const Cost &, const Cost &) const
Definition: vehicle.cpp:97
pgrouting::vrp::Vehicle::insert
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:183
pgrouting::vrp::Vehicle::Cost
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:90
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::vrp::Vehicle::swap
void swap(POS i, POS j)
Swap two nodes in the path.
Definition: vehicle.cpp:234
pgrouting::vrp::Vehicle::msg
static Pgr_messages & msg()
Access to the problem's message.
Definition: vehicle.cpp:51
pgrouting::vrp::Vehicle::erase
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:198
pgrouting::vrp::Vehicle::tau
std::string tau() const
Definition: vehicle.cpp:457