Skip to content

Commit

Permalink
[CP-SAT] more span; minor scheduling optims
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Aug 2, 2024
1 parent 9feaef9 commit d34ddd6
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 194 deletions.
2 changes: 2 additions & 0 deletions ortools/sat/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,12 @@ cc_library(
"//ortools/util:strong_integers",
"//ortools/util:time_limit",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/meta:type_traits",
"@com_google_absl//absl/random:distributions",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:span",
],
)
Expand Down
17 changes: 8 additions & 9 deletions ortools/sat/cp_model_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/random/distributions.h"
#include "absl/strings/str_cat.h"
Expand All @@ -43,10 +42,6 @@
#include "ortools/sat/util.h"
#include "ortools/util/strong_integers.h"

// TODO(user): remove this when the code is stable and does not use SCIP
// anymore.
ABSL_FLAG(bool, cp_model_use_max_hs, false, "Use max_hs in search portfolio.");

namespace operations_research {
namespace sat {

Expand Down Expand Up @@ -649,6 +644,14 @@ absl::flat_hash_map<std::string, SatParameters> GetNamedParameters(
new_params.set_use_dynamic_precedence_in_disjunctive(false);
new_params.set_use_dynamic_precedence_in_cumulative(false);
strategies["fixed"] = new_params;

new_params.set_linearization_level(0);
strategies["fixed_no_lp"] = new_params;

new_params.set_linearization_level(2);
new_params.set_add_lp_constraints_lazily(false);
new_params.set_root_lp_iterations(100'000);
strategies["fixed_max_lp"] = new_params;
}

// Quick restart.
Expand Down Expand Up @@ -803,10 +806,6 @@ std::vector<SatParameters> GetFullWorkerParameters(
names.push_back("probing_no_lp");
names.push_back("objective_lb_search_no_lp");
names.push_back("objective_lb_search_max_lp");

#if !defined(__PORTABLE_PLATFORM__) && defined(USE_SCIP)
if (absl::GetFlag(FLAGS_cp_model_use_max_hs)) names.push_back("max_hs");
#endif // !defined(__PORTABLE_PLATFORM__) && defined(USE_SCIP)
} else {
for (const std::string& name : base_params.subsolvers()) {
// Hack for flatzinc. At the time of parameter setting, the objective is
Expand Down
6 changes: 3 additions & 3 deletions ortools/sat/cp_model_symmetries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ void OrbitAndPropagation(absl::Span<const int> orbits, int var,
}

std::vector<int64_t> BuildInequalityCoeffsForOrbitope(
const std::vector<int64_t>& maximum_values, int64_t max_linear_size,
absl::Span<const int64_t> maximum_values, int64_t max_linear_size,
bool* is_approximated) {
std::vector<int64_t> out(maximum_values.size());
int64_t range_product = 1;
Expand All @@ -872,8 +872,8 @@ std::vector<int64_t> BuildInequalityCoeffsForOrbitope(
*is_approximated = true;

const auto compute_approximate_coeffs =
[max_linear_size, &maximum_values](double scaling_factor,
std::vector<int64_t>* coeffs) -> bool {
[max_linear_size, maximum_values](double scaling_factor,
std::vector<int64_t>* coeffs) -> bool {
int64_t max_size = 0;
double cumulative_product_double = 1.0;
for (int i = 0; i < maximum_values.size(); ++i) {
Expand Down
4 changes: 2 additions & 2 deletions ortools/sat/diffn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ bool NonOverlappingRectanglesDisjunctivePropagator::
// Compute relevant boxes, the one with a mandatory part of y. Because we will
// need to sort it this way, we consider them by increasing start max.
indexed_boxes_.clear();
const auto temp = y->TaskByDecreasingStartMax();
const auto temp = y->TaskByIncreasingNegatedStartMax();
for (int i = temp.size(); --i >= 0;) {
const int box = temp[i].task_index;
// Ignore absent boxes.
Expand All @@ -718,7 +718,7 @@ bool NonOverlappingRectanglesDisjunctivePropagator::
continue;
}

const IntegerValue start_max = temp[i].time;
const IntegerValue start_max = -temp[i].time;
const IntegerValue end_min = y->EndMin(box);
if (start_max < end_min) {
indexed_boxes_.push_back({box, start_max, end_min});
Expand Down
Loading

0 comments on commit d34ddd6

Please sign in to comment.