PGROUTING  2.6-dev
vehicle.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: vehicle.h
4 
5 Copyright (c) 2016 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 
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 
72 class Vehicle : public Identifier, public PD_problem {
73  protected:
74  typedef size_t POS;
75  std::deque< Vehicle_node > m_path;
76 
77  private:
78  double m_capacity;
79  double m_factor;
80  double m_speed;
81 
82  public:
83  /*
84  * (twv, cv, fleet_size, wait_time, duration)
85  */
86  typedef std::tuple< int, int, size_t, double, double > Cost;
87  std::vector<General_vehicle_orders_t>
88  get_postgres_result(int vid) const;
89 
90  Vehicle(const Vehicle &);
91  Vehicle(
92  size_t idx,
93  int64_t kind,
94  const Vehicle_node &starting_site,
95  const Vehicle_node &ending_site,
96  double p_capacity,
97  double p_speed,
98  double p_factor);
99 
100 
101  bool is_phony() const {return id() < 0;}
102  double speed() const;
103 
121  void invariant() const;
122 
123 
125 
132  void insert(POS pos, Vehicle_node node);
133 
134 
142  POS insert(std::pair<POS, POS> position_limits, const Vehicle_node &node);
143 
144 
145 
146 
147 
157  void push_back(const Vehicle_node &node);
158 
168  void push_front(const Vehicle_node &node);
169 
170 
178  void pop_back();
179 
187  void pop_front();
188 
198  void erase(const Vehicle_node &node);
199 
200 
201 
212  void erase(POS pos);
213 
221  bool empty() const;
222 
223 
225  Cost cost() const;
226  bool cost_compare(const Cost&, const Cost&) const;
227 
228  double duration() const {
229  return m_path.back().departure_time();
230  }
231  double total_wait_time() const {
232  return m_path.back().total_wait_time();
233  }
234  double total_travel_time() const {
235  return m_path.back().total_travel_time();
236  }
237  double total_service_time() const {
238  return m_path.back().total_service_time();
239  }
240  double free_time() const {
241  return total_wait_time() + (m_path[0].closes() - duration());
242  }
243  int twvTot() const {
244  return m_path.back().twvTot();
245  }
246  int cvTot() const {
247  return m_path.back().cvTot();
248  }
249  bool has_twv() const {
250  return twvTot() != 0;
251  }
252  bool has_cv() const {
253  return cvTot() != 0;
254  }
255 
256  bool is_feasable() const {
257  return !(has_twv() || has_cv());
258  }
259 
260  bool is_ok() const;
261 
263  return m_path.front();
264  }
266  return m_path.back();
267  }
268 #if 0
269  double speed() const {return m_speed;}
270 #endif
271  double capacity() const {return m_capacity;}
273 
274 
275 
287  void swap(POS i, POS j);
288 
289 
306 
309  void evaluate();
310 
316  void evaluate(POS from);
317 
319 
320  double deltaTime(const Vehicle_node &node, POS pos) const;
321  POS insert_less_travel_time(const Vehicle_node &node, POS after_pos = 0);
322 
323 
324 
326 
328  std::deque< Vehicle_node > path() const;
329 
331 
333 
335 
336  friend std::ostream& operator << (std::ostream &log, const Vehicle &v);
337 
338  std::string tau() const;
339 
340  friend bool operator<(const Vehicle &lhs, const Vehicle &rhs);
341 
343 
344 
345 
346  std::pair<POS, POS> position_limits(const Vehicle_node node) const;
347 
348  private:
349  POS getPosLowLimit(const Vehicle_node &node) const;
350  POS getPosHighLimit(const Vehicle_node &node) const;
351 };
352 
353 } // namespace vrp
354 } // namespace pgrouting
355 
356 #endif // INCLUDE_VRP_VEHICLE_H_
std::pair< POS, POS > position_limits(const Vehicle_node node) const
Definition: vehicle.cpp:388
POS getPosLowLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:410
Vehicle_node start_site() const
Definition: vehicle.h:262
friend std::ostream & operator<<(std::ostream &log, const Vehicle &v)
@ {
Definition: vehicle.cpp:543
POS getPosHighLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:442
int64_t id() const
Definition: identifier.cpp:42
Vehicle(const Vehicle &)
Definition: vehicle.cpp:498
std::deque< Vehicle_node > path() const
@ {
Definition: vehicle.cpp:381
POS insert_less_travel_time(const Vehicle_node &node, POS after_pos=0)
Definition: vehicle.cpp:215
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:48
void swap(POS i, POS j)
Swap two nodes in the path.
Definition: vehicle.cpp:329
void pop_front()
Evaluated: pop_front a node to the path.
Definition: vehicle.cpp:301
int cvTot() const
Definition: vehicle.h:246
bool is_phony() const
Definition: vehicle.h:101
double total_wait_time() const
Definition: vehicle.h:231
double total_service_time() const
Definition: vehicle.h:237
bool has_twv() const
Definition: vehicle.h:249
double duration() const
Definition: vehicle.h:228
Vehicle with time windows.
Definition: vehicle.h:72
double speed() const
Definition: vehicle.cpp:536
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
bool is_ok() const
Definition: vehicle.cpp:460
Cost cost() const
Definition: vehicle.cpp:166
double capacity() const
Definition: vehicle.h:271
double total_travel_time() const
Definition: vehicle.h:234
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:174
std::string tau() const
Definition: vehicle.cpp:516
double deltaTime(const Vehicle_node &node, POS pos) const
Definition: vehicle.cpp:188
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:354
friend bool operator<(const Vehicle &lhs, const Vehicle &rhs)
Definition: vehicle.cpp:561
void pop_back()
Evaluated: pop_back a node to the path.
Definition: vehicle.cpp:290
bool cost_compare(const Cost &, const Cost &) const
Definition: vehicle.cpp:88
double free_time() const
Definition: vehicle.h:240
Vehicle_node end_site() const
Definition: vehicle.h:265
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
bool has_cv() const
Definition: vehicle.h:252
void push_front(const Vehicle_node &node)
Evaluated: push_back a node to the path.
Definition: vehicle.cpp:263
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:238
void push_back(const Vehicle_node &node)
Evaluated: push_back a node to the path.
Definition: vehicle.cpp:280
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:86
size_t idx() const
Definition: identifier.cpp:37
bool is_feasable() const
Definition: vehicle.h:256
std::vector< General_vehicle_orders_t > get_postgres_result(int vid) const
Definition: vehicle.cpp:135
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
int twvTot() const
Definition: vehicle.h:243