PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vehicle.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: vehicle.h
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 #pragma once
27 
28 #include <deque>
29 #include <iostream>
30 #include <algorithm>
31 #include <string>
32 #include <tuple>
33 #include <utility>
34 #include <vector>
35 
36 
37 #include "./vehicle_node.h"
38 
39 namespace pgrouting {
40 namespace vrp {
41 
42 
62 class Vehicle {
63  protected:
64  typedef size_t ID;
65  typedef size_t POS;
67  std::deque< Vehicle_node > m_path;
68  double max_capacity;
69 
70  public:
71  /*
72  * (twv, cv, fleet_size, wait_time, dureation)
73  */
74  typedef std::tuple< int, int, size_t, double, double > Cost;
76  int vid,
77  std::vector< General_vehicle_orders_t > &result) const;
78 
79  Vehicle(
80  ID id,
81  const Vehicle_node &starting_site,
82  const Vehicle_node &ending_site,
83  double max_capacity);
84 
85 
86 
104  void invariant() const;
105 
106 
108 
115  void insert(POS pos, Vehicle_node node);
116 
117 
125  POS insert(std::pair<POS, POS> position_limits, const Vehicle_node &node);
126 
127 
128 
129 
130 
140  void push_back(const Vehicle_node &node);
141 
151  void push_front(const Vehicle_node &node);
152 
153 
161  void pop_back();
162 
170  void pop_front();
171 
181  void erase(const Vehicle_node &node);
182 
183 
184 
195  void erase(POS pos);
196 
204  bool empty() const;
205 
206  ID id() const {return m_id;}
207 
208 
210  Cost cost() const;
211  bool cost_compare(const Cost&, const Cost&) const;
212 
213  double duration() const {
214  return m_path.back().departure_time();
215  }
216  double total_wait_time() const {
217  return m_path.back().total_wait_time();
218  }
219  double total_travel_time() const {
220  return m_path.back().total_travel_time();
221  }
222  double total_service_time() const {
223  return m_path.back().total_service_time();
224  }
225  double free_time() const {
226  return total_wait_time() + (m_path[0].closes() - duration());
227  }
228  int twvTot() const {
229  return m_path.back().twvTot();
230  }
231  int cvTot() const {
232  return m_path.back().cvTot();
233  }
234  bool has_twv() const {
235  return twvTot() != 0;
236  }
237  bool has_cv() const {
238  return cvTot() != 0;
239  }
240  bool is_feasable() const {
241  return !(has_twv() || has_cv());
242  }
244 
245 
246 
258  void swap(POS i, POS j);
259 
260 
277 
280  void evaluate();
281 
287  void evaluate(POS from);
288 
290 
291  double deltaTime(const Vehicle_node &node, POS pos) const;
292  POS insert_less_travel_time(const Vehicle_node &node, POS after_pos = 0);
293 
294 
295 
297 
299  std::deque< Vehicle_node > path() const;
300 
302 
304 
306 
307  friend std::ostream& operator << (std::ostream &log, const Vehicle &v);
308 
309  std::string tau() const;
310 
311  friend bool operator<(const Vehicle &lhs, const Vehicle &rhs);
312 
314 
315 
316 
317  std::pair<POS, POS> position_limits(const Vehicle_node node) const;
318 
319  private:
320  POS getPosLowLimit(const Vehicle_node &node) const;
321  POS getPosHighLimit(const Vehicle_node &node) const;
322 };
323 
324 } // namespace vrp
325 } // namespace pgrouting
std::pair< POS, POS > position_limits(const Vehicle_node node) const
Definition: vehicle.cpp:377
POS getPosLowLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:399
friend std::ostream & operator<<(std::ostream &log, const Vehicle &v)
@ {
Definition: vehicle.cpp:488
POS getPosHighLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:431
std::deque< Vehicle_node > path() const
@ {
Definition: vehicle.cpp:370
POS insert_less_travel_time(const Vehicle_node &node, POS after_pos=0)
Definition: vehicle.cpp:205
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:46
void swap(POS i, POS j)
Swap two nodes in the path.
Definition: vehicle.cpp:318
void pop_front()
Evaluated: pop_front a node to the path.
Definition: vehicle.cpp:290
Vehicle(ID id, const Vehicle_node &starting_site, const Vehicle_node &ending_site, double max_capacity)
Definition: vehicle.cpp:450
int cvTot() const
Definition: vehicle.h:231
double total_wait_time() const
Definition: vehicle.h:216
double total_service_time() const
Definition: vehicle.h:222
bool has_twv() const
Definition: vehicle.h:234
double duration() const
Definition: vehicle.h:213
Vehicle with time windows.
Definition: vehicle.h:62
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
Cost cost() const
@ {
Definition: vehicle.cpp:156
PGDLLEXPORT Datum vrp(PG_FUNCTION_ARGS)
Definition: VRP.c:732
double total_travel_time() const
Definition: vehicle.h:219
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:164
std::string tau() const
Definition: vehicle.cpp:468
void get_postgres_result(int vid, std::vector< General_vehicle_orders_t > &result) const
Definition: vehicle.cpp:135
double deltaTime(const Vehicle_node &node, POS pos) const
Definition: vehicle.cpp:178
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:343
friend bool operator<(const Vehicle &lhs, const Vehicle &rhs)
Definition: vehicle.cpp:500
void pop_back()
Evaluated: pop_back a node to the path.
Definition: vehicle.cpp:279
bool cost_compare(const Cost &, const Cost &) const
Definition: vehicle.cpp:88
double free_time() const
Definition: vehicle.h:225
bool has_cv() const
Definition: vehicle.h:237
void push_front(const Vehicle_node &node)
Evaluated: push_back a node to the path.
Definition: vehicle.cpp:252
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:228
void push_back(const Vehicle_node &node)
Evaluated: push_back a node to the path.
Definition: vehicle.cpp:269
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:74
bool is_feasable() const
Definition: vehicle.h:240
std::deque< Vehicle_node > m_path
Definition: vehicle.h:67
int twvTot() const
Definition: vehicle.h:228