Search code examples
c#or-tools

How to implement SUM operation in Google OR-Tools for C#


I would like to know how can I implement a SUM operation in C# using OR-Tools. In my problem, I have the following constraint:

Constraint

NOTE: My problem is a Linear Programming Problem.


Solution

  • You can use arithmetic operators:

    model.Add(4 * r + 2 * p == 56);
    

    or

    model.Add(LinearExpr.Sum(new IntVar[] {r, p}) == 20);
    

    See: https://github.com/google/or-tools/blob/master/ortools/sat/docs/integer_arithmetic.md