PGROUTING  2.6-dev
pgrouting::vrp::Vehicle Class Reference

Vehicle with time windows. More...

#include "vehicle.h"

Inheritance diagram for pgrouting::vrp::Vehicle:
Collaboration diagram for pgrouting::vrp::Vehicle:

Public Types

typedef std::tuple< int, int, size_t, double, double > Cost
 

Public Member Functions

 Vehicle (const Vehicle &)
 
 Vehicle (size_t idx, int64_t kind, const Vehicle_node &starting_site, const Vehicle_node &ending_site, double p_capacity, double p_speed, double p_factor)
 
double deltaTime (const Vehicle_node &node, POS pos) const
 
std::vector< General_vehicle_orders_tget_postgres_result (int vid) const
 
int64_t id () const
 
size_t idx () const
 
POS insert_less_travel_time (const Vehicle_node &node, POS after_pos=0)
 
bool is_phony () const
 
std::pair< POS, POSposition_limits (const Vehicle_node node) const
 
void reset_id (int64_t)
 
double speed () const
 
void swap (POS i, POS j)
 Swap two nodes in the path. More...
 
deque like functions
Returns
True if the operation was performed
Warning
Assertions are performed for out of range operations
no feasability nor time window or capacity violations checks are performed
Todo:
TODO more deque like functions here
void invariant () const
 Invariant The path must: More...
 
void insert (POS pos, Vehicle_node node)
 @ { More...
 
POS insert (std::pair< POS, POS > position_limits, const Vehicle_node &node)
 Insert node in best position of the position_limits. More...
 
void push_back (const Vehicle_node &node)
 Evaluated: push_back a node to the path. More...
 
void push_front (const Vehicle_node &node)
 Evaluated: push_back a node to the path. More...
 
void pop_back ()
 Evaluated: pop_back a node to the path. More...
 
void pop_front ()
 Evaluated: pop_front a node to the path. More...
 
void erase (const Vehicle_node &node)
 Erase node.id() More...
 
void erase (POS pos)
 Erase node at pos from the path. More...
 
bool empty () const
 return true when no nodes are in the truck More...
 
Cost cost () const
 
bool cost_compare (const Cost &, const Cost &) const
 
double duration () const
 
double total_wait_time () const
 
double total_travel_time () const
 
double total_service_time () const
 
double free_time () const
 
int twvTot () const
 
int cvTot () const
 
bool has_twv () const
 
bool has_cv () const
 
bool is_feasable () const
 
bool is_ok () const
 
Vehicle_node start_site () const
 
Vehicle_node end_site () const
 
double capacity () const
 
Evaluation

Path evaluation is done incrementally: from a given position to the end of the path, and intermediate values are cached on each node.

So, for example, changing the path at position 100: the evaluation function should be called as evaluate(100, maxcapacity) and from that position to the end of the path will be evaluated. None of the "unaffected" positions get reevaluated

void evaluate ()
 @ { More...
 
void evaluate (POS from)
 Evaluate: Evaluate a path from the given position. More...
 
accessors
std::deque< Vehicle_nodepath () const
 @ { More...
 

Static Public Attributes

static Pgr_messages msg
 

Protected Types

typedef size_t POS
 

Protected Attributes

std::deque< Vehicle_nodem_path
 

Static Protected Attributes

static Pgr_pickDeliverproblem
 

Private Member Functions

POS getPosHighLimit (const Vehicle_node &node) const
 
POS getPosLowLimit (const Vehicle_node &node) const
 

Private Attributes

double m_capacity
 
double m_factor
 
double m_speed
 

operators

std::string tau () const
 
std::ostream & operator<< (std::ostream &log, const Vehicle &v)
 @ { More...
 
bool operator< (const Vehicle &lhs, const Vehicle &rhs)
 

Detailed Description

Vehicle with time windows.

General functionality for a vehicle in a VRP problem

Recommended use:

Class my_vehicle : public vechicle
Note
All members return true when the operation is successful

A vehicle is a sequence of Vehicle_node from starting site to ending site. has: capacity speed factor TODO(vicky)

See also
Vehicle_node

Definition at line 72 of file vehicle.h.

Member Typedef Documentation

typedef std::tuple< int, int, size_t, double, double > pgrouting::vrp::Vehicle::Cost

Definition at line 86 of file vehicle.h.

typedef size_t pgrouting::vrp::Vehicle::POS
protected

Definition at line 74 of file vehicle.h.

Constructor & Destructor Documentation

pgrouting::vrp::Vehicle::Vehicle ( const Vehicle v)

Definition at line 498 of file vehicle.cpp.

References ENTERING, EXITING, pgrouting::Pgr_messages::log, pgrouting::vrp::PD_problem::msg, and tau().

498  :
499  Identifier(v.idx(), v.id()),
500  PD_problem(),
501  m_path(v.m_path),
502  m_capacity(v.m_capacity),
503  m_factor(v.m_factor),
504  m_speed(v.m_speed) {
505 #if 0
506  ENTERING();
507  msg.log << v.tau() << "\n";
508  msg.log << tau() << "\n";
509  EXITING();
510 #endif
511 }
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
#define EXITING()
Definition: pgr_messages.h:119
#define ENTERING()
Definition: pgr_messages.h:118
std::string tau() const
Definition: vehicle.cpp:516
static Pgr_messages msg
Definition: pd_problem.h:48
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

pgrouting::vrp::Vehicle::Vehicle ( size_t  idx,
int64_t  kind,
const Vehicle_node starting_site,
const Vehicle_node ending_site,
double  p_capacity,
double  p_speed,
double  p_factor 
)

Definition at line 469 of file vehicle.cpp.

References capacity(), pgrouting::vrp::Tw_node::closes(), ENTERING, evaluate(), EXITING, pgrouting::Identifier::id(), pgrouting::Identifier::idx(), invariant(), pgrouting::Pgr_messages::log, m_path, pgrouting::vrp::PD_problem::msg, pgrouting::vrp::Tw_node::opens(), pgassert, and tau().

476  :
477  Identifier(p_idx, p_id),
478  m_capacity(p_m_capacity),
479  m_factor(p_factor),
480  m_speed(p_speed) {
481  ENTERING();
482  m_path.clear();
483  pgassert(starting_site.opens() <= starting_site.closes());
484  pgassert(ending_site.opens() <= ending_site.closes());
485  pgassert(capacity() > 0);
486  msg.log << "p_idx: " << p_idx << "\t idx(): " << idx() << "\n";
487  msg.log << "p_id: " << p_id << "\tid(): " << id() << "\n";
488 
489  m_path.push_back(starting_site);
490  m_path.push_back(ending_site);
491 
492  evaluate(0);
493  msg.log << tau() << "\n";
494  invariant();
495  EXITING();
496  }
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
int64_t id() const
Definition: identifier.cpp:42
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
double capacity() const
Definition: vehicle.h:271
#define EXITING()
Definition: pgr_messages.h:119
#define ENTERING()
Definition: pgr_messages.h:118
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::string tau() const
Definition: vehicle.cpp:516
static Pgr_messages msg
Definition: pd_problem.h:48
size_t idx() const
Definition: identifier.cpp:37
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Member Function Documentation

double pgrouting::vrp::Vehicle::capacity ( ) const
inline

Definition at line 271 of file vehicle.h.

References deltaTime(), evaluate(), getPosHighLimit(), getPosLowLimit(), insert_less_travel_time(), m_capacity, operator<, operator<<, path(), position_limits(), swap(), and tau().

Referenced by Vehicle().

271 {return m_capacity;}

Here is the call graph for this function:

Here is the caller graph for this function:

Vehicle::Cost pgrouting::vrp::Vehicle::cost ( ) const

Definition at line 166 of file vehicle.cpp.

References cvTot(), duration(), m_path, total_wait_time(), and twvTot().

Referenced by insert(), and is_phony().

166  {
167  return std::make_tuple(
168  twvTot(), cvTot(), m_path.size(),
170 }
int cvTot() const
Definition: vehicle.h:246
double total_wait_time() const
Definition: vehicle.h:231
double duration() const
Definition: vehicle.h:228
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
int twvTot() const
Definition: vehicle.h:243

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::cost_compare ( const Cost lhs,
const Cost rhs 
) const

Definition at line 88 of file vehicle.cpp.

Referenced by insert(), and is_phony().

88  {
89  /*
90  * capacity violations
91  */
92  if (std::get<1>(lhs) < std::get<1>(rhs))
93  return true;
94  if (std::get<1>(lhs) > std::get<1>(rhs))
95  return false;
96 
97  /*
98  * time window violations
99  */
100  if (std::get<0>(lhs) < std::get<0>(rhs))
101  return true;
102  if (std::get<0>(lhs) > std::get<0>(rhs))
103  return false;
104 
105  /*
106  * waiting time
107  */
108  if (std::get<3>(lhs) < std::get<3>(rhs))
109  return true;
110  if (std::get<3>(lhs) > std::get<3>(rhs))
111  return false;
112 
113  /*
114  * duration
115  */
116  if (std::get<4>(lhs) < std::get<4>(rhs))
117  return true;
118  if (std::get<4>(lhs) > std::get<4>(rhs))
119  return false;
120 
121  /*
122  * truck size
123  */
124  if (std::get<2>(lhs) < std::get<2>(rhs))
125  return true;
126  if (std::get<2>(lhs) > std::get<2>(rhs))
127  return false;
128 
129  return false;
130 }

Here is the caller graph for this function:

int pgrouting::vrp::Vehicle::cvTot ( ) const
inline

Definition at line 246 of file vehicle.h.

Referenced by cost(), has_cv(), and tau().

246  {
247  return m_path.back().cvTot();
248  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the caller graph for this function:

double pgrouting::vrp::Vehicle::deltaTime ( const Vehicle_node node,
POS  pos 
) const

Definition at line 188 of file vehicle.cpp.

References pgrouting::vrp::Tw_node::closes(), pgrouting::vrp::Tw_node::is_early_arrival(), m_path, pgrouting::vrp::Tw_node::service_time(), speed(), and pgrouting::vrp::Tw_node::travel_time_to().

Referenced by capacity(), and insert_less_travel_time().

188  {
189  /*
190  * .... POS POS+1 ....
191  * .... POS node POS+1 ....
192  *
193  */
194  auto prev = m_path[pos-1];
195  auto next = m_path[pos];
196  auto original_time = next.travel_time();
197  auto tt_p_n = prev.travel_time_to(node, speed());
198  tt_p_n = node.is_early_arrival(prev.departure_time() + tt_p_n) ?
199  node.closes() - prev.departure_time()
200  : tt_p_n;
201 
202  auto tt_n_x = node.travel_time_to(next, speed());
203  tt_p_n = next.is_early_arrival(
204  prev.departure_time() + tt_p_n + node.service_time() + tt_n_x) ?
205  next.closes() - (prev.departure_time() + tt_p_n + node.service_time())
206  : tt_n_x;
207 
208  return (tt_p_n + tt_n_x) - original_time;
209 }
double speed() const
Definition: vehicle.cpp:536
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

double pgrouting::vrp::Vehicle::duration ( ) const
inline

Definition at line 228 of file vehicle.h.

Referenced by cost(), free_time(), pgrouting::vrp::Vehicle_pickDeliver::get_worse_order(), pgrouting::vrp::Vehicle_pickDeliver::insert(), pgrouting::vrp::Optimize::sort_by_duration(), and tau().

228  {
229  return m_path.back().departure_time();
230  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::empty ( ) const

return true when no nodes are in the truck

True: S E
False: S <nodes> E

Definition at line 354 of file vehicle.cpp.

References invariant(), and m_path.

Referenced by pgrouting::vrp::Vehicle_pickDeliver::get_first_order(), pgrouting::vrp::Vehicle_pickDeliver::get_worse_order(), is_phony(), pgrouting::vrp::Vehicle_pickDeliver::pop_back(), and pgrouting::vrp::Vehicle_pickDeliver::pop_front().

354  {
355  invariant();
356  return m_path.size() <= 2;
357 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

Vehicle_node pgrouting::vrp::Vehicle::end_site ( ) const
inline

Definition at line 265 of file vehicle.h.

References m_speed, and speed().

Referenced by is_ok().

265  {
266  return m_path.back();
267  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::erase ( const Vehicle_node node)

Erase node.id()

Note
start and ending nodes cannot be erased

Numbers are positions before: S .... node.id() .... E after: S .... .... E

Todo:
TODO evaluate with matrix also

Definition at line 238 of file vehicle.cpp.

References evaluate(), pgrouting::Identifier::idx(), invariant(), and m_path.

Referenced by pgrouting::vrp::Vehicle_pickDeliver::erase(), pgrouting::vrp::Vehicle_pickDeliver::insert(), is_phony(), pop_back(), and pop_front().

238  {
239  invariant();
240 
241  POS pos = 0;
242  for ( ; pos < m_path.size() ; ++pos) {
243  if (node.idx() == m_path[pos].idx())
244  break;
245  }
246 
247  erase(pos);
249  evaluate(pos);
250 
251  invariant();
252 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:238
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::erase ( POS  pos)

Erase node at pos from the path.

Note
start and ending nodes cannot be erased

Numbers are positions before: S 1 2 3 4 5 6 pos 8 9 E after: S 1 2 3 4 5 6 8 9 E

Parameters
[in]posto be erased.

Definition at line 314 of file vehicle.cpp.

References evaluate(), invariant(), m_path, and pgassert.

314  {
315  invariant();
316 
317  pgassert(m_path.size() > 2);
318  pgassert(at < m_path.size());
319  pgassert(!m_path[at].is_start());
320  pgassert(!m_path[at].is_end());
321 
322  m_path.erase(m_path.begin() + at);
323  evaluate(at);
324 
325  invariant();
326 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

void pgrouting::vrp::Vehicle::evaluate ( )

@ {

Evaluate: Evaluate the whole path from the start.

Definition at line 345 of file vehicle.cpp.

References invariant().

Referenced by capacity(), erase(), insert(), pgrouting::vrp::Vehicle_pickDeliver::push_back(), pgrouting::vrp::Vehicle_pickDeliver::push_front(), swap(), and Vehicle().

345  {
346  invariant();
347 
348  evaluate(0);
349 
350  invariant();
351 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::evaluate ( POS  from)

Evaluate: Evaluate a path from the given position.

Parameters
[in]fromThe starting position in the path for evaluation to the end of the path.

Definition at line 360 of file vehicle.cpp.

References invariant(), m_capacity, m_path, pgassert, and speed().

360  {
361  invariant();
362  // preconditions
363  pgassert(from < m_path.size());
364 
365 
366  auto node = m_path.begin() + from;
367 
368  while (node != m_path.end()) {
369  if (node == m_path.begin()) {
370  node->evaluate(m_capacity);
371  } else {
372  node->evaluate(*(node - 1), m_capacity, speed());
373  }
374 
375  ++node;
376  }
377  invariant();
378 }
double speed() const
Definition: vehicle.cpp:536
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

double pgrouting::vrp::Vehicle::free_time ( ) const
inline

Definition at line 240 of file vehicle.h.

References duration(), and total_wait_time().

240  {
241  return total_wait_time() + (m_path[0].closes() - duration());
242  }
double total_wait_time() const
Definition: vehicle.h:231
double duration() const
Definition: vehicle.h:228
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

std::vector< General_vehicle_orders_t > pgrouting::vrp::Vehicle::get_postgres_result ( int  vid) const

Definition at line 135 of file vehicle.cpp.

References pgrouting::Identifier::id(), pgrouting::Pgr_messages::log, m_path, pgrouting::vrp::PD_problem::msg, and tau().

136  {
137  std::vector<General_vehicle_orders_t> result;
138  /* postgres numbering starts with 1 */
139  int stop_seq(1);
140  msg.log << "getting solution: " << tau() << "\n";
141  for (const auto p_stop : m_path) {
142  General_vehicle_orders_t data = {
143  vid,
144  id(),
145  stop_seq,
146  /* order_id
147  * The order_id is invalid for stops type 0 and 5
148  */
149  (p_stop.type() == 0 || p_stop.type() == 5)? -1 : p_stop.order(),
150  p_stop.id(),
151  p_stop.type(),
152  p_stop.cargo(),
153  p_stop.travel_time(),
154  p_stop.arrival_time(),
155  p_stop.wait_time(),
156  p_stop.service_time(),
157  p_stop.departure_time()};
158  result.push_back(data);
159  ++stop_seq;
160  }
161  return result;
162 }
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
int64_t id() const
Definition: identifier.cpp:42
std::string tau() const
Definition: vehicle.cpp:516
static Pgr_messages msg
Definition: pd_problem.h:48
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

size_t pgrouting::vrp::Vehicle::getPosHighLimit ( const Vehicle_node node) const
private

Definition at line 442 of file vehicle.cpp.

References invariant(), pgrouting::vrp::Tw_node::is_compatible_IJ(), m_path, and speed().

Referenced by capacity(), and position_limits().

442  {
443  invariant();
444 
445  POS low = 0;
446  POS high = m_path.size();
447  POS high_limit = low;
448 
449  /* I == m_path[high_limit] */
450  while (high_limit < high
451  && nodeJ.is_compatible_IJ(m_path[high_limit], speed())) {
452  ++high_limit;
453  }
454 
455  invariant();
456  return high_limit;
457 }
double speed() const
Definition: vehicle.cpp:536
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

size_t pgrouting::vrp::Vehicle::getPosLowLimit ( const Vehicle_node node) const
private

Definition at line 410 of file vehicle.cpp.

References invariant(), m_path, and speed().

Referenced by capacity(), and position_limits().

410  {
411  invariant();
412 
413  POS low = 0;
414  POS high = m_path.size();
415  POS low_limit = high;
416 
417  /* J == m_path[low_limit - 1] */
418  while (low_limit > low
419  && m_path[low_limit - 1].is_compatible_IJ(nodeI, speed())) {
420  --low_limit;
421  }
422 
423  invariant();
424  return low_limit;
425 }
double speed() const
Definition: vehicle.cpp:536
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::has_cv ( ) const
inline

Definition at line 252 of file vehicle.h.

References cvTot().

Referenced by pgrouting::vrp::Vehicle_pickDeliver::insert(), is_feasable(), pgrouting::vrp::Vehicle_pickDeliver::push_back(), and pgrouting::vrp::Vehicle_pickDeliver::push_front().

252  {
253  return cvTot() != 0;
254  }
int cvTot() const
Definition: vehicle.h:246

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::has_twv ( ) const
inline

Definition at line 249 of file vehicle.h.

References twvTot().

Referenced by is_feasable().

249  {
250  return twvTot() != 0;
251  }
int twvTot() const
Definition: vehicle.h:243

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::insert ( POS  pos,
Vehicle_node  node 
)

@ {

Insert node at pos position.

Parameters
[in]posThe position that the node should be inserted.
[in]nodeThe node to insert.

Definition at line 174 of file vehicle.cpp.

References evaluate(), pgrouting::Identifier::idx(), invariant(), m_path, and pgassert.

Referenced by insert(), pgrouting::vrp::Vehicle_pickDeliver::insert(), insert_less_travel_time(), is_phony(), push_back(), and push_front().

174  {
175  invariant();
176  pgassert(at <= m_path.size());
177 
178  m_path.insert(m_path.begin() + at, node);
179  evaluate(at);
180 
181  pgassert(at < m_path.size());
182  pgassert(m_path[at].idx() == node.idx());
183  invariant();
184 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
size_t idx() const
Definition: identifier.cpp:37
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

size_t pgrouting::vrp::Vehicle::insert ( std::pair< POS, POS position_limits,
const Vehicle_node node 
)

Insert node in best position of the position_limits.

Parameters
[in]position_limits
[in]nodeThe node to insert
Returns
position where it was inserted

Definition at line 54 of file vehicle.cpp.

References cost(), cost_compare(), pgrouting::Identifier::idx(), insert(), invariant(), m_path, pgassert, and swap().

54  {
55  invariant();
56  pgassert(position_limits.first <= m_path.size());
57  pgassert(position_limits.second <= m_path.size());
58 
59  auto low = position_limits.first;
60  auto high = position_limits.second;
61  auto best = low;
62 
63 
64  insert(low, node);
65 
66  Vehicle::Cost best_cost(cost());
67 
68 
69  while (low < high) {
70  swap(low, low + 1);
71  ++low;
72  if (cost_compare(best_cost, cost())) {
73  best_cost = cost();
74  best = low;
75  }
76  }
77  return best;
78 
79  pgassert(best < m_path.size());
80  pgassert(m_path[best].idx() == node.idx());
81  invariant();
82 }
std::pair< POS, POS > position_limits(const Vehicle_node node) const
Definition: vehicle.cpp:388
void swap(POS i, POS j)
Swap two nodes in the path.
Definition: vehicle.cpp:329
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
Cost cost() const
Definition: vehicle.cpp:166
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:174
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool cost_compare(const Cost &, const Cost &) const
Definition: vehicle.cpp:88
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:86
size_t idx() const
Definition: identifier.cpp:37
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

size_t pgrouting::vrp::Vehicle::insert_less_travel_time ( const Vehicle_node node,
POS  after_pos = 0 
)

Definition at line 215 of file vehicle.cpp.

References deltaTime(), insert(), invariant(), and m_path.

Referenced by capacity().

215  {
216  invariant();
217 
218  double min_delta = (std::numeric_limits<double>::max)();
219  POS min_pos = after_pos;
220 
221  for (POS pos = after_pos; pos < m_path.size(); ++pos) {
222  if (!m_path[pos].is_start()) {
223  auto tt = deltaTime(node, pos);
224 
225  if (tt < min_delta) {
226  min_delta = tt;
227  min_pos = pos;
228  }
229  }
230  }
231  insert(min_pos, node);
232 
233  invariant();
234  return min_pos;
235 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:174
double deltaTime(const Vehicle_node &node, POS pos) const
Definition: vehicle.cpp:188
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::is_feasable ( ) const
inline

Definition at line 256 of file vehicle.h.

References has_cv(), has_twv(), and is_ok().

Referenced by pgrouting::vrp::Vehicle_pickDeliver::do_while_feasable(), and pgrouting::vrp::Vehicle_pickDeliver::insert().

256  {
257  return !(has_twv() || has_cv());
258  }
bool has_twv() const
Definition: vehicle.h:249
bool has_cv() const
Definition: vehicle.h:252

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::is_ok ( ) const

Definition at line 460 of file vehicle.cpp.

References pgrouting::vrp::Tw_node::closes(), end_site(), m_capacity, m_path, pgrouting::vrp::Tw_node::opens(), pgassert, and start_site().

Referenced by is_feasable().

460  {
461  pgassert((m_path.front().opens() <= m_path.front().closes())
462  && (m_path.back().opens() <= m_path.back().closes())
463  && (m_capacity > 0));
464  return (start_site().opens() <= start_site().closes())
465  && (end_site().opens() <= end_site().closes())
466  && (m_capacity > 0);
467 }
Vehicle_node start_site() const
Definition: vehicle.h:262
double opens() const
Returns the opening time.
Definition: tw_node.h:76
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
double closes() const
Returns the closing time.
Definition: tw_node.h:79
Vehicle_node end_site() const
Definition: vehicle.h:265
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Vehicle::is_phony ( ) const
inline

Definition at line 101 of file vehicle.h.

References cost(), cost_compare(), empty(), erase(), pgrouting::Identifier::id(), insert(), invariant(), pop_back(), pop_front(), position_limits(), push_back(), push_front(), and speed().

101 {return id() < 0;}
int64_t id() const
Definition: identifier.cpp:42

Here is the call graph for this function:

std::deque< Vehicle_node > pgrouting::vrp::Vehicle::path ( ) const

@ {

Definition at line 381 of file vehicle.cpp.

References invariant(), and m_path.

Referenced by capacity(), and pgrouting::vrp::operator<<().

381  {
382  invariant();
383  return m_path;
384 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::pop_back ( )

Evaluated: pop_back a node to the path.

before: S <nodes> n E
after: S <nodes> E

Definition at line 290 of file vehicle.cpp.

References erase(), invariant(), m_path, and pgassert.

Referenced by is_phony().

290  {
291  invariant();
292  pgassert(m_path.size() > 2);
293 
294  /* erase evaluates */
295  erase(m_path.size() - 2);
296 
297  invariant();
298 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:238
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::pop_front ( )

Evaluated: pop_front a node to the path.

before: S n <nodes> E
after: S <nodes> E

Definition at line 301 of file vehicle.cpp.

References erase(), invariant(), m_path, and pgassert.

Referenced by is_phony().

301  {
302  invariant();
303  pgassert(m_path.size() > 2);
304 
305  /* erase evaluates */
306  erase(1);
307 
308  invariant();
309 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:238
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

std::pair< size_t, size_t > pgrouting::vrp::Vehicle::position_limits ( const Vehicle_node  node) const

Definition at line 388 of file vehicle.cpp.

References getPosHighLimit(), and getPosLowLimit().

Referenced by capacity(), pgrouting::vrp::Vehicle_pickDeliver::insert(), and is_phony().

388  {
389  POS high = getPosHighLimit(node);
390  POS low = getPosLowLimit(node);
391  return std::make_pair(low, high);
392 }
POS getPosLowLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:410
POS getPosHighLimit(const Vehicle_node &node) const
Definition: vehicle.cpp:442

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::push_back ( const Vehicle_node node)

Evaluated: push_back a node to the path.

before: S <nodes> E
after: S <nodes> n E
Parameters
[in]nodeto be push_back.

Definition at line 280 of file vehicle.cpp.

References insert(), invariant(), and m_path.

Referenced by is_phony().

280  {
281  invariant();
282 
283  /* insert evaluates */
284  insert(m_path.size() - 1, node);
285 
286  invariant();
287 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:174
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::push_front ( const Vehicle_node node)

Evaluated: push_back a node to the path.

before: S <nodes> E
after: S n <nodes> E
Parameters
[in]nodeto be push_back.

Definition at line 263 of file vehicle.cpp.

References insert(), and invariant().

Referenced by is_phony().

263  {
264  invariant();
265 
266  /* insert evaluates */
267  insert(1, node);
268 
269  invariant();
270 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:174

Here is the call graph for this function:

Here is the caller graph for this function:

void pgrouting::Identifier::reset_id ( int64_t  _id)
inherited

Definition at line 47 of file identifier.cpp.

References pgrouting::Identifier::m_id.

Referenced by pgrouting::vrp::Tw_node::Tw_node().

47  {
48  m_id = _id;
49 }

Here is the caller graph for this function:

double pgrouting::vrp::Vehicle::speed ( ) const

Definition at line 536 of file vehicle.cpp.

References m_factor, and m_speed.

Referenced by deltaTime(), end_site(), evaluate(), getPosHighLimit(), getPosLowLimit(), is_phony(), pgrouting::vrp::operator<<(), and pgrouting::vrp::Vehicle_pickDeliver::set_compatibles().

536  {
537  return m_speed/m_factor;
538 }

Here is the caller graph for this function:

Vehicle_node pgrouting::vrp::Vehicle::start_site ( ) const
inline

Definition at line 262 of file vehicle.h.

Referenced by is_ok().

262  {
263  return m_path.front();
264  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the caller graph for this function:

void pgrouting::vrp::Vehicle::swap ( POS  i,
POS  j 
)

Swap two nodes in the path.

Before: S <nodesA> I <nodesB> J <nodesC> E
After: S <nodesA> J <nodesB> I <nodesC> E
Parameters
[in]iThe position of the first node to swap.
[in]jThe position of the second node to swap.

Definition at line 329 of file vehicle.cpp.

References evaluate(), invariant(), m_path, and pgassert.

Referenced by capacity(), and insert().

329  {
330  invariant();
331  pgassert(m_path.size() > 3);
332  pgassert(!m_path[i].is_start());
333  pgassert(!m_path[i].is_end());
334  pgassert(!m_path[j].is_start());
335  pgassert(!m_path[j].is_end());
336 
337  std::swap(m_path[i], m_path[j]);
338  i < j ? evaluate(i) : evaluate(j);
339 
340  invariant();
341 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

std::string pgrouting::vrp::Vehicle::tau ( ) const

Definition at line 516 of file vehicle.cpp.

References cvTot(), duration(), pgrouting::Identifier::id(), pgrouting::Identifier::idx(), m_path, pgassert, total_wait_time(), and twvTot().

Referenced by capacity(), get_postgres_result(), pgrouting::vrp::Vehicle_pickDeliver::insert(), pgrouting::vrp::operator<<(), and Vehicle().

516  {
517  pgassert(m_path.size() > 1);
518  std::ostringstream log;
519  log << "Truck " << id() << "(" << idx() << ")"
520  << " (";
521  for (const auto p_stop : m_path) {
522  if (!(p_stop == m_path.front()))
523  log << ", ";
524  log << p_stop.id();
525  }
526  log << ")" << " \t(cv, twv, wait_time, duration) = ("
527  << cvTot() << ", "
528  << twvTot() << ", "
529  << total_wait_time() << ", "
530  << duration() << ")";
531 
532  return log.str();
533 }
int64_t id() const
Definition: identifier.cpp:42
int cvTot() const
Definition: vehicle.h:246
double total_wait_time() const
Definition: vehicle.h:231
double duration() const
Definition: vehicle.h:228
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
size_t idx() const
Definition: identifier.cpp:37
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
int twvTot() const
Definition: vehicle.h:243

Here is the call graph for this function:

Here is the caller graph for this function:

double pgrouting::vrp::Vehicle::total_service_time ( ) const
inline

Definition at line 237 of file vehicle.h.

237  {
238  return m_path.back().total_service_time();
239  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
double pgrouting::vrp::Vehicle::total_travel_time ( ) const
inline

Definition at line 234 of file vehicle.h.

234  {
235  return m_path.back().total_travel_time();
236  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
double pgrouting::vrp::Vehicle::total_wait_time ( ) const
inline

Definition at line 231 of file vehicle.h.

Referenced by cost(), free_time(), pgrouting::vrp::Optimize::sort_for_move(), and tau().

231  {
232  return m_path.back().total_wait_time();
233  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the caller graph for this function:

int pgrouting::vrp::Vehicle::twvTot ( ) const
inline

Definition at line 243 of file vehicle.h.

Referenced by cost(), has_twv(), and tau().

243  {
244  return m_path.back().twvTot();
245  }
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75

Here is the caller graph for this function:

Friends And Related Function Documentation

bool operator< ( const Vehicle lhs,
const Vehicle rhs 
)
friend

Definition at line 561 of file vehicle.cpp.

Referenced by capacity().

561  {
562  lhs.invariant();
563  rhs.invariant();
564 
565  if (lhs.m_path.size() < rhs.m_path.size()) return true;
566 
567  /* here because sizes are equal */
568 
569  if (lhs.m_path.back().total_travel_time()
570  < lhs.m_path.back().total_travel_time()) return true;
571 
572  return false;
573 }
std::ostream& operator<< ( std::ostream &  log,
const Vehicle v 
)
friend

@ {

Definition at line 543 of file vehicle.cpp.

Referenced by capacity().

543  {
544  v.invariant();
545  int i(0);
546  log << "\n\n****************** " << v.idx() << "th VEHICLE*************\n";
547  log << "id = " << v.id()
548  << "\tcapacity = " << v.m_capacity
549  << "\tfactor = " << v.m_factor << "\n"
550  << "\tspeed = " << v.m_speed << "\n"
551  << "\tnew speed = " << v.speed() << "\n";
552 
553  for (const auto &path_stop : v.path()) {
554  log << "Path_stop" << ++i << "\n";
555  log << path_stop << "\n";
556  }
557  return log;
558 }

Member Data Documentation

double pgrouting::vrp::Vehicle::m_capacity
private

Definition at line 78 of file vehicle.h.

Referenced by capacity(), evaluate(), is_ok(), and pgrouting::vrp::operator<<().

double pgrouting::vrp::Vehicle::m_factor
private

Definition at line 79 of file vehicle.h.

Referenced by pgrouting::vrp::operator<<(), and speed().

double pgrouting::vrp::Vehicle::m_speed
private

Definition at line 80 of file vehicle.h.

Referenced by end_site(), pgrouting::vrp::operator<<(), and speed().


The documentation for this class was generated from the following files: