![]() |
vrpRouting
0.3
|
Class that optimizes a solution. More...
#include "tabu.h"
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, TInterval > | cost () 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_rt > | get_postgres_result () const |
get solution like postgres needs it More... | |
std::vector< Short_vehicle > | get_stops () const |
get solution like postgres needs it More... | |
bool | is_feasible () const |
is the solution feasible? More... | |
Pgr_messages & | msg () |
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... | |
Class that optimizes a solution.
How to use:
Definition at line 51 of file optimizers/tabu.h.
vrprouting::optimizers::tabu::Optimize::Optimize | ( | const problem::Solution & | old_solution, |
size_t | max_cycles, | ||
bool | stop_on_all_served, | ||
bool | optimize | ||
) |
Optimization operation.
[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 |
Definition at line 95 of file optimizers/tabu.cpp.
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().
Get all statistics in one cycle.
idx | variable |
---|---|
0 | twv |
1 | cv |
2 | fleet size |
3 | waiting time |
4 | duration |
5 | travel time |
Definition at line 218 of file solution.cpp.
References vrprouting::problem::Solution::m_fleet.
Referenced by vrprouting::problem::Solution::cost_str(), and vrprouting::problem::Solution::operator<().
|
inherited |
Definition at line 246 of file solution.cpp.
References vrprouting::problem::Solution::cost().
Referenced by vrprouting::problem::Solution::tau().
|
inherited |
Total number of capacity constraint violations of the solution.
Definition at line 196 of file solution.cpp.
References vrprouting::problem::Vehicle::cvTot(), and vrprouting::problem::Solution::m_fleet.
Referenced by vrprouting::problem::Solution::get_postgres_result().
|
private |
deletes phony vehicles that are empty
Definition at line 788 of file optimizers/tabu.cpp.
Referenced by Optimize(), and tabu_search().
|
private |
Diversify the search.
diversify
Definition at line 437 of file optimizers/tabu.cpp.
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().
|
inherited |
Total duration of the solution.
The solution duration is the sum of the durations of all vehicles
Definition at line 140 of file solution.cpp.
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().
|
inlineinherited |
Get the current fleet solution.
Definition at line 107 of file solution.h.
References vrprouting::problem::Solution::m_fleet.
Referenced by intensify(), and Optimize().
|
inherited |
get solution like postgres needs it
Definition at line 61 of file solution.cpp.
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().
|
inherited |
get solution like postgres needs it
Definition at line 49 of file solution.cpp.
References Short_vehicle::id, and vrprouting::problem::Solution::m_fleet.
|
private |
Intensify the search.
intensify
Definition at line 408 of file optimizers/tabu.cpp.
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().
|
inherited |
is the solution feasible?
The solution is feasible when all vehicles are feasible.
Definition at line 129 of file solution.cpp.
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().
|
private |
moves orders from phony vehicles to a real vehicle
move_2_real
Definition at line 134 of file optimizers/tabu.cpp.
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().
|
inlineinherited |
Definition at line 119 of file solution.h.
References vrprouting::problem::Solution::m_msg.
Referenced by vrprouting::initialsol::simple::Initial_solution::do_while_foo(), vrprouting::optimizers::simple::Optimize::inter_swap(), move_2_real(), vrprouting::initialsol::simple::Initial_solution::one_truck_all_orders(), vrprouting::optimizers::simple::Optimize::Optimize(), Optimize(), vrprouting::initialsol::tabu::Initial_solution::process_unassigned(), vrprouting::optimizers::simple::Optimize::save_if_best(), and tabu_search().
|
inlineinherited |
Get the value of the objective function.
Definition at line 110 of file solution.h.
References vrprouting::problem::Solution::total_travel_time().
Referenced by move_2_real(), single_pair_insertion(), swap_between_routes(), and tabu_search().
|
inherited |
|
inlineinherited |
Definition at line 120 of file solution.h.
References vrprouting::problem::Solution::m_orders.
Referenced by vrprouting::optimizers::simple::Optimize::decrease_truck(), diversify(), move_2_real(), vrprouting::initialsol::tabu::Initial_solution::process_given_solution_from_user(), vrprouting::initialsol::tabu::Initial_solution::process_unassigned(), set_tabu_list_length(), single_pair_insertion(), and swap_between_routes().
|
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.
Referenced by single_pair_insertion(), and swap_between_routes().
|
private |
set tabu length
set_tabu_list_length
Definition at line 241 of file optimizers/tabu.cpp.
References m_standard_limit, vrprouting::problem::Solution::orders(), vrprouting::optimizers::tabu::TabuList::set_max_length(), and tabu_list.
Referenced by tabu_search().
|
private |
Single Pair Insertion: move order from one vehicle to another that reduces objective value.
Single Pair Insertion.
[in] | intensify | to declare an intensification phase single pair insertion |
[in] | diversify | to declare an diversification phase single pair insertion |
Definition at line 468 of file optimizers/tabu.cpp.
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().
|
private |
Definition at line 742 of file optimizers/tabu.cpp.
References vrprouting::problem::Solution::m_fleet.
Referenced by single_pair_insertion(), swap_between_routes(), and tabu_search().
|
private |
Swapping pairs Between Routes: initiate directed or undirected swaps of orders between vehicles.
Swap Between Routes.
[in] | intensify | to declare an intensification phase swap between routes |
[in] | diversify | to declare an diversification phase swap between routes |
Definition at line 587 of file optimizers/tabu.cpp.
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().
|
private |
Main optimization controller.
tabu_search will find the best solution.
The best solution is one that either:
The vehicle sort results on: [pv1, pv2, pv3, ... pvK, rv1 rv2 ... rvN] Phony vehicles (if exist) have orders that have not been served where:
Loop through cycles of tabu search Exit the loop when:
Definition at line 274 of file optimizers/tabu.cpp.
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().
|
inherited |
writing the solution in compact form into a string
[in] | title | Title to Use for the tau |
Definition at line 116 of file solution.cpp.
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().
|
inherited |
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.
References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::total_service_time().
Referenced by vrprouting::problem::Solution::get_postgres_result().
|
inherited |
Total travel time of the solution.
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.
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().
|
inherited |
Total number of time windows constraint violations of the solution.
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.
References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::twvTot().
Referenced by vrprouting::problem::Solution::get_postgres_result().
|
inlineinherited |
Definition at line 121 of file solution.h.
References vrprouting::problem::Solution::m_trucks.
Referenced by vrprouting::initialsol::simple::Initial_solution::do_while_foo(), vrprouting::initialsol::tabu::Initial_solution::Initial_solution(), vrprouting::initialsol::simple::Initial_solution::one_truck_all_orders(), vrprouting::initialsol::tabu::Initial_solution::process_given_solution_from_user(), and vrprouting::initialsol::tabu::Initial_solution::process_unassigned().
|
inherited |
Total waiting time of the solution.
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.
References vrprouting::problem::Solution::m_fleet, and vrprouting::problem::Vehicle::total_wait_time().
Referenced by vrprouting::problem::Solution::get_postgres_result().
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().
|
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().
|
private |
Maximum number of cycles on the optimization process.
Definition at line 87 of file optimizers/tabu.h.
Referenced by tabu_search().
|
protectedinherited |
Definition at line 130 of file solution.h.
Referenced by vrprouting::problem::Solution::msg().
|
private |
Flag to just build a solution and not optimize it.
Definition at line 93 of file optimizers/tabu.h.
Referenced by tabu_search().
|
protectedinherited |
the problem info
Definition at line 128 of file solution.h.
Referenced by vrprouting::initialsol::simple::Initial_solution::do_while_feasible(), and vrprouting::problem::Solution::orders().
|
private |
Limit for a cycle.
Definition at line 96 of file optimizers/tabu.h.
Referenced by set_tabu_list_length().
|
private |
Flag to stop when all orders are in real vehicles.
Definition at line 90 of file optimizers/tabu.h.
Referenced by tabu_search().
|
protectedinherited |
Definition at line 129 of file solution.h.
Referenced by vrprouting::problem::Solution::vehicles().
|
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().
|
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().