PGROUTING  2.6
pgrouting::vrp::Vehicle_pickDeliver Class Reference

#include "vehicle_pickDeliver.h"

Inheritance diagram for pgrouting::vrp::Vehicle_pickDeliver:
Collaboration diagram for pgrouting::vrp::Vehicle_pickDeliver:

Public Types

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

Public Member Functions

 Vehicle_pickDeliver (size_t id, size_t kind, const Vehicle_node &starting_site, const Vehicle_node &ending_site, double p_capacity, double p_speed, double factor)
 
 Vehicle_pickDeliver (const Vehicle_pickDeliver &)=default
 
double deltaTime (const Vehicle_node &node, POS pos) const
 
void do_while_feasable (int kind, Identifiers< size_t > &unassigned, Identifiers< size_t > &assigned)
 
void erase (const Order &order)
 
Identifiers< size_t > feasable_orders () const
 
Order get_first_order () const
 
std::vector< General_vehicle_orders_tget_postgres_result (int vid) const
 
Order get_worse_order (Identifiers< size_t > of_this_subset) const
 
bool has_order (const Order &order) const
 
int64_t id () const
 
size_t idx () const
 
void insert (const Order &order)
 Inserts an order. More...
 
POS insert_less_travel_time (const Vehicle_node &node, POS after_pos=0)
 
bool is_order_feasable (const Order &order) const
 
bool is_phony () const
 
const PD_Ordersorders () const
 
Identifiers< size_t > orders_in_vehicle () const
 
size_t orders_size () const
 
size_t pop_back ()
 The order that is picked last is removed. More...
 
size_t pop_front ()
 
std::pair< POS, POSposition_limits (const Vehicle_node node) const
 
void push_back (const Order &order)
 puts an order at the end of the truck More...
 
void push_front (const Order &order)
 Puts an order at the end front of the truck. More...
 
void reset_id (int64_t)
 
void set_compatibles (const PD_Orders &orders)
 
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 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...
 
operators
std::string tau () const
 

Static Public Attributes

static Pgr_messages msg
 

Protected Types

typedef size_t POS
 

Protected Attributes

double cost
 
Identifiers< size_t > m_feasable_orders
 orders that fit in the truck More...
 
PD_Orders m_orders
 
Identifiers< size_t > m_orders_in_vehicle
 orders inserted in this vehicle More...
 
std::deque< Vehicle_nodem_path
 

Static Protected Attributes

static Pgr_pickDeliverproblem
 

Friends

class Initial_solution
 
class Optimize
 

Detailed Description

Definition at line 46 of file vehicle_pickDeliver.h.

Member Typedef Documentation

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

Definition at line 86 of file vehicle.h.

typedef size_t pgrouting::vrp::Vehicle::POS
protectedinherited

Definition at line 74 of file vehicle.h.

Constructor & Destructor Documentation

pgrouting::vrp::Vehicle_pickDeliver::Vehicle_pickDeliver ( size_t  id,
size_t  kind,
const Vehicle_node starting_site,
const Vehicle_node ending_site,
double  p_capacity,
double  p_speed,
double  factor 
)

Definition at line 80 of file vehicle_pickDeliver.cpp.

References Identifiers< T >::clear(), ENTERING, EXITING, pgrouting::vrp::Vehicle::invariant(), and m_orders_in_vehicle.

87  :
88  Vehicle(id, kind, starting_site, ending_site, p_capacity, p_speed, factor),
89  cost((std::numeric_limits<double>::max)()) {
90  ENTERING();
92  invariant();
93  EXITING();
94  }
Vehicle(const Vehicle &)
Definition: vehicle.cpp:498
void clear()
Definition: identifiers.hpp:83
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
Cost cost() const
Definition: vehicle.cpp:166
#define EXITING()
Definition: pgr_messages.h:119
#define ENTERING()
Definition: pgr_messages.h:118
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

Here is the call graph for this function:

pgrouting::vrp::Vehicle_pickDeliver::Vehicle_pickDeliver ( const Vehicle_pickDeliver )
default

Member Function Documentation

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

Definition at line 166 of file vehicle.cpp.

References pgrouting::vrp::Vehicle::cvTot(), pgrouting::vrp::Vehicle::duration(), pgrouting::vrp::Vehicle::m_path, pgrouting::vrp::Vehicle::total_wait_time(), and pgrouting::vrp::Vehicle::twvTot().

Referenced by pgrouting::vrp::Vehicle::insert(), and pgrouting::vrp::Vehicle::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
inherited

Definition at line 88 of file vehicle.cpp.

Referenced by pgrouting::vrp::Vehicle::insert(), and pgrouting::vrp::Vehicle::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
inlineinherited

Definition at line 246 of file vehicle.h.

Referenced by pgrouting::vrp::Vehicle::cost(), pgrouting::vrp::Vehicle::has_cv(), and pgrouting::vrp::Vehicle::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
inherited

Definition at line 188 of file vehicle.cpp.

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

Referenced by pgrouting::vrp::Vehicle::capacity(), and pgrouting::vrp::Vehicle::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:

void pgrouting::vrp::Vehicle_pickDeliver::do_while_feasable ( int  kind,
Identifiers< size_t > &  unassigned,
Identifiers< size_t > &  assigned 
)

Definition at line 257 of file vehicle_pickDeliver.cpp.

References erase(), pgrouting::vrp::PD_Orders::find_best_I(), pgrouting::vrp::PD_Orders::find_best_J(), insert(), pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::is_feasable(), pgrouting::Pgr_messages::log, m_feasable_orders, m_orders, pgrouting::vrp::PD_problem::msg, orders_size(), pgassert, push_back(), and push_front().

Referenced by orders_in_vehicle().

260  {
262 #if 0
263  msg.log << "unasigned" << unassigned << "\n";
264  msg.log << "m_feasable_orders" << m_feasable_orders << "\n";
265 #endif
266  auto current_feasable = m_feasable_orders * unassigned;
267 
268  while (!current_feasable.empty()) {
269 #if 0
270  msg.log << "current_feasable" << current_feasable << "\n";
271 #endif
272  auto order = m_orders[current_feasable.front()];
273 
274  switch (kind) {
275  case 1:
276  push_back(order);
278  assigned += order.idx();
279  unassigned -= order.idx();
280  invariant();
281  return;
282  break;
283  case 2:
284  push_back(order);
285  break;
286  case 3:
287  push_front(order);
288  break;
289  case 4:
290  insert(order);
291  break;
292  case 5:
293  order = m_orders[m_orders.find_best_J(current_feasable)];
294  insert(order);
295  break;
296  case 6:
297  order = m_orders[m_orders.find_best_I(current_feasable)];
298  insert(order);
299  break;
300  default: pgassert(false);
301  }
302  if (orders_size() == 1 && !is_feasable()) {
303  pgassert(false);
304  }
305 
306  if (!is_feasable()) {
307  erase(order);
308  } else {
309  assigned += order.idx();
310  unassigned -= order.idx();
311  if (kind == 5) {
312  current_feasable = m_orders[order.idx()].subsetJ(
313  current_feasable);
314  }
315  if (kind == 6) {
316  current_feasable = m_orders[order.idx()].subsetI(
317  current_feasable);
318  }
319  }
320 
321  current_feasable -= order.idx();
322  invariant();
323  }
324 
326  invariant();
327 }
void push_back(const Order &order)
puts an order at the end of the truck
void push_front(const Order &order)
Puts an order at the end front of the truck.
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
Identifiers< size_t > m_feasable_orders
orders that fit in the truck
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
size_t find_best_J(Identifiers< size_t > &within_this_set) const
Definition: pd_orders.cpp:165
size_t find_best_I(Identifiers< size_t > &within_this_set) const
Definition: pd_orders.cpp:184
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
void insert(const Order &order)
Inserts an order.
static Pgr_messages msg
Definition: pd_problem.h:48
bool is_feasable() const
Definition: vehicle.h:256

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 228 of file vehicle.h.

Referenced by pgrouting::vrp::Vehicle::cost(), pgrouting::vrp::Vehicle::free_time(), get_worse_order(), insert(), pgrouting::vrp::Optimize::sort_by_duration(), and pgrouting::vrp::Vehicle::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
inherited

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 pgrouting::vrp::Vehicle::invariant(), and pgrouting::vrp::Vehicle::m_path.

Referenced by get_first_order(), get_worse_order(), pgrouting::vrp::Vehicle::is_phony(), pop_back(), and 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
inlineinherited

Definition at line 265 of file vehicle.h.

References pgrouting::vrp::Vehicle::m_speed, and pgrouting::vrp::Vehicle::speed().

Referenced by pgrouting::vrp::Vehicle::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_pickDeliver::erase ( const Order order)

Definition at line 331 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Order::delivery(), pgrouting::vrp::Vehicle::erase(), has_order(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::invariant(), m_orders_in_vehicle, pgassert, and pgrouting::vrp::Order::pickup().

Referenced by do_while_feasable(), pgrouting::vrp::Optimize::move_order(), orders_in_vehicle(), pop_back(), pop_front(), and pgrouting::vrp::Optimize::swap_order().

331  {
332  invariant();
333  pgassert(has_order(order));
334 
335 
336  Vehicle::erase(order.pickup());
337  Vehicle::erase(order.delivery());
338  m_orders_in_vehicle -= order.idx();
339 
340  invariant();
341  pgassert(!has_order(order));
342 }
bool has_order(const Order &order) const
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
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

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)
inherited

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 pgrouting::vrp::Vehicle::evaluate(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::invariant(), and pgrouting::vrp::Vehicle::m_path.

Referenced by erase(), insert(), pgrouting::vrp::Vehicle::is_phony(), pgrouting::vrp::Vehicle::pop_back(), and pgrouting::vrp::Vehicle::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)
inherited

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 pgrouting::vrp::Vehicle::evaluate(), pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::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 ( )
inherited

@ {

Evaluate: Evaluate the whole path from the start.

Definition at line 345 of file vehicle.cpp.

References pgrouting::vrp::Vehicle::invariant().

Referenced by pgrouting::vrp::Vehicle::capacity(), pgrouting::vrp::Vehicle::erase(), pgrouting::vrp::Vehicle::insert(), push_back(), push_front(), pgrouting::vrp::Vehicle::swap(), and pgrouting::vrp::Vehicle::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)
inherited

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 pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::m_capacity, pgrouting::vrp::Vehicle::m_path, pgassert, and pgrouting::vrp::Vehicle::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:

Identifiers<size_t> pgrouting::vrp::Vehicle_pickDeliver::feasable_orders ( ) const
inline

Definition at line 74 of file vehicle_pickDeliver.h.

References m_feasable_orders.

74 {return m_feasable_orders;}
Identifiers< size_t > m_feasable_orders
orders that fit in the truck
double pgrouting::vrp::Vehicle::free_time ( ) const
inlineinherited

Definition at line 240 of file vehicle.h.

References pgrouting::vrp::Vehicle::duration(), and pgrouting::vrp::Vehicle::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:

Order pgrouting::vrp::Vehicle_pickDeliver::get_first_order ( ) const

Definition at line 73 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Vehicle::empty(), pgrouting::vrp::Vehicle::invariant(), m_orders, pgrouting::vrp::Vehicle::m_path, and pgassert.

Referenced by orders_in_vehicle().

73  {
74  invariant();
75  pgassert(!empty());
76  return m_orders[m_path[1].idx()];
77 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:354
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::vector< General_vehicle_orders_t > pgrouting::vrp::Vehicle::get_postgres_result ( int  vid) const
inherited

Definition at line 135 of file vehicle.cpp.

References pgrouting::Identifier::id(), pgrouting::Pgr_messages::log, pgrouting::vrp::Vehicle::m_path, pgrouting::vrp::PD_problem::msg, and pgrouting::vrp::Vehicle::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:

Order pgrouting::vrp::Vehicle_pickDeliver::get_worse_order ( Identifiers< size_t >  of_this_subset) const

Definition at line 47 of file vehicle_pickDeliver.cpp.

References Identifiers< T >::begin(), pgrouting::vrp::Vehicle::duration(), Identifiers< T >::empty(), pgrouting::vrp::Vehicle::empty(), pgrouting::vrp::Vehicle::invariant(), m_orders, and pgassert.

Referenced by orders_in_vehicle().

48  {
49  invariant();
50  pgassert(!empty());
51 
52  // auto orders(of_this_subset);
53  auto worse_order(m_orders[*orders.begin()]);
54  auto delta_duration((std::numeric_limits<double>::max)());
55  auto curr_duration(duration());
56  while (!orders.empty()) {
57  auto truck(*this);
58  auto order = m_orders[*orders.begin()];
59  pgassert(truck.has_order(order));
60  orders -= order.idx();
61  truck.erase(order);
62  auto delta = truck.duration() - curr_duration;
63  if (delta < delta_duration) {
64  worse_order = order;
65  delta_duration = delta;
66  }
67  }
68  return worse_order;
69 }
const PD_Orders & orders() const
double duration() const
Definition: vehicle.h:228
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:354

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 252 of file vehicle.h.

References pgrouting::vrp::Vehicle::cvTot().

Referenced by insert(), pgrouting::vrp::Vehicle::is_feasable(), push_back(), and 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_pickDeliver::has_order ( const Order order) const

Definition at line 99 of file vehicle_pickDeliver.cpp.

References Identifiers< T >::has(), pgrouting::Identifier::idx(), and m_orders_in_vehicle.

Referenced by erase(), insert(), pgrouting::vrp::Optimize::move_order(), orders_in_vehicle(), push_back(), push_front(), and pgrouting::vrp::Optimize::swap_order().

99  {
100  return m_orders_in_vehicle.has(order.idx());
101 }
bool has(const T other) const
true ids() has element
Definition: identifiers.hpp:97
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 249 of file vehicle.h.

References pgrouting::vrp::Vehicle::twvTot().

Referenced by pgrouting::vrp::Vehicle::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 
)
inherited

@ {

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 pgrouting::vrp::Vehicle::evaluate(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::m_path, and pgassert.

Referenced by pgrouting::vrp::Vehicle::insert(), insert(), pgrouting::vrp::Vehicle::insert_less_travel_time(), pgrouting::vrp::Vehicle::is_phony(), pgrouting::vrp::Vehicle::push_back(), and pgrouting::vrp::Vehicle::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:

void pgrouting::vrp::Vehicle_pickDeliver::insert ( const Order order)

Inserts an order.

Precondition: !has_order(order)

Postcondition: has_order(order) !has_cv();

Before: S <nodes> E
After: S ....P .... D .... E

push_back is performed when

  • pickup

Can generate time window violation No capacity violation

Definition at line 105 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Order::delivery(), pgrouting::vrp::Vehicle::duration(), pgrouting::vrp::Vehicle::erase(), pgrouting::vrp::Vehicle::has_cv(), has_order(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::insert(), pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::is_feasable(), m_orders_in_vehicle, pgrouting::vrp::Vehicle::m_path, pgassert, pgassertwm, pgrouting::vrp::Order::pickup(), pgrouting::vrp::Vehicle::position_limits(), push_back(), and pgrouting::vrp::Vehicle::tau().

Referenced by do_while_feasable(), pgrouting::vrp::Optimize::move_order(), pgrouting::vrp::Initial_solution::one_truck_all_orders(), orders_in_vehicle(), and pgrouting::vrp::Optimize::swap_order().

105  {
106  invariant();
107  pgassert(!has_order(order));
108 
109  auto pick_pos(position_limits(order.pickup()));
110  auto deliver_pos(position_limits(order.delivery()));
111 #ifndef NDEBUG
112  std::ostringstream err_log;
113  err_log << "\n\tpickup limits (low, high) = ("
114  << pick_pos.first << ", "
115  << pick_pos.second << ") "
116  << "\n\tdeliver limits (low, high) = ("
117  << deliver_pos.first << ", "
118  << deliver_pos.second << ") "
119  << "\noriginal" << tau();
120 #endif
121 
122  if (pick_pos.second < pick_pos.first) {
123  /* pickup generates twv evrywhere,
124  * so put the order as last */
125  push_back(order);
126  return;
127  }
128 
129  if (deliver_pos.second < deliver_pos.first) {
130  /* delivery generates twv evrywhere,
131  * so put the order as last */
132  push_back(order);
133  return;
134  }
135  /*
136  * Because delivery positions were estimated without
137  * the pickup:
138  * - increase the upper limit position estimation
139  */
140  ++deliver_pos.second;
141 
142 
143  auto d_pos_backup(deliver_pos);
144  auto best_pick_pos = m_path.size();
145  auto best_deliver_pos = m_path.size() + 1;
146  auto current_duration(duration());
147  auto min_delta_duration = (std::numeric_limits<double>::max)();
148  auto found(false);
149  pgassertwm(!has_order(order), err_log.str());
150  while (pick_pos.first <= pick_pos.second) {
151 #ifndef NDEBUG
152  err_log << "\n\tpickup cycle limits (low, high) = ("
153  << pick_pos.first << ", "
154  << pick_pos.second << ") ";
155 #endif
156  Vehicle::insert(pick_pos.first, order.pickup());
157 #ifndef NDEBUG
158  err_log << "\npickup inserted: " << tau();
159 #endif
160 
161  while (deliver_pos.first <= deliver_pos.second) {
162  Vehicle::insert(deliver_pos.first, order.delivery());
163  m_orders_in_vehicle += order.idx();
164  pgassertwm(has_order(order), err_log.str());
165 #ifndef NDEBUG
166  err_log << "\ndelivery inserted: " << tau();
167 #endif
168  if (is_feasable()) {
170  auto delta_duration = duration()-current_duration;
171  if (delta_duration < min_delta_duration) {
172 #ifndef NDEBUG
173  err_log << "\nsuccess" << tau();
174 #endif
175  min_delta_duration = delta_duration;
176  best_pick_pos = pick_pos.first;
177  best_deliver_pos = deliver_pos.first;
178  found = true;
179  }
180  }
181  Vehicle::erase(deliver_pos.first);
182 #ifndef NDEBUG
183  err_log << "\ndelivery erased: " << tau();
184 #endif
185  ++deliver_pos.first;
186  }
187  Vehicle::erase(pick_pos.first);
188 #ifndef NDEBUG
189  err_log << "\npickup erased: " << tau();
190 #endif
191  m_orders_in_vehicle -= order.idx();
192  pgassertwm(!has_order(order), err_log.str());
193 
194  deliver_pos = d_pos_backup;
195 #ifndef NDEBUG
196  err_log << "\n\trestoring deliver limits (low, high) = ("
197  << deliver_pos.first << ", "
198  << deliver_pos.second << ") ";
199 #endif
200  ++pick_pos.first;
201  }
202  pgassertwm(!has_order(order), err_log.str());
203  if (!found) {
204  /* order causes twv
205  * so put the order as last */
206  push_back(order);
207  return;
208  }
209  Vehicle::insert(best_pick_pos, order.pickup());
210  Vehicle::insert(best_deliver_pos, order.delivery());
211 
212  m_orders_in_vehicle += order.idx();
213  pgassertwm(is_feasable(), err_log.str());
214  pgassertwm(has_order(order), err_log.str());
215  pgassertwm(!has_cv(), err_log.str());
216  invariant();
217 }
std::pair< POS, POS > position_limits(const Vehicle_node node) const
Definition: vehicle.cpp:388
bool has_order(const Order &order) const
void push_back(const Order &order)
puts an order at the end of the truck
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:104
double duration() const
Definition: vehicle.h:228
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
void insert(POS pos, Vehicle_node node)
@ {
Definition: vehicle.cpp:174
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::string tau() const
Definition: vehicle.cpp:516
bool has_cv() const
Definition: vehicle.h:252
void erase(const Vehicle_node &node)
Erase node.id()
Definition: vehicle.cpp:238
bool is_feasable() const
Definition: vehicle.h:256
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

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 
)
inherited

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 pgrouting::vrp::Vehicle::cost(), pgrouting::vrp::Vehicle::cost_compare(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::insert(), pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::m_path, pgassert, and pgrouting::vrp::Vehicle::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 
)
inherited

Definition at line 215 of file vehicle.cpp.

References pgrouting::vrp::Vehicle::deltaTime(), pgrouting::vrp::Vehicle::insert(), pgrouting::vrp::Vehicle::invariant(), and pgrouting::vrp::Vehicle::m_path.

Referenced by pgrouting::vrp::Vehicle::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
inlineinherited

Definition at line 256 of file vehicle.h.

References pgrouting::vrp::Vehicle::has_cv(), pgrouting::vrp::Vehicle::has_twv(), and pgrouting::vrp::Vehicle::is_ok().

Referenced by do_while_feasable(), and 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
inherited

Definition at line 460 of file vehicle.cpp.

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

Referenced by pgrouting::vrp::Vehicle::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_pickDeliver::is_order_feasable ( const Order order) const

Definition at line 409 of file vehicle_pickDeliver.cpp.

Referenced by set_compatibles().

409  {
410  auto test_truck = *this;
411  test_truck.push_back(order);
412  return test_truck.is_feasable();
413 }

Here is the caller graph for this function:

const PD_Orders& pgrouting::vrp::Vehicle_pickDeliver::orders ( ) const
inline

Definition at line 76 of file vehicle_pickDeliver.h.

References m_orders.

Referenced by pgrouting::vrp::operator<<(), set_compatibles(), and pgrouting::vrp::Optimize::swap_worse().

Here is the caller graph for this function:

Identifiers<size_t> pgrouting::vrp::Vehicle_pickDeliver::orders_in_vehicle ( ) const
inline

Definition at line 78 of file vehicle_pickDeliver.h.

References do_while_feasable(), erase(), get_first_order(), get_worse_order(), has_order(), insert(), m_orders_in_vehicle, pop_back(), pop_front(), push_back(), and push_front().

Referenced by pgrouting::vrp::Optimize::sort_by_id(), pgrouting::vrp::Optimize::sort_by_size(), and pgrouting::vrp::Optimize::swap_worse().

78 {return m_orders_in_vehicle;}
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

Here is the call graph for this function:

Here is the caller graph for this function:

size_t pgrouting::vrp::Vehicle_pickDeliver::orders_size ( ) const
inline

Definition at line 77 of file vehicle_pickDeliver.h.

References Identifiers< T >::size().

Referenced by do_while_feasable(), and pgrouting::vrp::Optimize::sort_for_move().

77 {return m_orders_in_vehicle.size();}
size_t size() const
Definition: identifiers.hpp:77
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

Here is the call graph for this function:

Here is the caller graph for this function:

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

@ {

Definition at line 381 of file vehicle.cpp.

References pgrouting::vrp::Vehicle::invariant(), and pgrouting::vrp::Vehicle::m_path.

Referenced by pgrouting::vrp::Vehicle::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:

size_t pgrouting::vrp::Vehicle_pickDeliver::pop_back ( )

The order that is picked last is removed.

Returns
id of the removed order

Definition at line 347 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Vehicle::empty(), erase(), pgrouting::vrp::Vehicle::invariant(), m_orders, pgrouting::vrp::Vehicle::m_path, and pgassert.

Referenced by orders_in_vehicle().

347  {
348  invariant();
349  pgassert(!empty());
350 
351  auto pick_itr = m_path.rbegin();
352  while (pick_itr != m_path.rend() && !pick_itr->is_pickup()) {
353  ++pick_itr;
354  }
355 
356  pgassert(pick_itr->is_pickup());
357 
358  auto deleted_pick_idx = pick_itr->idx();
359 
360  for (const auto o : m_orders) {
361  if (o.pickup().idx() == deleted_pick_idx) {
362  erase(o);
363  invariant();
364  return o.idx();
365  }
366  }
367  pgassert(false);
368  return 0;
369 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:354
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_pickDeliver::pop_front ( )

Definition at line 374 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Vehicle::empty(), erase(), pgrouting::vrp::Vehicle::invariant(), m_orders, pgrouting::vrp::Vehicle::m_path, and pgassert.

Referenced by orders_in_vehicle().

374  {
375  invariant();
376  pgassert(!empty());
377 
378  auto pick_itr = m_path.begin();
379  while (pick_itr != m_path.end() && !pick_itr->is_pickup()) {
380  ++pick_itr;
381  }
382 
383  pgassert(pick_itr->is_pickup());
384 
385  auto deleted_pick_idx = pick_itr->idx();
386 
387  for (const auto o : m_orders) {
388  if (o.pickup().idx() == deleted_pick_idx) {
389  erase(o);
390  invariant();
391  return o.idx();
392  }
393  }
394 
395  pgassert(false);
396  return 0;
397 }
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool empty() const
return true when no nodes are in the truck
Definition: vehicle.cpp:354
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
inherited

Definition at line 388 of file vehicle.cpp.

References pgrouting::vrp::Vehicle::getPosHighLimit(), and pgrouting::vrp::Vehicle::getPosLowLimit().

Referenced by pgrouting::vrp::Vehicle::capacity(), insert(), and pgrouting::vrp::Vehicle::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_pickDeliver::push_back ( const Order order)

puts an order at the end of the truck

Precondition: !has_order(order)

Postcondition: has_order(order) !has_cv();

Before: S <nodes> E
After: S <nodes> P D E

Can generate time window violation No capacity violation

Definition at line 221 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Order::delivery(), pgrouting::vrp::Vehicle::evaluate(), pgrouting::vrp::Vehicle::has_cv(), has_order(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::invariant(), m_orders_in_vehicle, pgrouting::vrp::Vehicle::m_path, pgassert, and pgrouting::vrp::Order::pickup().

Referenced by do_while_feasable(), insert(), and orders_in_vehicle().

221  {
222  invariant();
223  pgassert(!has_order(order));
224 
225  m_orders_in_vehicle += order.idx();
226  m_path.insert(m_path.end() - 1, order.pickup());
227  m_path.insert(m_path.end() - 1, order.delivery());
228  evaluate(m_path.size() - 3);
229 
230  pgassert(has_order(order));
231 #if 0
232  pgassert(!has_cv());
233 #endif
234  invariant();
235 }
bool has_order(const Order &order) const
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool has_cv() const
Definition: vehicle.h:252
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

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)
inherited

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 pgrouting::vrp::Vehicle::insert(), pgrouting::vrp::Vehicle::invariant(), and pgrouting::vrp::Vehicle::m_path.

Referenced by pgrouting::vrp::Vehicle::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_pickDeliver::push_front ( const Order order)

Puts an order at the end front of the truck.

Precondition: !has_order(order)

Postcondition: has_order(order) !has_cv();

Before: S <nodes> E
After: S P D <nodes> E

Can generate time window violation No capacity violation

Definition at line 239 of file vehicle_pickDeliver.cpp.

References pgrouting::vrp::Order::delivery(), pgrouting::vrp::Vehicle::evaluate(), pgrouting::vrp::Vehicle::has_cv(), has_order(), pgrouting::Identifier::idx(), pgrouting::vrp::Vehicle::invariant(), m_orders_in_vehicle, pgrouting::vrp::Vehicle::m_path, pgassert, and pgrouting::vrp::Order::pickup().

Referenced by do_while_feasable(), and orders_in_vehicle().

239  {
240  invariant();
241  pgassert(!has_order(order));
242 
243  m_orders_in_vehicle += order.idx();
244  m_path.insert(m_path.begin() + 1, order.delivery());
245  m_path.insert(m_path.begin() + 1, order.pickup());
246  evaluate(1);
247 
248  pgassert(has_order(order));
249 #if 0
250  pgassert(!has_cv());
251 #endif
252  invariant();
253 }
bool has_order(const Order &order) const
void invariant() const
Invariant The path must:
Definition: vehicle.cpp:47
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool has_cv() const
Definition: vehicle.h:252
std::deque< Vehicle_node > m_path
Definition: vehicle.h:75
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle

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)
inherited

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 pgrouting::vrp::Vehicle::insert(), and pgrouting::vrp::Vehicle::invariant().

Referenced by pgrouting::vrp::Vehicle::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:

void pgrouting::vrp::Vehicle_pickDeliver::set_compatibles ( const PD_Orders orders)

Definition at line 400 of file vehicle_pickDeliver.cpp.

References is_order_feasable(), m_feasable_orders, m_orders, orders(), pgrouting::vrp::PD_Orders::set_compatibles(), and pgrouting::vrp::Vehicle::speed().

400  {
401  m_orders = orders;
402  for (const auto o : orders) {
403  if (is_order_feasable(o)) m_feasable_orders += o.idx();
404  }
406 }
const PD_Orders & orders() const
Identifiers< size_t > m_feasable_orders
orders that fit in the truck
double speed() const
Definition: vehicle.cpp:536
void set_compatibles(double speed)
Definition: pd_orders.cpp:156
bool is_order_feasable(const Order &order) const

Here is the call graph for this function:

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

Definition at line 262 of file vehicle.h.

Referenced by pgrouting::vrp::Vehicle::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 
)
inherited

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 pgrouting::vrp::Vehicle::evaluate(), pgrouting::vrp::Vehicle::invariant(), pgrouting::vrp::Vehicle::m_path, and pgassert.

Referenced by pgrouting::vrp::Vehicle::capacity(), and pgrouting::vrp::Vehicle::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
inherited

Definition at line 516 of file vehicle.cpp.

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

Referenced by pgrouting::vrp::Vehicle::capacity(), pgrouting::vrp::Vehicle::get_postgres_result(), insert(), pgrouting::vrp::operator<<(), and pgrouting::vrp::Vehicle::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
inlineinherited

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
inlineinherited

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
inlineinherited

Definition at line 231 of file vehicle.h.

Referenced by pgrouting::vrp::Vehicle::cost(), pgrouting::vrp::Vehicle::free_time(), pgrouting::vrp::Optimize::sort_for_move(), and pgrouting::vrp::Vehicle::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
inlineinherited

Definition at line 243 of file vehicle.h.

Referenced by pgrouting::vrp::Vehicle::cost(), pgrouting::vrp::Vehicle::has_twv(), and pgrouting::vrp::Vehicle::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

friend class Initial_solution
friend

Definition at line 57 of file vehicle_pickDeliver.h.

friend class Optimize
friend

Definition at line 58 of file vehicle_pickDeliver.h.

Member Data Documentation

double pgrouting::vrp::Vehicle_pickDeliver::cost
protected

Definition at line 48 of file vehicle_pickDeliver.h.

Identifiers<size_t> pgrouting::vrp::Vehicle_pickDeliver::m_feasable_orders
protected

orders that fit in the truck

Definition at line 53 of file vehicle_pickDeliver.h.

Referenced by do_while_feasable(), feasable_orders(), and set_compatibles().

PD_Orders pgrouting::vrp::Vehicle_pickDeliver::m_orders
protected
Identifiers<size_t> pgrouting::vrp::Vehicle_pickDeliver::m_orders_in_vehicle
protected

orders inserted in this vehicle

Definition at line 50 of file vehicle_pickDeliver.h.

Referenced by erase(), has_order(), insert(), orders_in_vehicle(), push_back(), push_front(), and Vehicle_pickDeliver().


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