# OptionalIntervalVar enforced but not working OR-TOOLS

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;

{
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));


Thanks!

• Not sure that means that it was enforced, can you try forcing it? active = cp_model.TrueVar() instead of active = cp_model.NewBoolVar() – Stradivari Jan 30 '20 at 16:02
• It problably just means how many of your intervals were optional – Stradivari Jan 30 '20 at 16:35
• Thanks for your answer. I did that and the constraint start+size==end works. How can avoid the 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. – Diego R. Troncoso Jan 30 '20 at 16:37
• I guess the problem is that you are not constraining the active enforcement literal properly – Stradivari Jan 30 '20 at 16:41