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

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:



  • $\begingroup$ Not sure that means that it was enforced, can you try forcing it? active = cp_model.TrueVar() instead of active = cp_model.NewBoolVar() $\endgroup$ – Stradivari Jan 30 '20 at 16:02
  • 1
    $\begingroup$ It problably just means how many of your intervals were optional $\endgroup$ – Stradivari Jan 30 '20 at 16:35
  • $\begingroup$ 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. $\endgroup$ – Diego R. Troncoso Jan 30 '20 at 16:37
  • $\begingroup$ I guess the problem is that you are not constraining the active enforcement literal properly $\endgroup$ – Stradivari Jan 30 '20 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.