8

I'm trying to write this constraint in C++ and add it to my model (addLessOrEqual): $$\text{start}_{i}+\text{duration}_{i}\le\text{start}_{j}$$ for an $(i,j)$ arc of precedence.

Starts (IntVar) and durations (int) are part of an IntervalVar. The problem is that I can't operate $+$ with IntVar and Int.

I'm using C++ and i get this error:

    error: no match for ‘operator+’ (operand types are 
‘__gnu_cxx::__alloc_traits<std::allocator<operations_research::sat::IntVar> 
>::value_type {aka operations_research::sat::IntVar}’ and 
‘__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}’)
                 cp_model.AddLessOrEqual(starts[j]+durations[j],starts[succ[j][s]])

What can I do to sum and get the expression? Is there another predefined constraint that does the same? Thanks!

1 Answers1

8

What you want is:

AddLessOrEqual(LinearExpr(starts[j]).AddConstant(durations[j]), starts[succ[j][s]])

You might also want to take a look at the examples (ending with _sat.cc) to be more familiar with the c++ methods.

https://github.com/google/or-tools/tree/master/examples/cpp

Stradivari
  • 1,414
  • 6
  • 14