I wanted to expand the job shop problem for the CP-Sat Solver by adding optional tasks,that don’t have to be executed. But my problem is that I don’t really know how “remove” a task from the model if a BoolVar is true.
I added a boolean optional
to the class Task
and a BoolVar active
to the class TaskType
public class Task {
int machine;
int[] duration;
String name;
boolean optional;
Task(int machine, int[] duration, String name, boolean optional) {
this.machine = machine;
this.duration = duration;
this.name = name;
this.optional = optional;
}
}
public class TaskType {
IntVar start;
IntVar end;
IntervalVar interval;
BoolVar active;
}
My first idea was that if taskType.active == false
, then I don’t add the taskType to the allTasks list, so it isn’t considered by the model as a task that needs to be executed. But to my understanding, there is no way to compare a BoolVar because it’s state is technically undefined (if you know what I mean?)
In the part where we create the taskTypes in the link above, (a part of) my code looks as follows:
if(task.optional) {
taskType.active = model.newBoolVar(task.name + "_activeStatus");
}
taskType.interval = model.newIntervalVar(
taskType.start,
model.newIntVar(task.duration[0], task.duration[1], task.name + "_duration"),
taskType.end,
"interval" + suffix);
task.duration
is an int array, which has the minimum duration in duration[0]
and the maximum duration in duration[1]
.
At this point I honestly don’t know how to proceed. I thought about setting the duration of taskType.duration
to zero if taskType.active == true
, maybe by using onlyEnforceIf()
, so that it doesn’t effect the final duration of all tasks, and then filter the tasks out in the output. But then again, I haven’t found a way to use onlyEnforceIf()
this way.
My problem essentially is that I want to make the taskType “irrelevant” if its BoolVar active
is true, maybe by changing an existing IntVars bounds (but I also haven’t found out if that is even possible).
Maybe some of you have a hint for me, thanks in advance.