Skip to content
Advertisement

OR-Tools MIP Solver – Defining an objective in terms of int, instead of IntVar

I am trying to define an objective function which uses the current value of a variable, as an integer, for computation (as shown below):

JavaScript

where x0, x1, x2 are IntVars.

In my use case, the function foo is defined in a way that it requires int arguments.

When I try and maximize objective_that_does_not_work, it randomly gives me either the upper bound or the lower bound for each of x0, x1, x2 (different values each time I run the solver).

My questions:

  1. Is it possible to define the objective in terms of the value of the IntVar, instead of the IntVar itself?

  2. If yes, is solution_value() the right attribute to be using? From the documentation, it seemed the most appropriate, but I may be misinterpreting its use.

Thank you

Advertisement

Answer

You can only express the objective as a linear combination of variables.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement