I'm using OptionalIntervalVar
and then maximizing the starts. The optimal solution is not affecting the other variables that creates the OptionalIntervalVar
(i mean the constraint starts[j]+sizes[j]==ends[j]
), so I suppose that there are not enforced, but my CpModelStats
says that there are all enforced, so why they are not working?
This is how I create the IntervalVars
:
std::vector<IntVar> starts;
std::vector<IntVar> sizes;
std::vector<IntVar> ends;
std::vector<BoolVar> actives;
std::vector<IntervalVar> Intervals;
for (int j=0; j<nbTasks; j++)
{
const IntVar start = cp_model.NewIntVar(Domain(0, tmax)); // generamos una variable intervalo
const IntVar end = cp_model.NewIntVar(Domain(0, tmax)); // para cada job
const BoolVar active = cp_model.NewBoolVar();
const IntVar size = cp_model.NewConstant(duration[j]);
//const IntervalVar interval = cp_model.NewIntervalVar(start, size, end); // start+size==end
const IntervalVar interval = cp_model.NewOptionalIntervalVar(start, size, end, active);
starts.push_back(start);
sizes.push_back(size);
ends.push_back(end);
actives.push_back(active);
Intervals.push_back(interval);
}
And the CpModelStatus:
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0130 12:29:51.027925 23261 cp_rcpsp.cpp:1028] CpSolverResponse:
status: OPTIMAL
objective: 119978
best_bound: 119978
booleans: 18
conflicts: 0
branches: 26
propagations: 4
integer_propagations: 44
walltime: 0.00252666
usertime: 0.00252667
deterministic_time: 2.44e-06
primal_integral: 0.29268
I0130 12:29:51.030489 23261 cp_rcpsp.cpp:1029] Optimization model '':
#Variables: 30 (6 in objective)
- 6 in [0,1]
- 12 in [0,20000]
- 12 constants in {0,1,2,3,20,6000,8000,8187,10000,19113,33641,50000}
#kCumulative: 2
#kInterval: 6 (#enforced: 6)
#kLinear1: 13
#kLinear2: 7
And this is my objective:
cp_model.Maximize(LinearExpr::Sum(starts));
active = cp_model.TrueVar()
instead ofactive = cp_model.NewBoolVar()
$\endgroup$TrueVar()
so the model can choose if a job is present or not and at maximizing the starts the interval constraint works for all the other variables. $\endgroup$active
enforcement literal properly $\endgroup$