[CP-SAT] improve doc on C++ builder API; rewrite python API to remove the DoubleLinearExpr class

This commit is contained in:
Laurent Perron
2021-12-14 17:15:17 +01:00
parent 3bf1f19e0c
commit 0c22a715b2
13 changed files with 428 additions and 433 deletions

View File

@@ -106,7 +106,7 @@ int64_t ComputeHorizon(const JsspInputProblem& problem) {
struct JobTaskData {
IntervalVar interval;
IntVar start;
IntVar duration;
LinearExpr duration;
IntVar end;
};
@@ -488,7 +488,8 @@ void CreateObjective(
for (int a = 0; a < num_alternatives; ++a) {
// Add cost if present.
if (task.cost_size() > 0) {
objective_vars.push_back(job_task_to_alternatives[j][t][a].presence);
objective_vars.push_back(
IntVar(job_task_to_alternatives[j][t][a].presence));
objective_coeffs.push_back(task.cost(a));
}
}
@@ -626,14 +627,13 @@ void AddMakespanRedundantConstraints(
const int num_machines = problem.machines_size();
// Global energetic reasoning.
std::vector<IntVar> all_task_durations;
LinearExpr sum_of_duration;
for (const std::vector<JobTaskData>& tasks : job_to_tasks) {
for (const JobTaskData& task : tasks) {
all_task_durations.push_back(task.duration);
sum_of_duration += task.duration;
}
}
cp_model.AddLessOrEqual(LinearExpr::Sum(all_task_durations),
makespan * num_machines);
cp_model.AddLessOrEqual(sum_of_duration, makespan * num_machines);
}
void DisplayJobStatistics(
@@ -648,8 +648,7 @@ void DisplayJobStatistics(
for (const std::vector<JobTaskData>& job : job_to_tasks) {
num_tasks += job.size();
for (const JobTaskData& task : job) {
if (task.duration.Proto().domain_size() != 2 ||
task.duration.Proto().domain(0) != task.duration.Proto().domain(1)) {
if (!task.duration.IsConstant()) {
num_tasks_with_variable_duration++;
}
}

View File

@@ -578,7 +578,7 @@ class NetworkRoutingSolver {
// Node - Graph Constraint.
for (int demand_index = 0; demand_index < num_demands; ++demand_index) {
for (int arc = 0; arc < num_arcs; ++arc) {
path_vars[demand_index].push_back(cp_model.NewBoolVar());
path_vars[demand_index].push_back(IntVar(cp_model.NewBoolVar()));
}
// Fill Tuple Set for AllowedAssignment constraint.
TableConstraint path_ct =

View File

@@ -262,7 +262,7 @@ void LoadAndSolve(const std::string& file_name) {
}
// Check that we have not already visited this exact set of candidate jobs.
if (gtl::ContainsKey(visited_job_lists, intersecting_jobs)) continue;
if (visited_job_lists.contains(intersecting_jobs)) continue;
visited_job_lists.insert(intersecting_jobs);
// Collect the relevant worker job vars.

View File

@@ -107,14 +107,14 @@ void OpponentModel(int num_teams) {
std::vector<IntVar> day_home_aways;
for (int t = 0; t < num_teams; ++t) {
day_opponents.push_back(opponents[t][d]);
day_home_aways.push_back(home_aways[t][d]);
day_home_aways.push_back(IntVar(home_aways[t][d]));
}
builder.AddInverseConstraint(day_opponents, day_opponents);
for (int first_team = 0; first_team < num_teams; ++first_team) {
IntVar first_home = day_home_aways[first_team];
IntVar second_home = builder.NewBoolVar();
const IntVar first_home = IntVar(day_home_aways[first_team]);
const IntVar second_home = IntVar(builder.NewBoolVar());
builder.AddVariableElement(day_opponents[first_team], day_home_aways,
second_home);
builder.AddEquality(first_home + second_home, 1);