3.9. How does the solver optimize?

The main idea is simple. When you define an objective function, as in tutorials/cplusplus/chap3/golom1.cc:

OptimizeVar* const length = s.MakeMinimize(Y[num_vars - 1], 1);

you basically tell the solver three things:

  1. to minimize the objective function;
  2. the objective function is defined by the variable Y[num_vars - 1] and
  3. the improvement step is 1.

The last instruction ensures that each time the solver finds a feasible solution with a value z, it will attempt to find a better solution with value z-1 and so on until it cannot find a feasible solution with a give value \alpha. The optimal value is thus in this case \alpha + 1.

You can give any (positive) integer value as an improvement step to the solver:

OptimizeVar* const obj = s.MakeMaximize(obj_var, 42);

but beware that by default, there isn’t any smart algorithm implemented in or-tools to change this improvement step during the search. If the solver finds a solution with an objective value of 237, it will try next to find a solution with an objective value of 195[1]. If it finds one, it will try to find another solution with an objective value of 153 but if doesn’t find any feasible solution with a value of 195, it will stop the search and return the “best” solution with a value of 237!

If you use an improvement step of 1, you can be sure to reach an optimal solution if you provide the solver with enough time and memory but you could also devise your own algorithm to change this improvement step during the search.

Footnote

[1]It took us a while but we are pretty sure that 237 - 42 = 195.



























Google or-tools
open source library

User's Manual

Google search

Search:

Welcome

Tutorial examples

Current chapter

3. Using objectives in constraint programming: the Golomb Ruler Problem

Previous section

3.8. How to tighten the model?

Next section

3.10. Summary