Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add the horizontal elastic timetable overload checking rule to the cumulative constraint. #4401

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions ortools/sat/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,21 @@ cc_library(
],
)

cc_library(
name = "timetable_horizontal_edgefinding",
srcs = ["timetable_horizontal_edgefinding.cc"],
hdrs = ["timetable_horizontal_edgefinding.h"],
deps = [
":integer",
":intervals",
":model",
":sat_base",
"//ortools/base:iterator_adaptors",
"//ortools/util:strong_integers",
"@com_google_absl//absl/log:check",
],
)

cc_library(
name = "cumulative",
srcs = ["cumulative.cc"],
Expand All @@ -1898,6 +1913,7 @@ cc_library(
":sat_solver",
":timetable",
":timetable_edgefinding",
":timetable_horizontal_edgefinding",
"//ortools/base",
"//ortools/util:strong_integers",
"@com_google_absl//absl/log:check",
Expand Down
12 changes: 12 additions & 0 deletions ortools/sat/cumulative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "ortools/sat/sat_solver.h"
#include "ortools/sat/timetable.h"
#include "ortools/sat/timetable_edgefinding.h"
#include "ortools/sat/timetable_horizontal_edgefinding.h"
#include "ortools/util/strong_integers.h"

namespace operations_research {
Expand Down Expand Up @@ -244,6 +245,17 @@ std::function<void(Model*)> Cumulative(
time_tabling->RegisterWith(watcher);
model->TakeOwnership(time_tabling);

// Propagator responsible for applying the Horizontal Elastic Overload
// Checking rule. The propogator simply takes care of detecting conflicts
// without actually modifying the domain of the variables.
if (parameters.use_horizontal_overload_checking_in_cumulative()) {
HorizontallyElasticOverloadChecker* heoc =
new HorizontallyElasticOverloadChecker(capacity, helper,
demands_helper, model);
heoc->RegisterWith(watcher);
model->TakeOwnership(heoc);
}

// Propagator responsible for applying the Overload Checking filtering rule.
// It increases the minimum of the capacity variable.
if (parameters.use_overload_checker_in_cumulative()) {
Expand Down
15 changes: 10 additions & 5 deletions ortools/sat/cumulative_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ TEST(CumulativeTest, RegressionTest2) {
// ========================================================================

// Param1: Number of tasks.
// Param3: Enable overload checking.
// Param4: Enable timetable edge finding.
typedef ::testing::tuple<int, bool, bool> CumulativeTestParams;
// Param2: Enable overload checking.
// Param3: Enable timetable edge finding.
// Param4: Enable horizontal elastic overload checking.
typedef ::testing::tuple<int, bool, bool, bool> CumulativeTestParams;

class RandomCumulativeTest
: public ::testing::TestWithParam<CumulativeTestParams> {
Expand All @@ -369,6 +370,8 @@ class RandomCumulativeTest
::testing::get<1>(GetParam()));
parameters.set_use_timetable_edge_finding_in_cumulative(
::testing::get<2>(GetParam()));
parameters.set_use_horizontal_overload_checking_in_cumulative(
::testing::get<3>(GetParam()));
return parameters;
}
};
Expand Down Expand Up @@ -409,12 +412,14 @@ TEST_P(SlowRandomCumulativeTest, FindAllOptionalTasks) {
INSTANTIATE_TEST_SUITE_P(
All, FastRandomCumulativeTest,
::testing::Combine(::testing::Range(3, DEBUG_MODE ? 4 : 6),
::testing::Bool(), ::testing::Bool()));
::testing::Bool(), ::testing::Bool(),
::testing::Bool()));

INSTANTIATE_TEST_SUITE_P(
All, SlowRandomCumulativeTest,
::testing::Combine(::testing::Range(3, DEBUG_MODE ? 4 : 5),
::testing::Bool(), ::testing::Bool()));
::testing::Bool(), ::testing::Bool(),
::testing::Bool()));

} // namespace
} // namespace sat
Expand Down
10 changes: 9 additions & 1 deletion ortools/sat/sat_parameters.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ option java_multiple_files = true;
// Contains the definitions for all the sat algorithm parameters and their
// default values.
//
// NEXT TAG: 300
// NEXT TAG: 301
message SatParameters {
// In some context, like in a portfolio of search, it makes sense to name a
// given parameters set for logging purpose.
Expand Down Expand Up @@ -812,6 +812,14 @@ message SatParameters {
// depending on the problem, turning this off may lead to a faster solution.
optional bool use_overload_checker_in_cumulative = 78 [default = false];

// When this is true, the cumulative constraint is reinforced with horizontal
// elastic overload checking, i.e., an additional level of reasoning based on
// horizontal elasticity and energy. This additional level supplements the
// default level of reasoning as well as timetable edge finding.
//
// This propagator is experimental.
optional bool use_horizontal_overload_checking_in_cumulative = 300 [default = false];

// Enable a heuristic to solve cumulative constraints using a modified energy
// constraint. We modify the usual energy definition by applying a
// super-additive function (also called "conservative scale" or "dual-feasible
Expand Down
Loading