正如注释所指出的:实例化RoutingSearchParameters类的正确方法是导入
我无法运行带有路由参数的解决方案,因为该方法不接受默认的RoutingSearchParameters,因为实例为空(每个字段都设置为0(。
以下是我创建实例的方式:
// final var p = RoutingSearchParameters.newBuilder().build(); Both don't work
final var p = RoutingSearchParameters.getDefaultInstance();
final var s = routing.solveWithParameters(p);
以下是错误(每个字段都会发生(:
E0717 20:27:26.682358 6108 routing.cc:1886] Invalid RoutingSearchParameters: Invalid cheapest_insertion_first_solution_neighbors_ratio: 0
有没有什么方法可以在不手动设置每个字段的情况下解决它?
此处显示所有默认参数:
https://github.com/google/or-tools/blob/45770b833997f827d322e929b1ed4781c4e60d44/ortools/constraint_solver/routing_parameters.cc#L45
"first_solution_strategy: AUTOMATIC "
"use_unfiltered_first_solution_strategy: false "
"savings_neighbors_ratio: 1 "
"savings_max_memory_usage_bytes: 6e9 "
"savings_add_reverse_arcs: false "
"savings_arc_coefficient: 1 "
"savings_parallel_routes: false "
"cheapest_insertion_farthest_seeds_ratio: 0 "
"cheapest_insertion_first_solution_neighbors_ratio: 1 "
"cheapest_insertion_ls_operator_neighbors_ratio: 1 "
"local_search_operators {"
" use_relocate: BOOL_TRUE"
" use_relocate_pair: BOOL_TRUE"
" use_light_relocate_pair: BOOL_TRUE"
" use_relocate_subtrip: BOOL_TRUE"
" use_relocate_neighbors: BOOL_FALSE"
" use_exchange: BOOL_TRUE"
" use_exchange_pair: BOOL_TRUE"
" use_exchange_subtrip: BOOL_TRUE"
" use_cross: BOOL_TRUE"
" use_cross_exchange: BOOL_FALSE"
" use_relocate_expensive_chain: BOOL_TRUE"
" use_two_opt: BOOL_TRUE"
" use_or_opt: BOOL_TRUE"
" use_lin_kernighan: BOOL_TRUE"
" use_tsp_opt: BOOL_FALSE"
" use_make_active: BOOL_TRUE"
" use_relocate_and_make_active: BOOL_FALSE" // costly if true by default
" use_make_inactive: BOOL_TRUE"
" use_make_chain_inactive: BOOL_FALSE"
" use_swap_active: BOOL_TRUE"
" use_extended_swap_active: BOOL_FALSE"
" use_node_pair_swap_active: BOOL_TRUE"
" use_path_lns: BOOL_FALSE"
" use_full_path_lns: BOOL_FALSE"
" use_tsp_lns: BOOL_FALSE"
" use_inactive_lns: BOOL_FALSE"
" use_global_cheapest_insertion_path_lns: BOOL_TRUE"
" use_local_cheapest_insertion_path_lns: BOOL_TRUE"
" use_global_cheapest_insertion_expensive_chain_lns: BOOL_FALSE"
" use_local_cheapest_insertion_expensive_chain_lns: BOOL_FALSE"
"}"
"relocate_expensive_chain_num_arcs_to_consider: 4 "
"heuristic_expensive_chain_lns_num_arcs_to_consider: 4 "
"local_search_metaheuristic: AUTOMATIC "
"guided_local_search_lambda_coefficient: 0.1 "
"use_depth_first_search: false "
"use_cp: BOOL_TRUE "
"use_cp_sat: BOOL_FALSE "
"continuous_scheduling_solver: GLOP "
"mixed_integer_scheduling_solver: CP_SAT "
"optimization_step: 0.0 "
"number_of_solutions_to_collect: 1 "
// No "time_limit" by default.
"solution_limit: 0x7fffffffffffffff " // kint64max
"lns_time_limit: { seconds:0 nanos:100000000 } " // 0.1s
"use_full_propagation: false "
"log_search: false "
"log_cost_scaling_factor: 1.0 "
"log_cost_offset: 0.0";
com.google.ortools.constraintsolver.main
,然后使用方法main.defaultRoutingSearchParameters()
。