[CP-SAT] improve doc on C++ builder API; rewrite python API to remove the DoubleLinearExpr class
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user