From bd51fa48c4c65dbd0054bb34e940fd8703150981 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Sun, 12 Dec 2021 08:11:11 +0100 Subject: [PATCH] implement #2699 --- examples/cpp/jobshop_sat.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/cpp/jobshop_sat.cc b/examples/cpp/jobshop_sat.cc index 567e0aaf4f..64e1716a39 100644 --- a/examples/cpp/jobshop_sat.cc +++ b/examples/cpp/jobshop_sat.cc @@ -383,6 +383,12 @@ void CreateMachines( // Create circuit constraint on a machine. Node 0 is both the source and // sink, i.e. the first and last job. CircuitConstraint circuit = cp_model.AddCircuitConstraint(); + + // If all intervals are optional, a solution without any performed + // interval in this resource requires an empty circuit. + BoolVar empty_circuit = cp_model.NewBoolVar(); + circuit.AddArc(0, 0, empty_circuit); + for (int i = 0; i < num_intervals; ++i) { const int job_i = machine_to_tasks[m][i].job; const MachineTaskData& tail = machine_to_tasks[m][i]; @@ -395,6 +401,10 @@ void CreateMachines( // Node to sink. circuit.AddArc(i + 1, 0, cp_model.NewBoolVar()); + // If the circuit is empty, the interval cannot be performed. + cp_model.AddImplication(empty_circuit, + Not(tail.interval.PresenceBoolVar())); + // Used to constrain the size of the tail interval. std::vector literals; std::vector transitions;