diff --git a/ortools/routing/lp_scheduling.h b/ortools/routing/lp_scheduling.h index 7176298e08..7e84b1eb4f 100644 --- a/ortools/routing/lp_scheduling.h +++ b/ortools/routing/lp_scheduling.h @@ -456,6 +456,9 @@ class RoutingCPSatWrapper : public RoutingLinearSolverWrapper { // significantly faster than both full presolve and no presolve. parameters_.set_cp_model_presolve(true); parameters_.set_max_presolve_iterations(1); + parameters_.set_cp_model_probing_level(0); + parameters_.set_use_sat_inprocessing(false); + parameters_.set_symmetry_level(0); parameters_.set_catch_sigint_signal(false); parameters_.set_mip_max_bound(1e8); parameters_.set_search_branching(sat::SatParameters::LP_SEARCH); diff --git a/ortools/routing/routing.cc b/ortools/routing/routing.cc index 36a04e11e3..bb0807493e 100644 --- a/ortools/routing/routing.cc +++ b/ortools/routing/routing.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -4770,10 +4771,13 @@ void RoutingModel::CreateNeighborhoodOperators( CreateCPOperator(); std::vector> alternative_sets(disjunctions_.size()); for (const RoutingModel::Disjunction& disjunction : disjunctions_) { - // Only add disjunctions of cardinality 1, as + // Only add disjunctions of cardinality 1 and of size > 1, as // SwapActiveToShortestPathOperator and TwoOptWithShortestPathOperator only - // support DAGs. - if (disjunction.value.max_cardinality == 1) { + // support DAGs, and don't care about chain-DAGS. + // TODO(user): Optimize TwoOptWithShortestPathOperator to skip DAG-less + // chains. + if (disjunction.value.max_cardinality == 1 && + disjunction.indices.size() > 1) { alternative_sets.push_back(disjunction.indices); } } @@ -4992,6 +4996,11 @@ LocalSearchOperator* RoutingModel::GetNeighborhoodOperators( CP_ROUTING_PUSH_OPERATOR(TWO_OPT, two_opt); CP_ROUTING_PUSH_OPERATOR(OR_OPT, or_opt); CP_ROUTING_PUSH_OPERATOR(RELOCATE_EXPENSIVE_CHAIN, relocate_expensive_chain); + size_t max_alternative_set_size = 0; + for (const RoutingModel::Disjunction& disjunction : disjunctions_) { + max_alternative_set_size = + std::max(max_alternative_set_size, disjunction.indices.size()); + } if (!disjunctions_.empty()) { CP_ROUTING_PUSH_OPERATOR(MAKE_INACTIVE, make_inactive); CP_ROUTING_PUSH_OPERATOR(MAKE_CHAIN_INACTIVE, make_chain_inactive); @@ -5007,9 +5016,11 @@ LocalSearchOperator* RoutingModel::GetNeighborhoodOperators( CP_ROUTING_PUSH_OPERATOR(SWAP_ACTIVE, swap_active); CP_ROUTING_PUSH_OPERATOR(SWAP_ACTIVE_CHAIN, swap_active_chain); CP_ROUTING_PUSH_OPERATOR(EXTENDED_SWAP_ACTIVE, extended_swap_active); - CP_ROUTING_PUSH_OPERATOR(SHORTEST_PATH_SWAP_ACTIVE, - shortest_path_swap_active); - CP_ROUTING_PUSH_OPERATOR(SHORTEST_PATH_TWO_OPT, shortest_path_two_opt); + if (max_alternative_set_size > 1) { + CP_ROUTING_PUSH_OPERATOR(SHORTEST_PATH_SWAP_ACTIVE, + shortest_path_swap_active); + CP_ROUTING_PUSH_OPERATOR(SHORTEST_PATH_TWO_OPT, shortest_path_two_opt); + } } LocalSearchOperator* main_operator_group = ConcatenateOperators(search_parameters, operators);