PGROUTING  3.2
pgrouting::vrp::Optimize Class Reference

#include "optimize.h"

Inheritance diagram for pgrouting::vrp::Optimize:
Collaboration diagram for pgrouting::vrp::Optimize:

Public Member Functions

 Optimize (const Solution &solution)
 
 Optimize (const Solution &solution, size_t times)
 
Vehicle::Cost cost () const
 
std::string cost_str () const
 
int cvTot () const
 
void decrease_truck ()
 
double duration () const
 
Initials_code get_kind () const
 
std::vector< General_vehicle_orders_tget_postgres_result () const
 
void inter_swap (size_t times)
 
bool is_feasable () const
 
bool operator< (const Solution &s_rhs) const
 
std::string tau (const std::string &title="Tau") const
 
double total_service_time () const
 
double total_travel_time () const
 
int twvTot () const
 
double wait_time () const
 

Static Public Member Functions

static Pgr_messagesmsg ()
 The problem's message. More...
 

Public Attributes

Solution best_solution
 

Protected Attributes

double EPSILON
 
std::deque< Vehicle_pickDeliverfleet
 
Fleet trucks
 

Private Member Functions

bool decrease_truck (size_t)
 
void delete_empty_truck ()
 
bool inter_swap ()
 
bool move_order (Order order, Vehicle_pickDeliver &from_truck, Vehicle_pickDeliver &to_truck)
 moves an order to an non empty vehicle More...
 
bool move_reduce_cost (Vehicle_pickDeliver &from, Vehicle_pickDeliver &to)
 
void save_if_best ()
 
void sort_by_duration ()
 
void sort_by_size ()
 
bool swap_worse (Vehicle_pickDeliver &from, Vehicle_pickDeliver &to)
 

Static Private Attributes

static Pgr_pickDeliverproblem
 this solution belongs to this problem More...
 

Detailed Description

Definition at line 41 of file optimize.h.

Constructor & Destructor Documentation

◆ Optimize() [1/2]

pgrouting::vrp::Optimize::Optimize ( const Solution solution)
explicit

Definition at line 41 of file optimize.cpp.

42  :
43  Solution(old_solution),
44  best_solution(old_solution) {
45  pgassert(false);
47  inter_swap(fleet.size());
48  }

References decrease_truck(), pgrouting::vrp::Solution::fleet, inter_swap(), and pgassert.

◆ Optimize() [2/2]

pgrouting::vrp::Optimize::Optimize ( const Solution solution,
size_t  times 
)

Definition at line 50 of file optimize.cpp.

52  :
53  Solution(old_solution),
54  best_solution(old_solution) {
55  inter_swap(times);
56 
57  this->fleet = best_solution.fleet;
58  msg().log << tau("bestSol before sort by size");
59  sort_by_size();
60  msg().log << tau("bestSol after sort by size");
61  msg().log << tau();
62  }

References best_solution, pgrouting::vrp::Solution::fleet, inter_swap(), pgrouting::Pgr_messages::log, pgrouting::vrp::Solution::msg(), sort_by_size(), and pgrouting::vrp::Solution::tau().

Member Function Documentation

◆ cost()

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

Definition at line 130 of file solution.cpp.

130  {
131  double total_duration(0);
132  double total_wait_time(0);
133  int total_twv(0);
134  int total_cv(0);
135  for (const auto &v : fleet) {
136  total_duration += v.duration();
137  total_wait_time += v.total_wait_time();
138  total_twv += v.twvTot();
139  total_cv += v.cvTot();
140  }
141  return std::make_tuple(
142  total_twv, total_cv, fleet.size(),
143  total_wait_time, total_duration);
144 }

References pgrouting::vrp::Solution::fleet.

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

◆ cost_str()

std::string pgrouting::vrp::Solution::cost_str ( ) const
inherited

Definition at line 149 of file solution.cpp.

149  {
150  Vehicle::Cost s_cost(cost());
151  std::ostringstream log;
152 
153  log << "(twv, cv, fleet, wait, duration) = ("
154  << std::get<0>(s_cost) << ", "
155  << std::get<1>(s_cost) << ", "
156  << std::get<2>(s_cost) << ", "
157  << std::get<3>(s_cost) << ", "
158  << std::get<4>(s_cost) << ")";
159 
160  return log.str();
161 }

References pgrouting::vrp::Solution::cost().

Referenced by save_if_best(), and pgrouting::vrp::Solution::tau().

◆ cvTot()

int pgrouting::vrp::Solution::cvTot ( ) const
inherited

Definition at line 121 of file solution.cpp.

121  {
122  int total(0);
123  for (const auto &v : fleet) {
124  total += v.cvTot();
125  }
126  return total;
127 }

References pgrouting::vrp::Solution::fleet.

◆ decrease_truck() [1/2]

void pgrouting::vrp::Optimize::decrease_truck ( )

Definition at line 446 of file optimize.cpp.

446  {
447  bool decreased(false);
448  for (size_t i = 1; i < fleet.size(); ++i) {
449  decreased = decrease_truck(i) || decreased;
450  }
451  if (decreased) {
453  save_if_best();
454  decrease_truck();
455  }
456  save_if_best();
457 }

References delete_empty_truck(), pgrouting::vrp::Solution::fleet, and save_if_best().

Referenced by inter_swap(), and Optimize().

◆ decrease_truck() [2/2]

bool pgrouting::vrp::Optimize::decrease_truck ( size_t  cycle)
private

Definition at line 460 of file optimize.cpp.

460  {
461  auto position = cycle;
462  for (auto orders = fleet[position].orders_in_vehicle();
463  !orders.empty();
464  orders.pop_front()) {
465  /* Step 2: grab an order */
466  auto order = fleet[position].orders()[orders.front()];
467  pgassert(order.idx() == orders.front());
468 
469 
470  /* Step 3:
471  * cycle the fleet
472  * insert in first truck possible
473  */
474 
475  for (size_t i = 0; i < position; ++i) {
476  fleet[i].insert(order);
477  pgassert((fleet[i].has_order(order) && fleet[i].is_feasable()) || !fleet[i].has_order(order));
478  if (fleet[i].has_order(order)) {
479  /*
480  * delete the order from the current truck
481  */
482  fleet[position].erase(order);
483  break;
484  }
485  }
486  }
487  return fleet[position].orders_in_vehicle().empty();
488 }

References pgrouting::vrp::Solution::fleet, pgrouting::vrp::Solution::is_feasable(), and pgassert.

◆ delete_empty_truck()

void pgrouting::vrp::Optimize::delete_empty_truck ( )
private

Definition at line 288 of file optimize.cpp.

288  {
289  fleet.erase(std::remove_if(
290  fleet.begin(),
291  fleet.end(),
292  [](const Vehicle_pickDeliver &v){
293  return v.orders_in_vehicle().empty();}),
294  fleet.end());
295  save_if_best();
296 }

References pgrouting::vrp::Solution::fleet, and save_if_best().

Referenced by decrease_truck(), and inter_swap().

◆ duration()

double pgrouting::vrp::Solution::duration ( ) const
inherited

Definition at line 76 of file solution.cpp.

76  {
77  double total(0);
78  for (const auto &v : fleet) {
79  total += v.duration();
80  }
81  return total;
82 }

References pgrouting::vrp::Solution::fleet.

Referenced by move_reduce_cost(), save_if_best(), and swap_worse().

◆ get_kind()

Initials_code pgrouting::vrp::Solution::get_kind ( ) const
inherited

Definition at line 237 of file solution.cpp.

237  {
238  return problem->get_kind();
239 }

References pgrouting::vrp::Pgr_pickDeliver::get_kind(), and pgrouting::vrp::Solution::problem.

Referenced by move_order(), move_reduce_cost(), and swap_worse().

◆ get_postgres_result()

std::vector< General_vehicle_orders_t > pgrouting::vrp::Solution::get_postgres_result ( ) const
inherited

Definition at line 42 of file solution.cpp.

42  {
43  std::vector<General_vehicle_orders_t> result;
44  /* postgres numbering starts with 1 */
45  int i(1);
46  for (const auto& truck : fleet) {
47  std::vector<General_vehicle_orders_t> data =
48  truck.get_postgres_result(i);
49  result.insert(result.end(), data.begin(), data.end());
50 
51  ++i;
52  }
53  return result;
54 }

References pgrouting::vrp::Solution::fleet.

◆ inter_swap() [1/2]

bool pgrouting::vrp::Optimize::inter_swap ( )
private

Definition at line 94 of file optimize.cpp.

94  {
95  msg().log
96  << "\n" <<tau("before inter swap");
98  auto swapped_f = false;
99  /*
100  * .. to ... from ....
101  */
102  for (auto &from : fleet) {
103  for (auto &to : fleet) {
104  if (&from == &to) break;
105 
106 #if 0
107  msg().log
108  << "\n to " << to.id()
109  << "from " << from.id();
110  auto swapped = false;
111 #endif
112  swap_worse(to, from);
113  move_reduce_cost(from, to);
114 #if 0
115  msg().log << "++++++++" << p_swaps;
116 #endif
117  }
118  }
119 
120  msg().log
121  << "\n" <<tau("after");
123 
124  return swapped_f;
125 }

References delete_empty_truck(), pgrouting::vrp::Solution::fleet, pgrouting::Pgr_messages::log, move_reduce_cost(), pgrouting::vrp::Solution::msg(), swap_worse(), and pgrouting::vrp::Solution::tau().

Referenced by inter_swap(), and Optimize().

◆ inter_swap() [2/2]

void pgrouting::vrp::Optimize::inter_swap ( size_t  times)

Definition at line 66 of file optimize.cpp.

66  {
67  msg().log << tau("before sort by size");
68  sort_by_size();
69  msg().log << tau("before decrease");
71  msg().log << tau("after decrease");
72  sort_by_size();
73  msg().log << tau("after sort by size");
74 
75  size_t i = 0;
76  while (i++ < times) {
77  msg().log << "\n*************************** CYCLE" << i;
78  inter_swap();
79  msg().log << tau("after inter swap");
80  std::rotate(fleet.begin(), fleet.begin() + 1, fleet.end());
81  msg().log << tau("before next cycle");
82  }
83 }

References decrease_truck(), pgrouting::vrp::Solution::fleet, inter_swap(), pgrouting::Pgr_messages::log, pgrouting::vrp::Solution::msg(), sort_by_size(), and pgrouting::vrp::Solution::tau().

◆ is_feasable()

bool pgrouting::vrp::Solution::is_feasable ( ) const
inherited

Definition at line 67 of file solution.cpp.

67  {
68  for (const auto& v : fleet) {
69  if (v.is_feasable()) continue;
70  return false;
71  }
72  return true;
73 }

References pgrouting::vrp::Solution::fleet.

Referenced by decrease_truck(), and pgrouting::vrp::Initial_solution::do_while_foo().

◆ move_order()

bool pgrouting::vrp::Optimize::move_order ( Order  order,
Vehicle_pickDeliver from_truck,
Vehicle_pickDeliver to_truck 
)
private

moves an order to an non empty vehicle

order: order to be moved from_truck: here is the order to truck: truck to put the order

to check if the order was inserted: to_truck.has_order(order)

Returns
bool: when move was done

Definition at line 393 of file optimize.cpp.

396  {
397  pgassert(from_truck.has_order(order));
398  pgassert(!to_truck.has_order(order));
399  /*
400  * don't move to empty truck
401  */
402  if (to_truck.empty()) return false;
403 
404  /*
405  * don't move from a real truck to a phoney truck
406  */
407  if (!from_truck.is_phony() && to_truck.is_phony()) return false;
408 
409  /*
410  * Don't move from a vehicle with more orders
411  */
412  if (from_truck.size() > to_truck.size()) return false;
413 
414  /*
415  * insert the order
416  */
417  this->get_kind() == OneDepot?
418  to_truck.semiLIFO(order) :
419  to_truck.insert(order);
420 
421  if (to_truck.has_order(order)) {
422  from_truck.erase(order);
423 
424  pgassert(!(from_truck.has_order(order) && to_truck.has_order(order)));
425  pgassert(!from_truck.has_order(order));
426  pgassert(to_truck.has_order(order));
427  return true;
428  }
429 
430  pgassert(!(from_truck.has_order(order) && to_truck.has_order(order)));
431  pgassert(from_truck.has_order(order));
432  pgassert(!to_truck.has_order(order));
433  return false;
434 }

References pgrouting::vrp::Vehicle::empty(), pgrouting::vrp::Vehicle_pickDeliver::erase(), pgrouting::vrp::Solution::get_kind(), pgrouting::vrp::Vehicle_pickDeliver::has_order(), pgrouting::vrp::Vehicle_pickDeliver::insert(), pgrouting::vrp::Vehicle::is_phony(), pgrouting::vrp::OneDepot, pgassert, pgrouting::vrp::Vehicle_pickDeliver::semiLIFO(), and pgrouting::vrp::Vehicle::size().

Referenced by swap_worse().

◆ move_reduce_cost()

bool pgrouting::vrp::Optimize::move_reduce_cost ( Vehicle_pickDeliver from,
Vehicle_pickDeliver to 
)
private

Definition at line 311 of file optimize.cpp.

313  {
314  pgassert(&from != &to);
315 
316  auto from_truck = from;
317  auto to_truck = to;
318  /*
319  * don't move to empty truck
320  */
321  if (to_truck.empty()) return false;
322 
323  /*
324  * don't move from a real truck to a phoney truck
325  */
326  if (!from_truck.is_phony() && to_truck.is_phony()) {
327  return false;
328  }
329 
330  auto moved = false;
331 
332  auto from_orders = from_truck.orders_in_vehicle();
333  for (const auto o_id : from_orders) {
334  /*
335  * removing an order decreases the duration
336  */
337  auto order = from_truck.orders()[o_id];
338 
339  auto curr_duration = from_truck.duration() + to_truck.duration();
340  /*
341  * insert it in the "to" truck
342  */
343  pgassert(!to_truck.has_order(order));
344  this->get_kind() == OneDepot?
345  to_truck.semiLIFO(order) :
346  to_truck.insert(order);
347  pgassert((to_truck.has_order(order) && to_truck.is_feasable()) || !to_truck.has_order(order));
348 
349  if (to_truck.has_order(order)) {
350  from_truck.erase(order);
351 
352  auto new_duration = from_truck.duration() + to_truck.duration();
353 
354  /*
355  * cost is reduced
356  */
357  if (new_duration < curr_duration
358  || from_truck.empty()
359  || new_duration < best_solution.duration()) {
360  moved = true;
361  save_if_best();
362  continue;
363  }
364 
365  /*
366  * cost is not reduced
367  * revert changes
368  */
369  to_truck.erase(order);
370  this->get_kind() == OneDepot?
371  from_truck.semiLIFO(order) :
372  from_truck.insert(order);
373  }
374  }
375  return moved;
376 }

References best_solution, pgrouting::vrp::Solution::duration(), pgrouting::vrp::Solution::get_kind(), pgrouting::vrp::OneDepot, pgrouting::vrp::Vehicle_pickDeliver::orders_in_vehicle(), pgassert, and save_if_best().

Referenced by inter_swap().

◆ msg()

Pgr_messages & pgrouting::vrp::Solution::msg ( )
staticinherited

◆ operator<()

bool pgrouting::vrp::Solution::operator< ( const Solution s_rhs) const
inherited

Definition at line 189 of file solution.cpp.

189  {
190  Vehicle::Cost lhs(cost());
191  Vehicle::Cost rhs(s_rhs.cost());
192 
193  /*
194  * capacity violations
195  */
196  if (std::get<0>(lhs) < std::get<0>(rhs))
197  return true;
198  if (std::get<0>(lhs) > std::get<0>(rhs))
199  return false;
200 
201  /*
202  * time window violations
203  */
204  if (std::get<1>(lhs) < std::get<1>(rhs))
205  return true;
206  if (std::get<1>(lhs) > std::get<1>(rhs))
207  return false;
208 
209  /*
210  * fleet size
211  */
212  if (std::get<2>(lhs) < std::get<2>(rhs))
213  return true;
214  if (std::get<2>(lhs) > std::get<2>(rhs))
215  return false;
216 
217  /*
218  * waiting time
219  */
220  if (std::get<3>(lhs) < std::get<3>(rhs))
221  return true;
222  if (std::get<3>(lhs) > std::get<3>(rhs))
223  return false;
224 
225  /*
226  * duration
227  */
228  if (std::get<4>(lhs) < std::get<4>(rhs))
229  return true;
230  if (std::get<4>(lhs) > std::get<4>(rhs))
231  return false;
232 
233  return false;
234 }

References pgrouting::vrp::Solution::cost().

◆ save_if_best()

void pgrouting::vrp::Optimize::save_if_best ( )
private

Definition at line 491 of file optimize.cpp.

491  {
492  if (duration() < best_solution.duration()) {
493  best_solution = (*this);
494  msg().log << "\n*********** best by duration"
495  << best_solution.cost_str();
496 #if 0
497  msg().dbg_log << best_solution.tau("best by duration");
498 #endif
499  }
500  if (fleet.size() < best_solution.fleet.size()) {
501  best_solution = (*this);
502  msg().log << "\n*********** best by fleet size"
503  << best_solution.cost_str();
504 #if 0
505  msg().dbg_log << best_solution.tau("best by fleet size");
506 #endif
507  }
508 }

References best_solution, pgrouting::vrp::Solution::cost_str(), pgrouting::vrp::Solution::duration(), pgrouting::vrp::Solution::fleet, pgrouting::Pgr_messages::log, pgrouting::vrp::Solution::msg(), and pgrouting::vrp::Solution::tau().

Referenced by decrease_truck(), delete_empty_truck(), and move_reduce_cost().

◆ sort_by_duration()

void pgrouting::vrp::Optimize::sort_by_duration ( )
private

Definition at line 279 of file optimize.cpp.

279  {
280  std::sort(fleet.begin(), fleet.end(), []
281  (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs)
282  -> bool {
283  return lhs.duration() > rhs.duration();
284  });
285 }

References pgrouting::vrp::Solution::fleet.

Referenced by sort_by_size().

◆ sort_by_size()

void pgrouting::vrp::Optimize::sort_by_size ( )
private

Definition at line 268 of file optimize.cpp.

268  {
270  std::stable_sort(fleet.begin(), fleet.end(), []
271  (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs)
272  -> bool {
273  return lhs.orders_in_vehicle().size()
274  > rhs.orders_in_vehicle().size();
275  });
276 }

References pgrouting::vrp::Solution::fleet, and sort_by_duration().

Referenced by inter_swap(), and Optimize().

◆ swap_worse()

bool pgrouting::vrp::Optimize::swap_worse ( Vehicle_pickDeliver from,
Vehicle_pickDeliver to 
)
private

Definition at line 133 of file optimize.cpp.

133  {
134  /*
135  * working on a copy of the vehicles
136  */
137  auto from_truck = from;
138  auto to_truck = to;
139 
140  auto swapped = false;
141 
142  /*
143  * To avoid invalidation of cycles
144  */
145  auto o_from_orders = from_truck.orders_in_vehicle();
146  auto o_to_orders = to_truck.orders_in_vehicle();
147 
148  pgassert((o_from_orders * o_to_orders).empty());
149 
150  for (auto from_orders = from_truck.orders_in_vehicle();
151  !from_orders.empty();
152  from_orders.pop_front()) {
153  auto from_order = from_truck.orders()[from_orders.front()];
154 
155  pgassert(from_truck.has_order(from_order));
156 
157  if (move_order(from_order, from_truck, to_truck)) {
158  pgassert(!from_truck.has_order(from_order));
159  pgassert(to_truck.has_order(from_order));
160  /*
161  * The order could be moved to "to" truck
162  */
163  to = to_truck;
164  from = from_truck;
165  /*
166  * go to next order
167  */
168  pgassert(!from.has_order(from_order));
169  pgassert(to.has_order(from_order));
170  pgassert(!from_truck.has_order(from_order));
171  pgassert(to_truck.has_order(from_order));
172  pgassert(!(from.has_order(from_order) && to.has_order(from_order)));
173  pgassert(from.has_order(from_order) || to.has_order(from_order));
174  continue;
175  }
176 
177  pgassert(from_truck.has_order(from_order));
178  auto curr_from_duration = from_truck.duration();
179 
180  for (auto to_order_id : o_to_orders) {
181  auto to_order = to.orders()[to_order_id];
182  /*
183  * The orders might have being swapped before
184  */
185  if (!to_truck.has_order(to_order)) continue;
186  // if (!from_truck.has_order(from_order)) break; // TODO delete line
187 
188  pgassert(from_truck.has_order(from_order));
189  pgassert(to_truck.has_order(to_order));
190 
191  auto curr_to_duration = to_truck.duration();
192 
193  /*
194  * delete from_order, and to order from their trucks
195  */
196  pgassert(from_truck.has_order(from_order));
197  from_truck.erase(from_order);
198  pgassert(to_truck.has_order(to_order));
199  to_truck.erase(to_order);
200 
201  /*
202  * insert them in the other truck
203  */
204  if (this->get_kind() == OneDepot) {
205  from_truck.semiLIFO(to_order);
206  to_truck.semiLIFO(from_order);
207  } else {
208  from_truck.insert(to_order);
209  to_truck.insert(from_order);
210  }
211 
212  pgassert((from_truck.has_order(to_order) && from_truck.is_feasable()) || !from_truck.has_order(to_order));
213  pgassert((to_truck.has_order(from_order) && to_truck.is_feasable()) || !to_truck.has_order(from_order));
214 
215  if (from_truck.has_order(to_order) && to_truck.has_order(from_order)) {
216  auto new_from_duration = from_truck.duration();
217  auto new_to_duration = to_truck.duration();
218 
219  auto estimated_delta =
220  - (curr_from_duration + curr_to_duration)
221  + (new_to_duration + new_from_duration);
222 
223  auto estimated_duration = duration() + estimated_delta;
224 
225  /*
226  * Can swap when:
227  * - or from_truck duration is reduced
228  * - the total fleet duration is reduced
229  * - or the new fleet duration is better than best_solution duration
230  */
231  if (new_from_duration < curr_from_duration ||
232  estimated_delta < 0 ||
233  estimated_duration < best_solution.duration()) {
234  /*
235  * this acctually makes the swapping
236  */
237  to = to_truck;
238  from = from_truck;
239 
240  pgassert(!(from.has_order(from_order) && to.has_order(from_order)));
241  pgassert(from.has_order(from_order) || to.has_order(from_order));
242  pgassert(!(from.has_order(to_order) && to.has_order(to_order)));
243  pgassert(from.has_order(to_order) || to.has_order(to_order));
244 
245  swapped = true;
246  break;
247  }
248  }
249  /*
250  * Can't swap, restore vehicles
251  */
252  to_truck = to;
253  from_truck = from;
254 
255  pgassert(!(from.has_order(from_order) && to.has_order(from_order)));
256  pgassert(from.has_order(from_order) || to.has_order(from_order));
257  pgassert(!(from.has_order(to_order) && to.has_order(to_order)));
258  pgassert(from.has_order(to_order) || to.has_order(to_order));
259  }
260  }
261 
262  return false && swapped;
263 }

References best_solution, pgrouting::vrp::Solution::duration(), pgrouting::vrp::Solution::get_kind(), pgrouting::vrp::Vehicle_pickDeliver::has_order(), move_order(), pgrouting::vrp::OneDepot, pgrouting::vrp::Vehicle_pickDeliver::orders(), pgrouting::vrp::Vehicle_pickDeliver::orders_in_vehicle(), and pgassert.

Referenced by inter_swap().

◆ tau()

std::string pgrouting::vrp::Solution::tau ( const std::string &  title = "Tau") const
inherited

Definition at line 164 of file solution.cpp.

164  {
165  std::ostringstream log;
166 
167  log << "\n" << title << ": " << std::endl;
168  for (const auto &v : fleet) {
169  log << "\n" << v.tau();
170  }
171  log << "\n" << cost_str() << "\n";
172  return log.str();
173 }

References pgrouting::vrp::Solution::cost_str(), and pgrouting::vrp::Solution::fleet.

Referenced by inter_swap(), pgrouting::vrp::operator<<(), Optimize(), and save_if_best().

◆ total_service_time()

double pgrouting::vrp::Solution::total_service_time ( ) const
inherited

Definition at line 112 of file solution.cpp.

112  {
113  double total(0);
114  for (const auto &v : fleet) {
115  total += v.total_service_time();
116  }
117  return total;
118 }

References pgrouting::vrp::Solution::fleet.

◆ total_travel_time()

double pgrouting::vrp::Solution::total_travel_time ( ) const
inherited

Definition at line 103 of file solution.cpp.

103  {
104  double total(0);
105  for (const auto &v : fleet) {
106  total += v.total_travel_time();
107  }
108  return total;
109 }

References pgrouting::vrp::Solution::fleet.

◆ twvTot()

int pgrouting::vrp::Solution::twvTot ( ) const
inherited

Definition at line 85 of file solution.cpp.

85  {
86  int total(0);
87  for (const auto &v : fleet) {
88  total += v.twvTot();
89  }
90  return total;
91 }

References pgrouting::vrp::Solution::fleet.

◆ wait_time()

double pgrouting::vrp::Solution::wait_time ( ) const
inherited

Definition at line 94 of file solution.cpp.

94  {
95  double total(0);
96  for (const auto &v : fleet) {
97  total += v.total_wait_time();
98  }
99  return total;
100 }

References pgrouting::vrp::Solution::fleet.

Member Data Documentation

◆ best_solution

Solution pgrouting::vrp::Optimize::best_solution

Definition at line 52 of file optimize.h.

Referenced by move_reduce_cost(), Optimize(), save_if_best(), and swap_worse().

◆ EPSILON

double pgrouting::vrp::Solution::EPSILON
protectedinherited

Definition at line 48 of file solution.h.

Referenced by pgrouting::vrp::Solution::operator=().

◆ fleet

◆ problem

Pgr_pickDeliver * pgrouting::vrp::Solution::problem
staticprivateinherited

this solution belongs to this problem

Definition at line 114 of file solution.h.

Referenced by pgrouting::vrp::Solution::get_kind(), pgrouting::vrp::Solution::msg(), and pgrouting::vrp::PD_problem::PD_problem().

◆ trucks


The documentation for this class was generated from the following files:
pgrouting::vrp::Solution::tau
std::string tau(const std::string &title="Tau") const
Definition: solution.cpp:164
pgrouting::vrp::Optimize::delete_empty_truck
void delete_empty_truck()
Definition: optimize.cpp:288
pgrouting::vrp::Optimize::swap_worse
bool swap_worse(Vehicle_pickDeliver &from, Vehicle_pickDeliver &to)
Definition: optimize.cpp:133
pgrouting::vrp::Solution::is_feasable
bool is_feasable() const
Definition: solution.cpp:67
pgrouting::vrp::Solution::problem
static Pgr_pickDeliver * problem
this solution belongs to this problem
Definition: solution.h:114
pgrouting::vrp::Optimize::decrease_truck
void decrease_truck()
Definition: optimize.cpp:446
pgrouting::vrp::Solution::fleet
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
pgrouting::vrp::Optimize::sort_by_duration
void sort_by_duration()
Definition: optimize.cpp:279
pgrouting::Pgr_messages::log
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:81
pgrouting::vrp::Pgr_pickDeliver::msg
Pgr_messages msg
message controller for all classes
Definition: pgr_pickDeliver.h:99
pgrouting::vrp::Optimize::move_order
bool move_order(Order order, Vehicle_pickDeliver &from_truck, Vehicle_pickDeliver &to_truck)
moves an order to an non empty vehicle
Definition: optimize.cpp:393
pgrouting::vrp::Optimize::move_reduce_cost
bool move_reduce_cost(Vehicle_pickDeliver &from, Vehicle_pickDeliver &to)
Definition: optimize.cpp:311
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::vrp::Optimize::best_solution
Solution best_solution
Definition: optimize.h:52
pgrouting::vrp::OneDepot
@ OneDepot
Push front order that allows more orders to be inserted at the front.
Definition: initials_code.h:44
pgrouting::vrp::Solution::cost
Vehicle::Cost cost() const
Definition: solution.cpp:130
pgrouting::vrp::Solution::cost_str
std::string cost_str() const
Definition: solution.cpp:149
pgrouting::vrp::Optimize::sort_by_size
void sort_by_size()
Definition: optimize.cpp:268
pgrouting::vrp::Solution::Solution
Solution()
Definition: solution.cpp:241
pgrouting::vrp::Pgr_pickDeliver::get_kind
Initials_code get_kind() const
Definition: pgr_pickDeliver.h:84
pgrouting::vrp::Solution::get_kind
Initials_code get_kind() const
Definition: solution.cpp:237
pgrouting::vrp::Solution::duration
double duration() const
Definition: solution.cpp:76
pgrouting::vrp::Optimize::save_if_best
void save_if_best()
Definition: optimize.cpp:491
pgrouting::vrp::Vehicle::Cost
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:90
pgrouting::vrp::Optimize::inter_swap
bool inter_swap()
Definition: optimize.cpp:94
pgrouting::vrp::Solution::msg
static Pgr_messages & msg()
The problem's message.
Definition: solution.cpp:60