19 #include "absl/status/status.h"
20 #include "absl/time/time.h"
32 "Routing: forbids use of Large Neighborhood Search.");
34 "Routing: forbids use of Full-path Large Neighborhood Search.");
36 "Routing: forbids use of Relocate neighborhood.");
38 "Routing: forbids use of RelocateNeighbors neighborhood.");
40 "Routing: forbids use of RelocateSubtrips neighborhood.");
42 "Routing: forbids use of Exchange neighborhood.");
44 "Routing: forbids use of ExchangeSubtrips neighborhood.");
46 "Routing: forbids use of Cross neighborhood.");
48 "Routing: forbids use of 2Opt neighborhood.");
50 "Routing: forbids use of OrOpt neighborhood.");
52 "Routing: forbids use of MakeActive/SwapActive/MakeInactive "
54 DEFINE_bool(routing_no_lkh,
false,
"Routing: forbids use of LKH neighborhood.");
56 "Routing: forbids use of RelocateExpensiveChain operator.");
58 "Routing: forbids use of TSPOpt neighborhood.");
60 "Routing: forbids use of TSPLNS neighborhood.");
62 "Routing: use chain version of MakeInactive neighborhood.");
64 "Routing: use extended version of SwapActive neighborhood.");
67 DEFINE_bool(routing_guided_local_search,
false,
"Routing: use GLS.");
69 "Lambda coefficient in GLS.");
71 "Routing: use simulated annealing.");
72 DEFINE_bool(routing_tabu_search,
false,
"Routing: use tabu search.");
74 "Routing: use tabu search based on a list of values.");
78 "Routing: number of solutions limit.");
81 "Routing: time limit in ms for LNS sub-decisionbuilder.");
85 "Routing first solution heuristic. See SetupParametersFromFlags "
86 "in the code to get a full list.");
88 "Use filtered version of first solution heuristics if available.");
90 "Ratio of neighbors to consider for each node when "
91 "constructing the savings.");
93 "Add savings related to reverse arcs when finding the nearest "
94 "neighbors of the nodes.");
96 "Coefficient of the cost of the arc for which the saving value "
97 "is being computed.");
99 "Ratio of available vehicles in the model on which farthest "
100 "nodes of the model are inserted as seeds.");
102 "Ratio of nodes considered as neighbors in the "
103 "GlobalCheapestInsertion first solution heuristic.");
104 DEFINE_bool(routing_dfs,
false,
"Routing: use a complete depth-first search.");
107 "Number of solutions to collect.");
109 "Number of arcs to consider in the RelocateExpensiveChain "
110 "neighborhood operator.");
114 "Use constraints with light propagation in routing model.");
117 DEFINE_bool(routing_cache_callbacks,
false,
"Cache callback calls.");
119 "Maximum cache size when callback caching is on.");
127 "Routing: use homogeneous cost model when possible.");
129 "Use gzip to compress the trail, zippy otherwise.");
135 const std::map<std::string, FirstSolutionStrategy::Value>
136 first_solution_string_to_parameters = {
137 {
"PathCheapestArc", FirstSolutionStrategy::PATH_CHEAPEST_ARC},
138 {
"PathMostConstrainedArc",
139 FirstSolutionStrategy::PATH_MOST_CONSTRAINED_ARC},
140 {
"EvaluatorStrategy", FirstSolutionStrategy::EVALUATOR_STRATEGY},
141 {
"Savings", FirstSolutionStrategy::SAVINGS},
142 {
"Sweep", FirstSolutionStrategy::SWEEP},
143 {
"Christofides", FirstSolutionStrategy::CHRISTOFIDES},
144 {
"AllUnperformed", FirstSolutionStrategy::ALL_UNPERFORMED},
145 {
"BestInsertion", FirstSolutionStrategy::BEST_INSERTION},
146 {
"GlobalCheapestInsertion",
147 FirstSolutionStrategy::PARALLEL_CHEAPEST_INSERTION},
148 {
"SequentialGlobalCheapestInsertion",
149 FirstSolutionStrategy::SEQUENTIAL_CHEAPEST_INSERTION},
150 {
"LocalCheapestInsertion",
151 FirstSolutionStrategy::LOCAL_CHEAPEST_INSERTION},
152 {
"GlobalCheapestArc", FirstSolutionStrategy::GLOBAL_CHEAPEST_ARC},
153 {
"LocalCheapestArc", FirstSolutionStrategy::LOCAL_CHEAPEST_ARC},
154 {
"DefaultStrategy", FirstSolutionStrategy::FIRST_UNBOUND_MIN_VALUE},
155 {
"", FirstSolutionStrategy::FIRST_UNBOUND_MIN_VALUE}};
158 FLAGS_routing_first_solution, &strategy)) {
159 parameters->set_first_solution_strategy(strategy);
161 parameters->set_use_unfiltered_first_solution_strategy(
162 !FLAGS_routing_use_filtered_first_solutions);
163 parameters->set_savings_neighbors_ratio(FLAGS_savings_neighbors_ratio);
164 parameters->set_savings_max_memory_usage_bytes(6e9);
165 parameters->set_savings_add_reverse_arcs(FLAGS_savings_add_reverse_arcs);
166 parameters->set_savings_arc_coefficient(FLAGS_savings_arc_coefficient);
167 parameters->set_cheapest_insertion_farthest_seeds_ratio(
168 FLAGS_cheapest_insertion_farthest_seeds_ratio);
169 parameters->set_cheapest_insertion_first_solution_neighbors_ratio(
170 FLAGS_cheapest_insertion_first_solution_neighbors_ratio);
175 if (FLAGS_routing_tabu_search) {
177 LocalSearchMetaheuristic::TABU_SEARCH);
178 }
else if (FLAGS_routing_generic_tabu_search) {
180 LocalSearchMetaheuristic::GENERIC_TABU_SEARCH);
181 }
else if (FLAGS_routing_simulated_annealing) {
183 LocalSearchMetaheuristic::SIMULATED_ANNEALING);
184 }
else if (FLAGS_routing_guided_local_search) {
186 LocalSearchMetaheuristic::GUIDED_LOCAL_SEARCH);
188 parameters->set_guided_local_search_lambda_coefficient(
189 FLAGS_routing_guided_local_search_lambda_coefficient);
199 parameters->set_cheapest_insertion_ls_operator_neighbors_ratio(1.0);
200 RoutingSearchParameters::LocalSearchNeighborhoodOperators*
const
201 local_search_operators =
parameters->mutable_local_search_operators();
205 local_search_operators->set_use_relocate_pair(
BOOL_TRUE);
206 local_search_operators->set_use_light_relocate_pair(
BOOL_TRUE);
207 local_search_operators->set_use_exchange_pair(
BOOL_TRUE);
208 local_search_operators->set_use_relocate_and_make_active(
BOOL_FALSE);
209 local_search_operators->set_use_node_pair_swap_active(
BOOL_FALSE);
210 local_search_operators->set_use_cross_exchange(
BOOL_FALSE);
211 local_search_operators->set_use_global_cheapest_insertion_path_lns(
BOOL_TRUE);
212 local_search_operators->set_use_local_cheapest_insertion_path_lns(
BOOL_TRUE);
213 local_search_operators->set_use_global_cheapest_insertion_expensive_chain_lns(
215 local_search_operators->set_use_local_cheapest_insertion_expensive_chain_lns(
217 local_search_operators->set_use_global_cheapest_insertion_close_nodes_lns(
219 local_search_operators->set_use_local_cheapest_insertion_close_nodes_lns(
222 local_search_operators->set_use_relocate(
223 ToOptionalBoolean(!FLAGS_routing_no_relocate));
224 local_search_operators->set_use_relocate_neighbors(
225 ToOptionalBoolean(!FLAGS_routing_no_relocate_neighbors));
226 local_search_operators->set_use_relocate_subtrip(
227 ToOptionalBoolean(!FLAGS_routing_no_relocate_subtrip));
228 local_search_operators->set_use_exchange_subtrip(
229 ToOptionalBoolean(!FLAGS_routing_no_exchange_subtrip));
230 local_search_operators->set_use_exchange(
231 ToOptionalBoolean(!FLAGS_routing_no_exchange));
232 local_search_operators->set_use_cross(
233 ToOptionalBoolean(!FLAGS_routing_no_cross));
234 local_search_operators->set_use_two_opt(
235 ToOptionalBoolean(!FLAGS_routing_no_2opt));
236 local_search_operators->set_use_or_opt(
237 ToOptionalBoolean(!FLAGS_routing_no_oropt));
238 local_search_operators->set_use_lin_kernighan(
239 ToOptionalBoolean(!FLAGS_routing_no_lkh));
240 local_search_operators->set_use_relocate_expensive_chain(
241 ToOptionalBoolean(!FLAGS_routing_no_relocate_expensive_chain));
242 local_search_operators->set_use_tsp_opt(
243 ToOptionalBoolean(!FLAGS_routing_no_tsp));
244 local_search_operators->set_use_make_active(
245 ToOptionalBoolean(!FLAGS_routing_no_make_active));
246 local_search_operators->set_use_make_inactive(ToOptionalBoolean(
247 !FLAGS_routing_use_chain_make_inactive && !FLAGS_routing_no_make_active));
248 local_search_operators->set_use_make_chain_inactive(ToOptionalBoolean(
249 FLAGS_routing_use_chain_make_inactive && !FLAGS_routing_no_make_active));
250 local_search_operators->set_use_swap_active(
251 ToOptionalBoolean(!FLAGS_routing_use_extended_swap_active &&
252 !FLAGS_routing_no_make_active));
253 local_search_operators->set_use_extended_swap_active(ToOptionalBoolean(
254 FLAGS_routing_use_extended_swap_active && !FLAGS_routing_no_make_active));
255 local_search_operators->set_use_path_lns(
256 ToOptionalBoolean(!FLAGS_routing_no_lns));
257 local_search_operators->set_use_inactive_lns(
258 ToOptionalBoolean(!FLAGS_routing_no_lns));
259 local_search_operators->set_use_full_path_lns(
260 ToOptionalBoolean(!FLAGS_routing_no_fullpathlns));
261 local_search_operators->set_use_tsp_lns(
262 ToOptionalBoolean(!FLAGS_routing_no_tsplns));
267 parameters->set_use_depth_first_search(FLAGS_routing_dfs);
270 parameters->set_optimization_step(FLAGS_routing_optimization_step);
271 parameters->set_number_of_solutions_to_collect(
272 FLAGS_routing_number_of_solutions_to_collect);
273 parameters->set_solution_limit(FLAGS_routing_solution_limit);
274 if (FLAGS_routing_time_limit !=
kint64max) {
276 absl::Milliseconds(FLAGS_routing_time_limit),
279 if (FLAGS_routing_lns_time_limit !=
kint64max) {
281 absl::Milliseconds(FLAGS_routing_lns_time_limit),
288 parameters->set_use_full_propagation(!FLAGS_routing_use_light_propagation);
289 parameters->set_log_search(FLAGS_routing_trace);
291 parameters->set_relocate_expensive_chain_num_arcs_to_consider(
292 FLAGS_routing_relocate_expensive_chain_num_arcs_to_consider);
293 parameters->set_heuristic_expensive_chain_lns_num_arcs_to_consider(4);
294 parameters->set_heuristic_close_nodes_lns_num_nodes(5);
295 parameters->set_continuous_scheduling_solver(RoutingSearchParameters::GLOP);
296 parameters->set_mixed_integer_scheduling_solver(
297 RoutingSearchParameters::CP_SAT);
308 LOG_IF(DFATAL, !error.empty())
309 <<
"Error in the routing search parameters built from flags: " << error;
315 ConstraintSolverParameters*
const solver_parameters =
317 *solver_parameters = Solver::DefaultSolverParameters();
318 parameters.set_reduce_vehicle_cost_model(FLAGS_routing_use_homogeneous_costs);
319 if (FLAGS_routing_cache_callbacks) {
320 parameters.set_max_callback_cache_size(FLAGS_routing_max_cache_size);
322 solver_parameters->set_profile_local_search(FLAGS_routing_profile);