1

I have to find the set of integers that minimize this objective function:

enter image description here

The costraints are:

  • every x must be a non-negative integer
  • enter image description here

T, A and B are double known numbers.

I have been looking at the OR-Tools C++ library in order to solve this problem, specifically at the CP-SAT solver.

  • Is it the right tool from such problems?
  • If yes, would it be feasible to convert all the double to int in the objective function?
  • If not, what else do you suggest? (I'm also open to other open source C++ libraries)
AathakA
  • 117
  • 7

1 Answers1

1

It will fit in the CP-SAT solver. You will need to scale floating point coefficients to integers.

The objective function accepts floating point coefficients. But (x1 + A1)^2 will propagate better if you keep it that way instead of A1^2 + 2 * A1 * x1 + x1^2. which fits into the linear with double coefficient limitation of CP-SAT, provided you use temporary variables sx1 = x1 * x1.

Then make sure to use at least 8 workers for that. (parameters num_search_workers:8).

Now, I believe there are least square solvers that are more suited for this.

Laurent Perron
  • 8,594
  • 1
  • 8
  • 22
  • Are you sure I can work with decimals inside the objective function? This is from the guide: "In order to increase computational speed, the CP-SAT solver works over the integers. This means all constraints and the objective must have integer coefficients." That would mean that by multiplying the coefficient by some n*10 to get rid of the decimal value I'd need to add a costraint to the X's to accept only integer solutions – AathakA Jan 19 '22 at 19:40
  • The objective function accepts floating point coefficients with integer variables natively since the last version. – Laurent Perron Jan 19 '22 at 20:37
  • So in that case I would minimize the obj func `2A1x1 + sx1 ...` , right? How can I create the variable sx1 and impose it to be equal to x1 * x1? – AathakA Jan 20 '22 at 12:37
  • use model.AddMultiplicationEquality(). – Laurent Perron Jan 20 '22 at 13:59
  • But I would do `model.AddMultiplicationEquality(t1, [1000 * a1 + 1000 * x1, 1000 * a1 + 1000 * x1])`. The `model.Add(sum(1000 * bi * ai) <= 1000 * T` and `model.Minimize(sum(ti) * 1.0 / 1e6)` – Laurent Perron Jan 20 '22 at 15:03