vrpRouting  0.3
vrprouting::optimizers::tabu::Optimize Class Reference

Class that optimizes a solution. More...

#include "tabu.h"

Inheritance diagram for vrprouting::optimizers::tabu::Optimize:
Collaboration diagram for vrprouting::optimizers::tabu::Optimize:

Public Member Functions

 Optimize (const problem::Solution &solution, size_t times, bool stop_on_all_served, bool)
 Optimization operation. More...
 
std::tuple< int, int, size_t, TInterval, TInterval, TIntervalcost () const
 Get all statistics in one cycle. More...
 
std::string cost_str () const
 
int cvTot () const
 Total number of capacity constraint violations of the solution. More...
 
TInterval duration () const
 Total duration of the solution. More...
 
const std::deque< Vehicle_pickDeliver > & fleet () const
 Get the current fleet solution. More...
 
std::vector< Solution_rtget_postgres_result () const
 get solution like postgres needs it More...
 
std::vector< Short_vehicleget_stops () const
 get solution like postgres needs it More...
 
bool is_feasible () const
 is the solution feasible? More...
 
Pgr_messagesmsg ()
 
double objective () const
 Get the value of the objective function. More...
 
bool operator< (const Solution &) const
 
const Orders & orders () const
 
std::string tau (const std::string &title="Tau") const
 writing the solution in compact form into a string More...
 
TInterval total_service_time () const
 Total service time of the solution. More...
 
TInterval total_travel_time () const
 Total travel time of the solution. More...
 
int twvTot () const
 Total number of time windows constraint violations of the solution. More...
 
Fleet & vehicles ()
 
TInterval wait_time () const
 Total waiting time of the solution. More...
 

Public Attributes

problem::Solution best_solution
 The best solution so far. More...
 

Protected Attributes

std::deque< Vehicle_pickDeliver > m_fleet
 The current solution. More...
 
Pgr_messages m_msg
 
Orders m_orders
 the problem info More...
 
Fleet m_trucks
 

Private Member Functions

void delete_empty_truck ()
 deletes phony vehicles that are empty More...
 
bool diversify ()
 Diversify the search. More...
 
void intensify ()
 Intensify the search. More...
 
bool move_2_real ()
 moves orders from phony vehicles to a real vehicle More...
 
void save_if_best ()
 save a new found solution only if it is best More...
 
void set_tabu_list_length ()
 set tabu length More...
 
bool single_pair_insertion (bool intensify, bool diversify)
 Single Pair Insertion: move order from one vehicle to another that reduces objective value. More...
 
void sort_by_size (bool asc)
 
bool swap_between_routes (bool intensify, bool diversify)
 Swapping pairs Between Routes: initiate directed or undirected swaps of orders between vehicles. More...
 
void tabu_search ()
 Main optimization controller. More...
 

Private Attributes

size_t m_max_cycles
 Maximum number of cycles on the optimization process. More...
 
bool m_optimize
 Flag to just build a solution and not optimize it. More...
 
size_t m_standard_limit = 30
 Limit for a cycle. More...
 
bool m_stop_on_all_served
 Flag to stop when all orders are in real vehicles. More...
 
Identifiers< size_t > m_unassignedOrders
 Set of unassigned orders. More...
 
TabuList tabu_list
 Tabu lists of the problem. More...
 

Detailed Description

Class that optimizes a solution.

How to use:

// Given a solution in solution_to_optimize
// in this example it is one cycle and to stop when all orders are served
Solution optimized_solution = Optimize(solution_to_optimize, 1, true);

Definition at line 51 of file optimizers/tabu.h.

Constructor & Destructor Documentation

◆ Optimize()

vrprouting::optimizers::tabu::Optimize::Optimize ( const problem::Solution old_solution,
size_t  max_cycles,
bool  stop_on_all_served,
bool  optimize 
)

Optimization operation.

dot_inline_dotgraph_14.png
Parameters
[in]old_solution- solution to be optimized
[in]max_cycles- number of times to perform a single tabu search (optimization) cycle
[in]stop_on_all_served- a stopping condition: stop when all orders are served
[in]optimize- a stopping condition when false: only add orders; do not optimize
Postcondition
this solution's fleet has the best solution found

Definition at line 95 of file optimizers/tabu.cpp.

99  :
100  problem::Solution(old_solution),
101  best_solution(old_solution),
102  m_max_cycles(max_cycles),
103  m_stop_on_all_served(stop_on_all_served),
104  m_optimize(optimize) {
105  ENTERING(msg());
106 
107  /*
108  * this function does the actual work
109  */
110  tabu_search();
111 
112  /*
113  * delete empty phony trucks
114  */
116 
117  /*
118  * Save best fleet/order structure found
119  */
120  this->m_fleet = best_solution.fleet();
121 
122  msg().log << tau("Best solution found");
123  EXITING(msg());
124 }

References best_solution, delete_empty_truck(), ENTERING, EXITING, vrprouting::problem::Solution::fleet(), vrprouting::Pgr_messages::log, vrprouting::problem::Solution::m_fleet, vrprouting::problem::Solution::msg(), tabu_search(), and vrprouting::problem::Solution::tau().

Member Function Documentation

◆ cost()

std::tuple< int, int, size_t, TInterval, TInterval, TInterval > Solution::cost ( ) const
inherited

Get all statistics in one cycle.

Returns
totals of
idx variable
0 twv
1 cv
2 fleet size
3 waiting time
4 duration
5 travel time
std::get<idx>

Definition at line 218 of file solution.cpp.

218  {
219  TInterval total_duration(0);
220  TInterval total_wait_time(0);
221  TInterval total_tt(0);
222  int total_twv(0);
223  int total_cv(0);
224  /*
225  * Cycle the fleet
226  */
227  for (const auto& v : m_fleet) {
228  total_duration += v.duration();
229  total_wait_time += v.total_wait_time();
230  total_twv += v.twvTot();
231  total_cv += v.cvTot();
232  total_tt += v.total_travel_time();
233  }
234  /*
235  * build the tuple
236  */
237  return std::make_tuple(
238  total_twv, total_cv, m_fleet.size(),
239  total_wait_time, total_duration,
240  total_tt);
241 }

References vrprouting::problem::Solution::m_fleet.

Referenced by vrprouting::problem::Solution::cost_str(), and vrprouting::problem::Solution::operator<().

◆ cost_str()

std::string Solution::cost_str ( ) const
inherited
Returns
The costs in one string

Definition at line 246 of file solution.cpp.

246  {
247  /*
248  * get the cost
249  */
250  auto s_cost(cost());
251  std::ostringstream log;
252 
253  /*
254  * Build the string
255  */
256  log << std::fixed << std::setprecision(4)
257  << "twv=" << std::get<0>(s_cost)
258  << " cv=" << std::get<1>(s_cost)
259  << " wait=" << std::get<3>(s_cost)
260  << " duration=" << std::get<4>(s_cost)
261  << " tt=" << std::get<5>(s_cost);
262 
263  return log.str();
264 }

References vrprouting::problem::Solution::cost().

Referenced by vrprouting::problem::Solution::tau().

◆ cvTot()

int Solution::cvTot ( ) const
inherited

Total number of capacity constraint violations of the solution.

Returns
Total number of capacity violations The total capacity violations of the solution is the sum of the capacity violations of all vehicles

Definition at line 196 of file solution.cpp.

196  {
197  return std::accumulate(begin(m_fleet), end(m_fleet), 0,
198  [](int i, const Vehicle_pickDeliver& v) {return v.cvTot() + i;});
199 }

References vrprouting::problem::Vehicle::cvTot(), and vrprouting::problem::Solution::m_fleet.

Referenced by vrprouting::problem::Solution::get_postgres_result().

◆ delete_empty_truck()

void vrprouting::optimizers::tabu::Optimize::delete_empty_truck ( )
private

deletes phony vehicles that are empty

Postcondition
the fleet does not have phony empty vehicles
does not remove real vehicles
the fleet size is reduced

Definition at line 788 of file optimizers/tabu.cpp.

788  {
789  /*
790  * remove from the fleet vehicles that are phony and empty
791  */
792  m_fleet.erase(std::remove_if(
793  m_fleet.begin(),
794  m_fleet.end(),
795  [](const problem::Vehicle_pickDeliver &v){
796  return v.orders_in_vehicle().empty() && v.is_phony();}),
797  m_fleet.end());
798 }

Referenced by Optimize(), and tabu_search().

◆ diversify()

bool vrprouting::optimizers::tabu::Optimize::diversify ( )
private

Diversify the search.

diversify

  • diversifies the search by moving into a solution space that has never been visited before
  • returns true if diversification was successful.

Definition at line 437 of file optimizers/tabu.cpp.

437  {
438  /*
439  * set the number of maximum swaps between routes for diversification
440  */
441  size_t max_swaps = std::min(m_fleet.size(), orders().size() / 10);
442  size_t s = 0;
443  bool swaps_were_done = true;
444  while (swaps_were_done && s < max_swaps) {
445  swaps_were_done = single_pair_insertion(false, true);
446  if (!swaps_were_done) {
447  swaps_were_done = swap_between_routes(false, true);
448  }
449  if (!swaps_were_done) {
450  swaps_were_done = swap_between_routes(false, false);
451  }
452  if (swaps_were_done) if (!are_all_served(m_unassignedOrders)) move_2_real();
453  s++;
454  }
455  return swaps_were_done;
456 }

References anonymous_namespace{tabu.cpp}::are_all_served(), vrprouting::problem::Solution::m_fleet, m_unassignedOrders, move_2_real(), vrprouting::problem::Solution::orders(), single_pair_insertion(), and swap_between_routes().

Referenced by single_pair_insertion(), swap_between_routes(), and tabu_search().

◆ duration()

TInterval Solution::duration ( ) const
inherited

Total duration of the solution.

Returns
the solution's duration

The solution duration is the sum of the durations of all vehicles

Definition at line 140 of file solution.cpp.

140  {
141  return std::accumulate(begin(m_fleet), end(m_fleet), static_cast<TInterval>(0),
142  [](TInterval i, const Vehicle_pickDeliver& v) {return v.duration() + i;});
143 }

References vrprouting::problem::Vehicle::duration(), and vrprouting::problem::Solution::m_fleet.

Referenced by vrprouting::problem::Solution::get_postgres_result(), vrprouting::optimizers::simple::Optimize::save_if_best(), and vrprouting::optimizers::simple::Optimize::swap_worse().

◆ fleet()

const std::deque<Vehicle_pickDeliver>& vrprouting::problem::Solution::fleet ( ) const
inlineinherited

Get the current fleet solution.

Definition at line 107 of file solution.h.

107 {return m_fleet;}

References vrprouting::problem::Solution::m_fleet.

Referenced by intensify(), and Optimize().

◆ get_postgres_result()

std::vector< Solution_rt > Solution::get_postgres_result ( ) const
inherited

get solution like postgres needs it

Returns
container for postgres

Definition at line 61 of file solution.cpp.

61  {
62  std::vector<Solution_rt> result;
63 
64  /* postgres numbering starts with 1 */
65  int i(1);
66 
67  for (auto v : m_fleet) {
68  v.evaluate(0);
69  auto data = v.get_postgres_result(i);
70  /*
71  * Results adjusted for the depot and the first stop
72  * So the vehicle waits on the depot not on the first stop
73  */
74  data[1].arrivalTime = data[1].operationTime;
75  data[0].waitDuration = data[1].waitDuration;
76  data[1].waitDuration = 0;
77  data[0].departureTime = data[0].arrivalTime + data[0].waitDuration;
78 
79 
80  result.insert(result.end(), data.begin(), data.end());
81  ++i;
82  }
83 
84  Solution_rt aggregates = {
85  /*
86  * Vehicle id = -2 indicates its an aggregate row
87  *
88  * (twv, cv, fleet, wait, duration)
89  */
90  -2, // summary row on vehicle_number
91  twvTot(), // on vehicle_id
92  cvTot(), // on vehicle_seq
93  -1, // on order_id
94  -1, // on stop_id
95  -2, // on stop_type (gets increased later by one so it gets -1)
96  -1, // not accounting total loads
97  static_cast<int64_t>(total_travel_time()),
98  -1, // not accounting arrival_travel_time
99  static_cast<int64_t>(wait_time()),
100  -1, // not accounting operation time
101  static_cast<int64_t>(total_service_time()),
102  static_cast<int64_t>(duration()),
103  cvTot(),
104  twvTot()
105  };
106  result.push_back(aggregates);
107 
108  return result;
109 }

References vrprouting::problem::Solution::cvTot(), vrprouting::problem::Solution::duration(), vrprouting::problem::Solution::m_fleet, vrprouting::problem::Solution::total_service_time(), vrprouting::problem::Solution::total_travel_time(), vrprouting::problem::Solution::twvTot(), and vrprouting::problem::Solution::wait_time().

◆ get_stops()

std::vector< Short_vehicle > Solution::get_stops ( ) const
inherited

get solution like postgres needs it

Returns
container for postgres

Definition at line 49 of file solution.cpp.

49  {
50  std::vector<Short_vehicle> result;
51  for (auto v : m_fleet) {
52  result.push_back(Short_vehicle{v.id(), v.get_stops()});
53  }
54  return result;
55 }

References Short_vehicle::id, and vrprouting::problem::Solution::m_fleet.

◆ intensify()

void vrprouting::optimizers::tabu::Optimize::intensify ( )
private

Intensify the search.

intensify

  • Intensifies the search by returning to the current best solution and only focusing on moves that improve the current best solution.

Definition at line 408 of file optimizers/tabu.cpp.

408  {
410 
411  bool do_spi = true;
412  bool do_sbr = true;
413 
414  int max_iter = 20;
415  int i = 0;
416  while (do_spi && i < max_iter) {
417  do_spi = single_pair_insertion(true, false);
418  if (do_spi) if (!are_all_served(m_unassignedOrders)) move_2_real();
419  i++;
420  }
421  i = 0;
422  while (do_sbr && i < max_iter) {
423  do_sbr = swap_between_routes(true, false);
424  if (do_spi) if (!are_all_served(m_unassignedOrders)) move_2_real();
425  i++;
426  }
427 }

References anonymous_namespace{tabu.cpp}::are_all_served(), best_solution, vrprouting::problem::Solution::fleet(), vrprouting::problem::Solution::m_fleet, m_unassignedOrders, move_2_real(), single_pair_insertion(), and swap_between_routes().

Referenced by single_pair_insertion(), swap_between_routes(), and tabu_search().

◆ is_feasible()

bool Solution::is_feasible ( ) const
inherited

is the solution feasible?

The solution is feasible when all vehicles are feasible.

Returns
true when all vehicles in solution are feasible

Definition at line 129 of file solution.cpp.

129  {
130  return std::find_if(m_fleet.begin(), m_fleet.end(),
131  [] (const Vehicle_pickDeliver& v) -> bool {return !v.is_feasible();}) == m_fleet.end();
132 }

References vrprouting::problem::Solution::m_fleet.

Referenced by vrprouting::optimizers::simple::Optimize::decrease_truck(), vrprouting::initialsol::simple::Initial_solution::do_while_feasible(), vrprouting::initialsol::simple::Initial_solution::do_while_foo(), vrprouting::initialsol::tabu::Initial_solution::Initial_solution(), vrprouting::initialsol::tabu::Initial_solution::process_given_solution_from_user(), and vrprouting::initialsol::tabu::Initial_solution::process_unassigned().

◆ move_2_real()

bool vrprouting::optimizers::tabu::Optimize::move_2_real ( )
private

moves orders from phony vehicles to a real vehicle

move_2_real

  • moving orders from a phony vehicle to a real vehicle
  • vehicles can be unordered
  • returns true if unassigned orders were assigned to a (real) vehicle

Definition at line 134 of file optimizers/tabu.cpp.

134  {
135  ENTERING(msg());
136  /*
137  * nothing to do:
138  * - No orders pending on phony vehicle
139  */
140  if (are_all_served(m_unassignedOrders)) return false;
142 
143  bool moves_were_done(false);
144 
145  /*
146  * cycling to find phony vehicles
147  */
148  for (auto &phony_vehicle : m_fleet) {
149  /*
150  * skip
151  * - real vehicle
152  * - empty vehicle
153  */
154  if (phony_vehicle.is_real() || phony_vehicle.empty()) continue;
155  pgassert(phony_vehicle.is_phony() && !phony_vehicle.empty());
156 
157 
158  auto orders_in_phony_vehicle = phony_vehicle.orders_in_vehicle();
159  for (const auto o_id : orders_in_phony_vehicle) {
160  /*
161  * get the order to be inserted on a real vehicle
162  */
163  double best_score = 0;
164  auto order = orders()[o_id];
165 
166  auto best_vehicle_ref = &phony_vehicle;
167 
168  for (auto &real_vehicle : m_fleet) {
169  /*
170  * skip when:
171  * - destination vehicle is the current vehicle
172  * - destination vehicle is phony
173  * - When current order is not feasible on real vehicle
174  */
175  if (&phony_vehicle == &real_vehicle) continue;
176  if (real_vehicle.is_phony()) continue;
177  if (!real_vehicle.feasible_orders().has(o_id)) continue;
178  if (real_vehicle.has_order(order)) continue;
179 
180  pgassert(&phony_vehicle != &real_vehicle);
181  pgassert(real_vehicle.is_real());
182 
183  /*
184  * setup local working vehicles
185  */
186  auto real_vehicle_copy = real_vehicle;
187 
188  /* current travel_time */
189  auto curr_travel_time = phony_vehicle.total_travel_time() + real_vehicle_copy.total_travel_time();
190 
191  /*
192  * insert order on destination vehicle
193  */
194  pgassert(!real_vehicle_copy.has_order(order));
195  real_vehicle_copy.hillClimb(order);
196 
197  // either the to vehicle has the and is feasible OR it does not have the order
198  pgassert((real_vehicle_copy.has_order(order) && real_vehicle_copy.is_feasible())
199  || !real_vehicle_copy.has_order(order));
200 
201  /*
202  * Skip to next order if the order wasnt inserted
203  */
204  if (!real_vehicle_copy.has_order(order)) continue;
205  pgassert(real_vehicle_copy.has_order(order));
206 
207  auto new_travel_time = phony_vehicle.total_travel_time() + real_vehicle_copy.total_travel_time();
208  auto delta_travel_time = new_travel_time - curr_travel_time;
209 
210  auto delta_objective = delta_travel_time;
211  auto estimated_objective = objective() + static_cast<double>(delta_objective);
212 
213 
214  if (best_score == 0 || estimated_objective < best_score) {
215  best_score = estimated_objective;
216  best_vehicle_ref = &real_vehicle;
217  }
218  } // to_v
219 
220  if (best_score != 0) {
221  pgassert(best_vehicle_ref != &phony_vehicle);
222  phony_vehicle.erase(order);
223  best_vehicle_ref->hillClimb(order);
224  m_unassignedOrders -= order.idx();
225  best_solution = (*this);
226  moves_were_done = true;
227  }
228  } // orders
229  } // from phony
230  EXITING(msg());
231  if (moves_were_done) tabu_list.clear();
232  return moves_were_done;
233 }

References anonymous_namespace{tabu.cpp}::are_all_served(), best_solution, vrprouting::optimizers::tabu::TabuList::clear(), ENTERING, EXITING, vrprouting::problem::Solution::m_fleet, m_unassignedOrders, vrprouting::problem::Solution::msg(), vrprouting::problem::Solution::objective(), vrprouting::problem::Solution::orders(), pgassert, and tabu_list.

Referenced by diversify(), intensify(), and tabu_search().

◆ msg()

◆ objective()

double vrprouting::problem::Solution::objective ( ) const
inlineinherited

Get the value of the objective function.

Definition at line 110 of file solution.h.

110 {return static_cast<double>(total_travel_time());}

References vrprouting::problem::Solution::total_travel_time().

Referenced by move_2_real(), single_pair_insertion(), swap_between_routes(), and tabu_search().

◆ operator<()

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

Definition at line 267 of file solution.cpp.

267  {
268  auto lhs(cost());
269  auto rhs(s_rhs.cost());
270 
271  /*
272  * time window violations
273  */
274  if (std::get<0>(lhs) < std::get<0>(rhs))
275  return true;
276  if (std::get<0>(lhs) > std::get<0>(rhs))
277  return false;
278 
279  /*
280  * capacity violations
281  */
282  if (std::get<1>(lhs) < std::get<1>(rhs))
283  return true;
284  if (std::get<1>(lhs) > std::get<1>(rhs))
285  return false;
286 
287  /*
288  * fleet size
289  */
290  if (std::get<2>(lhs) < std::get<2>(rhs))
291  return true;
292  if (std::get<2>(lhs) > std::get<2>(rhs))
293  return false;
294 
295  /*
296  * waiting time
297  */
298  if (std::get<3>(lhs) < std::get<3>(rhs))
299  return true;
300  if (std::get<3>(lhs) > std::get<3>(rhs))
301  return false;
302 
303  /*
304  * duration
305  */
306  if (std::get<4>(lhs) < std::get<4>(rhs))
307  return true;
308  if (std::get<4>(lhs) > std::get<4>(rhs))
309  return false;
310 
311  return false;
312 }

References vrprouting::problem::Solution::cost().

◆ orders()

◆ save_if_best()

void vrprouting::optimizers::tabu::Optimize::save_if_best ( )
private

save a new found solution only if it is best

Save as best solution when objective function value is smaller.

Definition at line 805 of file optimizers/tabu.cpp.

805  {
806  if (objective() < best_solution.objective()) {
807  best_solution = (*this);
808  msg().log << "\t*** best objective " << best_solution.cost_str();
809  }
810 }

Referenced by single_pair_insertion(), and swap_between_routes().

◆ set_tabu_list_length()

void vrprouting::optimizers::tabu::Optimize::set_tabu_list_length ( )
private

set tabu length

set_tabu_list_length

  • Sets the tabu list max length

Definition at line 241 of file optimizers/tabu.cpp.

241  {
242  auto max_length = std::max(orders().size(), m_standard_limit);
243  tabu_list.set_max_length(max_length);
244 }

References m_standard_limit, vrprouting::problem::Solution::orders(), vrprouting::optimizers::tabu::TabuList::set_max_length(), and tabu_list.

Referenced by tabu_search().

◆ single_pair_insertion()

bool vrprouting::optimizers::tabu::Optimize::single_pair_insertion ( bool  intensify,
bool  diversify 
)
private

Single Pair Insertion: move order from one vehicle to another that reduces objective value.

Single Pair Insertion.

Returns
false when a single pair insertion was not successful
true when a single pair insertion was successful
Parameters
[in]intensifyto declare an intensification phase single pair insertion
[in]diversifyto declare an diversification phase single pair insertion

Definition at line 468 of file optimizers/tabu.cpp.

468  {
469  sort_by_size(true);
470  auto best_to_v = &m_fleet[0];
471  auto best_from_v = &m_fleet[0];
472  double best_score = intensify ? objective() : 0;
473  double best_to_score;
474  double best_from_score;
475  bool moved = false;
476  auto best_order = orders()[0];
477  bool has_phony = false;
478 
479  std::string best_candidate;
480 
481  for (auto &from_vehicle : m_fleet) {
482  if (from_vehicle.is_phony() || from_vehicle.empty()) continue;
483 
484  auto first_order_set = from_vehicle.orders_in_vehicle();
485  for (const auto o_id : first_order_set) {
486  auto order = orders()[o_id];
487  for (auto &to_v : m_fleet) {
488  if (&from_vehicle == &to_v) continue;
489  if (to_v.is_phony()) {
490  has_phony = true;
491  }
492  if (to_v.is_phony()) continue;
493  if (!has_phony && to_v.empty()) continue;
494 
495  if (!to_v.feasible_orders().has(o_id)) continue;
496 
497  std::ostringstream ss;
498 
499  ss << to_v.path_str() << ":" << o_id;
500 
501  std::string candidate = ss.str();
502 
503  if (tabu_list.has_infeasible(candidate)) continue;
504 
505  if (diversify && tabu_list.has_seen(candidate)) continue;
506 
507  /*
508  * setup local working vehicles
509  */
510  auto to_v_copy = to_v;
511  auto from_v_copy = from_vehicle;
512 
513  /* current travel_time */
514  auto curr_travel_time = from_v_copy.total_travel_time() + to_v_copy.total_travel_time();
515 
516  /*
517  * insert order on destination vehicle
518  */
519  pgassert(!to_v_copy.has_order(order));
520  to_v_copy.hillClimb(order);
521 
522  // either the to vehicle has the order and is feasible OR it does not have the order
523  pgassert((to_v_copy.has_order(order) && to_v_copy.is_feasible()) || !to_v_copy.has_order(order));
524 
525  /*
526  * Skip to next order if the order wasn't inserted
527  */
528  if (!to_v_copy.has_order(order)) {
529  tabu_list.add_infeasible(candidate);
530  continue;
531  }
532 
533  from_v_copy.erase(order);
534  if (from_v_copy.has_order(order) || !from_v_copy.is_feasible()) continue;
535 
536  auto new_travel_time = from_v_copy.total_travel_time() + to_v_copy.total_travel_time();
537  auto delta_travel_time = new_travel_time - curr_travel_time;
538 
539  auto delta_objective = delta_travel_time;
540  auto estimated_objective = objective() + static_cast<double>(delta_objective);
541 
542  /*
543  * evaluate the move
544  */
545  if (estimated_objective >= best_score && !from_v_copy.empty() && best_score != 0) continue;
546 
547  if (tabu_list.has_move(
548  from_v_copy, to_v_copy, order, to_v_copy.objective(),
549  from_v_copy.objective())
550  && estimated_objective >= best_solution.objective()
551  && !from_v_copy.empty()) continue;
552 
553  if (estimated_objective < best_score || from_v_copy.empty() || best_score == 0) {
554  moved = true;
555  best_score = estimated_objective;
556  best_to_score = to_v.objective();
557  best_from_score = from_vehicle.objective();
558  best_to_v = &to_v;
559  best_from_v = &from_vehicle;
560  best_order = order;
561  best_candidate = candidate;
562  }
563  } // to vehicles
564  } // orders
565  } // from vehicles
566 
567  if (moved) {
568  tabu_list.add(Move((*best_from_v), (*best_to_v), best_order, best_to_score, best_from_score));
569  best_to_v->hillClimb(best_order);
570  best_from_v->erase(best_order);
571  tabu_list.add_seen(best_candidate);
572  if (best_from_v->is_phony()) m_unassignedOrders -= best_order.idx();
573  save_if_best();
574  }
575  return moved;
576 }

References vrprouting::optimizers::tabu::TabuList::add(), vrprouting::optimizers::tabu::TabuList::add_infeasible(), vrprouting::optimizers::tabu::TabuList::add_seen(), best_solution, diversify(), vrprouting::optimizers::tabu::TabuList::has_infeasible(), vrprouting::optimizers::tabu::TabuList::has_move(), vrprouting::optimizers::tabu::TabuList::has_seen(), intensify(), vrprouting::problem::Solution::m_fleet, m_unassignedOrders, vrprouting::problem::Solution::objective(), vrprouting::problem::Solution::orders(), pgassert, save_if_best(), sort_by_size(), and tabu_list.

Referenced by diversify(), intensify(), and tabu_search().

◆ sort_by_size()

void vrprouting::optimizers::tabu::Optimize::sort_by_size ( bool  asc)
private
Postcondition
pv1.size <= pv2.size ... <= pvN.size v1.size <= v2.size ... <= vN.size

Definition at line 742 of file optimizers/tabu.cpp.

742  {
743  /*
744  * sort by number of orders on the vehicles
745  */
746  if (asc) {
747  std::sort(m_fleet.begin(), m_fleet.end(), []
748  (const problem::Vehicle_pickDeliver &lhs, const problem::Vehicle_pickDeliver &rhs)
749  -> bool {
750  if (lhs.orders_in_vehicle().size() == rhs.orders_in_vehicle().size()) {
751  return lhs.id() < rhs.id();
752  } else {
753  return lhs.orders_in_vehicle().size() < rhs.orders_in_vehicle().size();
754  }
755  });
756  } else {
757  std::sort(m_fleet.begin(), m_fleet.end(), []
758  (const problem::Vehicle_pickDeliver &lhs, const problem::Vehicle_pickDeliver &rhs)
759  -> bool {
760  if (lhs.orders_in_vehicle().size() == rhs.orders_in_vehicle().size()) {
761  return lhs.id() > rhs.id();
762  } else {
763  return lhs.orders_in_vehicle().size() > rhs.orders_in_vehicle().size();
764  }
765  });
766  }
767 
768 
769  /*
770  * Leave the phony vehicles at the beginning
771  */
772  std::stable_partition(m_fleet.begin(), m_fleet.end(), []
773  (const problem::Vehicle_pickDeliver &v)
774  -> bool {
775  return v.id() < 0;
776  });
777 }

References vrprouting::problem::Solution::m_fleet.

Referenced by single_pair_insertion(), swap_between_routes(), and tabu_search().

◆ swap_between_routes()

bool vrprouting::optimizers::tabu::Optimize::swap_between_routes ( bool  intensify,
bool  diversify 
)
private

Swapping pairs Between Routes: initiate directed or undirected swaps of orders between vehicles.

Swap Between Routes.

Returns
false when a swap between routes was not successful
true when a swap between routes was successful
Parameters
[in]intensifyto declare an intensification phase swap between routes
[in]diversifyto declare an diversification phase swap between routes

Definition at line 587 of file optimizers/tabu.cpp.

587  {
588  sort_by_size(false);
589  auto best_to_v = &m_fleet[0];
590  auto best_from_v = &m_fleet[0];
591  double best_score = intensify ? objective() : 0;
592  double best_to_score;
593  double best_from_score;
594  bool swapped = false;
595  auto best_from_order = orders()[0];
596  auto best_to_order = orders()[0];
597 
598  std::string best_candidate1;
599  std::string best_candidate2;
600 
601  for (size_t i = 0; i < m_fleet.size(); ++i) {
602  problem::Vehicle_pickDeliver &from_vehicle = m_fleet[i];
603  if (from_vehicle.is_phony() || from_vehicle.empty()) continue;
604 
605  auto first_order_set = from_vehicle.orders_in_vehicle();
606  for (const auto o_id1 : first_order_set) {
607  auto order1 = orders()[o_id1];
608  for (size_t j = i + 1; j < m_fleet.size(); ++j) {
609  problem::Vehicle_pickDeliver &to_v = m_fleet[j];
610  if (&from_vehicle == &to_v) continue;
611  if (to_v.is_phony() || to_v.empty()) continue;
612  if (!to_v.feasible_orders().has(o_id1)) continue;
613 
614 
615  /*
616  * cycle through to orders for swap
617  */
618  auto second_order_set = to_v.orders_in_vehicle();
619  for (const auto o_id2 : second_order_set) {
620  auto order2 = orders()[o_id2];
621  if (!from_vehicle.feasible_orders().has(o_id2)) continue;
622 
623  auto curr_from_objective = from_vehicle.objective();
624  auto curr_to_objective = to_v.objective();
625 
626  /*
627  * setup local working vehicles
628  */
629  auto from_v_copy = from_vehicle;
630  auto to_v_copy = to_v;
631 
632 
633  pgassert(from_v_copy.has_order(order1));
634  pgassert(to_v_copy.has_order(order2));
635 
636 
637  /*
638  * do one truck at a time
639  */
640  to_v_copy.erase(order2);
641  if (to_v_copy.orders_in_vehicle().has(o_id2) || !to_v_copy.is_feasible()) continue;
642 
643  std::ostringstream ss1;
644  ss1 << to_v_copy.path_str() << ":" << o_id1;
645 
646  std::string candidate1 = ss1.str();
647 
648  if (tabu_list.has_infeasible(candidate1)) continue;
649 
650  from_v_copy.erase(order1);
651  if (from_v_copy.orders_in_vehicle().has(o_id1) || !from_v_copy.is_feasible()) continue;
652 
653  std::ostringstream ss2;
654  ss2 << from_v_copy.path_str() << ":" << o_id2;
655 
656  std::string candidate2 = ss2.str();
657 
658  if (diversify && tabu_list.has_seen(candidate1) && tabu_list.has_seen(candidate2)) continue;
659 
660  if (tabu_list.has_infeasible(candidate2)) continue;
661 
662  to_v_copy.hillClimb(order1);
663  if (!to_v_copy.has_order(order1) || !to_v_copy.is_feasible()) {
664  tabu_list.add_infeasible(candidate1);
665  continue;
666  }
667 
668 
669  from_v_copy.hillClimb(order2);
670  if (!from_v_copy.has_order(order2) || !from_v_copy.is_feasible()) {
671  tabu_list.add_infeasible(candidate2);
672  continue;
673  }
674 
675 
676  /*
677  * Evaluate the swap
678  */
679  auto new_from_objective = from_v_copy.objective();
680  auto new_to_objective = to_v_copy.objective();
681 
682  auto estimated_delta =
683  +(new_to_objective + new_from_objective)
684  - (curr_from_objective + curr_to_objective);
685 
686  auto estimated_objective = objective() + estimated_delta;
687  /*
688  * dont swap if there is no improvement in either vehicle
689  */
690  if (estimated_objective >= best_score && best_score != 0) continue;
691 
692  if (tabu_list.has_swap(
693  from_v_copy, to_v_copy, order1, order2, from_v_copy.objective(),
694  to_v_copy.objective())
695  && estimated_objective >= best_solution.objective()) continue;
696 
697 
698  if (estimated_objective < best_score || best_score == 0) {
699  swapped = true;
700  best_from_score = from_vehicle.objective();
701  best_to_score = to_v.objective();
702  best_score = estimated_objective;
703  best_to_v = &to_v;
704  best_from_v = &from_vehicle;
705  best_from_order = order1;
706  best_to_order = order2;
707  best_candidate1 = candidate1;
708  best_candidate2 = candidate2;
709  }
710  }
711  } // to vehicles
712  } // orders
713  } // from vehicles
714  if (swapped) {
715  tabu_list.add(
716  Move((*best_from_v), (*best_to_v), best_from_order, best_to_order, best_to_score, best_from_score));
717  best_from_v->erase(best_from_order);
718  best_to_v->erase(best_to_order);
719  best_from_v->hillClimb(best_to_order);
720  best_to_v->hillClimb(best_from_order);
721  tabu_list.add_seen(best_candidate1);
722  tabu_list.add_seen(best_candidate2);
723  if (best_from_v->is_phony()) {
724  m_unassignedOrders -= best_from_order.idx();
725  m_unassignedOrders += best_to_order.idx();
726  }
727  if (best_to_v->is_phony()) {
728  m_unassignedOrders -= best_to_order.idx();
729  m_unassignedOrders += best_from_order.idx();
730  }
731  save_if_best();
732  }
733  return swapped;
734 }

References vrprouting::optimizers::tabu::TabuList::add(), vrprouting::optimizers::tabu::TabuList::add_infeasible(), vrprouting::optimizers::tabu::TabuList::add_seen(), best_solution, diversify(), vrprouting::problem::Vehicle_pickDeliver::empty(), vrprouting::problem::Vehicle_pickDeliver::feasible_orders(), Identifiers< T >::has(), vrprouting::optimizers::tabu::TabuList::has_infeasible(), vrprouting::optimizers::tabu::TabuList::has_seen(), vrprouting::optimizers::tabu::TabuList::has_swap(), intensify(), vrprouting::problem::Vehicle::is_phony(), vrprouting::problem::Solution::m_fleet, m_unassignedOrders, vrprouting::problem::Solution::objective(), vrprouting::problem::Vehicle_pickDeliver::objective(), vrprouting::problem::Solution::orders(), vrprouting::problem::Vehicle_pickDeliver::orders_in_vehicle(), pgassert, save_if_best(), sort_by_size(), and tabu_list.

Referenced by diversify(), intensify(), and tabu_search().

◆ tabu_search()

void vrprouting::optimizers::tabu::Optimize::tabu_search ( )
private

Main optimization controller.

tabu_search will find the best solution.

The best solution is one that either:

  1. adds an order
  2. meets the evaluation criteria. It searches until either (terminating conditions):
  1. all cycles are complete
  2. all possible orders are served without optimization and optimize is set to false
  3. all orders are served and stop_on_all_served is set to true The stopping condition stop_on_all_served exists in order to give a fast response to the user. Note:
  • Phony vehicles (if exist) have orders that have not been served

The vehicle sort results on: [pv1, pv2, pv3, ... pvK, rv1 rv2 ... rvN] Phony vehicles (if exist) have orders that have not been served where:

  • [pv1, pv2, ... pvK] are phony vehicles
  • [rv1 ... rvN] are real vehicles And within the real vehicles for i < j : rv(i).size < rv(j).size

Loop through cycles of tabu search Exit the loop when:

  • all orders are served if stop_on_all_served
  • maximum number of cycles is reached

Definition at line 274 of file optimizers/tabu.cpp.

274  {
275  ENTERING(msg());
276 
277  sort_by_size(true);
278 
280 
281  move_2_real();
283  /*
284  * stop if no optimization is asked
285  */
286  if (!m_optimize) return;
287 
288  /*
289  * stop if all orders are served
290  */
292 
294  /*
295  * Do the cycles
296  */
297  /*
298  * initialize the iterator counter
299  */
300  size_t iter = 0;
301 
302  int no_moves = 0;
303 
304  int max_no_moves = 2;
305 
306  int max_no_swaps = 2;
307 
308  bool diversification = true;
309 
310  bool intensification = false;
311 
312  bool do_spi = true;
313 
314  int could_not_spi = 0;
315 
316  int stuck_counter = 0;
317 
318  int wander_counter = 0;
319 
320  int max_no_improvement = 1000;
321 
322  std::string neighborhood;
323 
324  int wander_length = 100;
325 
326  while (iter < m_max_cycles) {
327  double curr_best = best_solution.objective();
328 
329  if (stuck_counter == max_no_improvement) {
330  intensify();
331  if (best_solution.objective() == curr_best)
332  break;
333  }
334 
335  if (no_moves < max_no_moves && do_spi) {
336  neighborhood = "spi";
337  } else {
338  neighborhood = "sbr";
339  }
340 
341  bool moved;
342 
343  if (neighborhood == "spi") {
344  moved = single_pair_insertion(false, false);
346  if (moved) {
348  }
349  } else {
350  moved = swap_between_routes(false, false);
351  if (moved) {
353  }
354  }
355 
357 
358  if (!moved) {
359  no_moves += 1;
360  if (neighborhood == "spi") {
361  could_not_spi += 1;
362  }
363  if (neighborhood == "sbr") {
364  intensify();
365  }
366  } else {
367  no_moves = 0;
368  }
369 
370  if (no_moves >= max_no_swaps + max_no_moves) break;
371 
373 
374  /*
375  * check for aimless wandering ...
376  */
377  if (curr_best == best_solution.objective()) {
378  stuck_counter += 1;
379  wander_counter += 1;
380  if (stuck_counter % wander_length == 0) {
381  intensification = !intensification;
382  diversification = !diversification;
383 
384  if (intensification) {
385  intensify();
386  }
387  if (diversification) {
388  diversify();
389  }
390  }
391  } else {
392  // if it is not the same then it must be better!
393  stuck_counter = 0;
394  }
395  iter++;
396  }
397  EXITING(msg());
398 }

References anonymous_namespace{tabu.cpp}::are_all_served(), best_solution, delete_empty_truck(), diversify(), ENTERING, EXITING, intensify(), vrprouting::problem::Solution::m_fleet, m_max_cycles, m_optimize, m_stop_on_all_served, m_unassignedOrders, move_2_real(), vrprouting::problem::Solution::msg(), vrprouting::problem::Solution::objective(), set_tabu_list_length(), anonymous_namespace{tabu.cpp}::set_unassignedOrders(), single_pair_insertion(), sort_by_size(), and swap_between_routes().

Referenced by Optimize().

◆ tau()

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

writing the solution in compact form into a string

Parameters
[in]titleTitle to Use for the tau
Returns
The solution in one compacted string

Definition at line 116 of file solution.cpp.

116  {
117  std::string str {"\n" + title + ": " + '\n'};
118  for (const auto& v : m_fleet) str += ("\n" + v.tau());
119  str += "\n" + cost_str() + "\n";
120  return str;
121 }

References vrprouting::problem::Solution::cost_str(), and vrprouting::problem::Solution::m_fleet.

Referenced by vrprouting::optimizers::simple::Optimize::inter_swap(), vrprouting::optimizers::simple::Optimize::Optimize(), and Optimize().

◆ total_service_time()

TInterval Solution::total_service_time ( ) const
inherited

Total service time of the solution.

Returns
the total service time of the solution

The total service time of the solution is the sum of the service times of all vehicles

Definition at line 174 of file solution.cpp.

174  {
175  return std::accumulate(begin(m_fleet), end(m_fleet), static_cast<TInterval>(0),
176  [](TInterval i, const Vehicle_pickDeliver& v) {return v.total_service_time() + i;});
177 }

References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::total_service_time().

Referenced by vrprouting::problem::Solution::get_postgres_result().

◆ total_travel_time()

TInterval Solution::total_travel_time ( ) const
inherited

Total travel time of the solution.

Returns
the total waiting time

The total travel time of the solution is the sum of the travel times of all vehicles

Definition at line 162 of file solution.cpp.

162  {
163  return std::accumulate(begin(m_fleet), end(m_fleet), static_cast<TInterval>(0),
164  [](TInterval i, const Vehicle_pickDeliver& v) {return v.total_travel_time() + i;});
165 }

References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::total_travel_time().

Referenced by vrprouting::problem::Solution::get_postgres_result(), and vrprouting::problem::Solution::objective().

◆ twvTot()

int Solution::twvTot ( ) const
inherited

Total number of time windows constraint violations of the solution.

Returns
the total number of time window violations

The total time window violations of the solution is the sum of the time window violations of all vehicles

Definition at line 185 of file solution.cpp.

185  {
186  return std::accumulate(begin(m_fleet), end(m_fleet), 0,
187  [](int i, const Vehicle_pickDeliver& v) {return v.twvTot() + i;});
188 }

References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::twvTot().

Referenced by vrprouting::problem::Solution::get_postgres_result().

◆ vehicles()

◆ wait_time()

TInterval Solution::wait_time ( ) const
inherited

Total waiting time of the solution.

Returns
the total waiting time

The total waiting time of the solution is the sum of the waiting time of all vehicles

Definition at line 151 of file solution.cpp.

151  {
152  return std::accumulate(begin(m_fleet), end(m_fleet), static_cast<TInterval>(0),
153  [](TInterval i, const Vehicle_pickDeliver& v) {return v.total_wait_time() + i;});
154 }

References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::total_wait_time().

Referenced by vrprouting::problem::Solution::get_postgres_result().

Member Data Documentation

◆ best_solution

problem::Solution vrprouting::optimizers::tabu::Optimize::best_solution

The best solution so far.

Definition at line 57 of file optimizers/tabu.h.

Referenced by intensify(), move_2_real(), Optimize(), single_pair_insertion(), swap_between_routes(), and tabu_search().

◆ m_fleet

std::deque<Vehicle_pickDeliver> vrprouting::problem::Solution::m_fleet
protectedinherited

The current solution.

Definition at line 125 of file solution.h.

Referenced by vrprouting::problem::Solution::cost(), vrprouting::problem::Solution::cvTot(), vrprouting::optimizers::simple::Optimize::decrease_truck(), vrprouting::optimizers::simple::Optimize::delete_empty_truck(), diversify(), vrprouting::initialsol::simple::Initial_solution::do_while_foo(), vrprouting::problem::Solution::duration(), vrprouting::problem::Solution::fleet(), vrprouting::problem::Solution::get_postgres_result(), vrprouting::problem::Solution::get_stops(), vrprouting::initialsol::tabu::Initial_solution::Initial_solution(), intensify(), vrprouting::optimizers::simple::Optimize::inter_swap(), vrprouting::problem::Solution::is_feasible(), move_2_real(), vrprouting::initialsol::simple::Initial_solution::one_truck_all_orders(), vrprouting::optimizers::simple::Optimize::Optimize(), Optimize(), vrprouting::initialsol::tabu::Initial_solution::process_given_solution_from_user(), vrprouting::initialsol::tabu::Initial_solution::process_unassigned(), vrprouting::optimizers::simple::Optimize::save_if_best(), single_pair_insertion(), vrprouting::optimizers::simple::Optimize::sort_by_duration(), vrprouting::optimizers::simple::Optimize::sort_by_id(), vrprouting::optimizers::simple::Optimize::sort_by_size(), sort_by_size(), vrprouting::optimizers::simple::Optimize::sort_for_move(), swap_between_routes(), tabu_search(), vrprouting::problem::Solution::tau(), vrprouting::problem::Solution::total_service_time(), vrprouting::problem::Solution::total_travel_time(), vrprouting::problem::Solution::twvTot(), and vrprouting::problem::Solution::wait_time().

◆ m_max_cycles

size_t vrprouting::optimizers::tabu::Optimize::m_max_cycles
private

Maximum number of cycles on the optimization process.

Definition at line 87 of file optimizers/tabu.h.

Referenced by tabu_search().

◆ m_msg

Pgr_messages vrprouting::problem::Solution::m_msg
protectedinherited

Definition at line 130 of file solution.h.

Referenced by vrprouting::problem::Solution::msg().

◆ m_optimize

bool vrprouting::optimizers::tabu::Optimize::m_optimize
private

Flag to just build a solution and not optimize it.

Definition at line 93 of file optimizers/tabu.h.

Referenced by tabu_search().

◆ m_orders

Orders vrprouting::problem::Solution::m_orders
protectedinherited

◆ m_standard_limit

size_t vrprouting::optimizers::tabu::Optimize::m_standard_limit = 30
private

Limit for a cycle.

Definition at line 96 of file optimizers/tabu.h.

Referenced by set_tabu_list_length().

◆ m_stop_on_all_served

bool vrprouting::optimizers::tabu::Optimize::m_stop_on_all_served
private

Flag to stop when all orders are in real vehicles.

Definition at line 90 of file optimizers/tabu.h.

Referenced by tabu_search().

◆ m_trucks

Fleet vrprouting::problem::Solution::m_trucks
protectedinherited

Definition at line 129 of file solution.h.

Referenced by vrprouting::problem::Solution::vehicles().

◆ m_unassignedOrders

Identifiers<size_t> vrprouting::optimizers::tabu::Optimize::m_unassignedOrders
private

Set of unassigned orders.

Definition at line 105 of file optimizers/tabu.h.

Referenced by diversify(), intensify(), move_2_real(), single_pair_insertion(), swap_between_routes(), and tabu_search().

◆ tabu_list

TabuList vrprouting::optimizers::tabu::Optimize::tabu_list
private

Tabu lists of the problem.

Definition at line 61 of file optimizers/tabu.h.

Referenced by move_2_real(), set_tabu_list_length(), single_pair_insertion(), and swap_between_routes().


The documentation for this class was generated from the following files:
vrprouting::problem::Solution::orders
const Orders & orders() const
Definition: solution.h:120
vrprouting::optimizers::tabu::Optimize::save_if_best
void save_if_best()
save a new found solution only if it is best
Definition: optimizers/tabu.cpp:805
vrprouting::optimizers::tabu::TabuList::has_seen
bool has_seen(const std::string &candidate)
Checks to see if a move candidate has already been done before (in the seen list)
Definition: tabu_list.cpp:158
EXITING
#define EXITING(x)
Definition: pgr_messages.h:105
vrprouting::Pgr_messages::log
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:91
vrprouting::problem::Solution::total_service_time
TInterval total_service_time() const
Total service time of the solution.
Definition: solution.cpp:174
vrprouting::optimizers::tabu::Optimize::best_solution
problem::Solution best_solution
The best solution so far.
Definition: optimizers/tabu.h:57
vrprouting::problem::Solution::objective
double objective() const
Get the value of the objective function.
Definition: solution.h:110
vrprouting::problem::Solution::m_fleet
std::deque< Vehicle_pickDeliver > m_fleet
The current solution.
Definition: solution.h:125
vrprouting::optimizers::tabu::Optimize::swap_between_routes
bool swap_between_routes(bool intensify, bool diversify)
Swapping pairs Between Routes: initiate directed or undirected swaps of orders between vehicles.
Definition: optimizers/tabu.cpp:587
vrprouting::optimizers::tabu::TabuList::has_move
bool has_move(const problem::Vehicle_pickDeliver &, const problem::Vehicle_pickDeliver &, const problem::Order &from_order, double obj1, double obj2) const
Checks to see if a "move" move is "tabu" (in the tabu list)
Definition: tabu_list.cpp:73
vrprouting::optimizers::tabu::Optimize::tabu_list
TabuList tabu_list
Tabu lists of the problem.
Definition: optimizers/tabu.h:61
vrprouting::problem::Solution::cvTot
int cvTot() const
Total number of capacity constraint violations of the solution.
Definition: solution.cpp:196
anonymous_namespace{tabu.cpp}::set_unassignedOrders
Identifiers< size_t > set_unassignedOrders(const std::deque< vrprouting::problem::Vehicle_pickDeliver > &fleet)
set of unassigned orders
Definition: optimizers/tabu.cpp:48
vrprouting::problem::Solution::total_travel_time
TInterval total_travel_time() const
Total travel time of the solution.
Definition: solution.cpp:162
ENTERING
#define ENTERING(x)
Definition: pgr_messages.h:104
vrprouting::optimizers::tabu::Optimize::single_pair_insertion
bool single_pair_insertion(bool intensify, bool diversify)
Single Pair Insertion: move order from one vehicle to another that reduces objective value.
Definition: optimizers/tabu.cpp:468
Short_vehicle::id
Id id
Definition: short_vehicle.h:42
anonymous_namespace{tabu.cpp}::are_all_served
bool are_all_served(const Identifiers< size_t > &unassigned)
Are all orders served?
Definition: optimizers/tabu.cpp:63
vrprouting::optimizers::tabu::Optimize::intensify
void intensify()
Intensify the search.
Definition: optimizers/tabu.cpp:408
vrprouting::problem::Solution::twvTot
int twvTot() const
Total number of time windows constraint violations of the solution.
Definition: solution.cpp:185
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
vrprouting::optimizers::tabu::Optimize::move_2_real
bool move_2_real()
moves orders from phony vehicles to a real vehicle
Definition: optimizers/tabu.cpp:134
vrprouting::optimizers::tabu::Optimize::sort_by_size
void sort_by_size(bool asc)
Definition: optimizers/tabu.cpp:742
vrprouting::optimizers::tabu::Optimize::m_unassignedOrders
Identifiers< size_t > m_unassignedOrders
Set of unassigned orders.
Definition: optimizers/tabu.h:105
vrprouting::optimizers::tabu::Optimize::delete_empty_truck
void delete_empty_truck()
deletes phony vehicles that are empty
Definition: optimizers/tabu.cpp:788
vrprouting::problem::Solution::Solution
Solution()=delete
constructor
vrprouting::problem::Solution::wait_time
TInterval wait_time() const
Total waiting time of the solution.
Definition: solution.cpp:151
vrprouting::problem::Solution::duration
TInterval duration() const
Total duration of the solution.
Definition: solution.cpp:140
Short_vehicle
short_vehicle
Definition: short_vehicle.h:41
vrprouting::optimizers::tabu::TabuList::clear
void clear()
removes all moves from the tabu list
Definition: tabu_list.cpp:50
vrprouting::optimizers::tabu::TabuList::add_infeasible
void add_infeasible(const std::string &candidate)
Adds a move candidate to the infeasible list.
Definition: tabu_list.cpp:154
vrprouting::optimizers::tabu::Optimize::diversify
bool diversify()
Diversify the search.
Definition: optimizers/tabu.cpp:437
vrprouting::optimizers::tabu::Optimize::m_stop_on_all_served
bool m_stop_on_all_served
Flag to stop when all orders are in real vehicles.
Definition: optimizers/tabu.h:90
Solution_rt
Solution schedule when twv & cw are hard restrictions.
Definition: solution_rt.h:56
vrprouting::problem::Solution::fleet
const std::deque< Vehicle_pickDeliver > & fleet() const
Get the current fleet solution.
Definition: solution.h:107
vrprouting::problem::Solution::msg
Pgr_messages & msg()
Definition: solution.h:119
vrprouting::optimizers::tabu::TabuList::has_swap
bool has_swap(const problem::Vehicle_pickDeliver &, const problem::Vehicle_pickDeliver &, const problem::Order &, const problem::Order &, double obj1, double obj2) const
Checks to see if a "swap" move is "tabu" (in the tabu list)
Definition: tabu_list.cpp:91
vrprouting::problem::Solution::tau
std::string tau(const std::string &title="Tau") const
writing the solution in compact form into a string
Definition: solution.cpp:116
vrprouting::optimizers::tabu::Optimize::m_standard_limit
size_t m_standard_limit
Limit for a cycle.
Definition: optimizers/tabu.h:96
vrprouting::problem::Solution::m_msg
Pgr_messages m_msg
Definition: solution.h:130
vrprouting::optimizers::tabu::Optimize::m_optimize
bool m_optimize
Flag to just build a solution and not optimize it.
Definition: optimizers/tabu.h:93
vrprouting::optimizers::tabu::TabuList::set_max_length
void set_max_length(size_t length)
sets the maximum length (tabu_length) of the tabu list
Definition: tabu_list.cpp:131
vrprouting::optimizers::tabu::Optimize::Optimize
Optimize(const problem::Solution &solution, size_t times, bool stop_on_all_served, bool)
Optimization operation.
Definition: optimizers/tabu.cpp:95
vrprouting::optimizers::tabu::Optimize::set_tabu_list_length
void set_tabu_list_length()
set tabu length
Definition: optimizers/tabu.cpp:241
vrprouting::problem::Solution::cost
std::tuple< int, int, size_t, TInterval, TInterval, TInterval > cost() const
Get all statistics in one cycle.
Definition: solution.cpp:218
vrprouting::optimizers::tabu::TabuList::add_seen
void add_seen(const std::string &candidate)
Adds a move candidate to the seen list.
Definition: tabu_list.cpp:162
vrprouting::optimizers::tabu::TabuList::add
void add(const Move &m)
Make a move "tabu" by adding it to the tabu list.
Definition: tabu_list.cpp:42
TInterval
int64_t TInterval
Definition: typedefs.h:72
vrprouting::optimizers::tabu::Optimize::m_max_cycles
size_t m_max_cycles
Maximum number of cycles on the optimization process.
Definition: optimizers/tabu.h:87
vrprouting::problem::Solution::m_trucks
Fleet m_trucks
Definition: solution.h:129
vrprouting::problem::Solution::m_orders
Orders m_orders
the problem info
Definition: solution.h:128
vrprouting::optimizers::tabu::TabuList::has_infeasible
bool has_infeasible(const std::string &candidate)
Checks to see if a move candidate is infeasible (in the infeasible list)
Definition: tabu_list.cpp:150
vrprouting::optimizers::tabu::Optimize::tabu_search
void tabu_search()
Main optimization controller.
Definition: optimizers/tabu.cpp:274
vrprouting::problem::Solution::cost_str
std::string cost_str() const
Definition: solution.cpp:246