# Precedence Constraint in OR-Tools

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}’)


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

• I'm not familiar with or-tools but have you tried bringing all of your expression to the left-hand side and your value to the right-hand side and see if the error goes away? – EhsanK Jan 20 '20 at 15:12
• I did this but now the problem is with the operator. – Diego R. Troncoso Jan 20 '20 at 15:25
• AddLessOrEqual(LinearExpr(starts[j]).AddConstant(durations[j]), starts[succ[j][s]]) – Stradivari Jan 20 '20 at 15:28
• thanks Stradivari, apparently it works! – Diego R. Troncoso Jan 20 '20 at 15:32

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.