I am trying to code a multi variable goal seeker in C#. The main idea is having a set of variables x_1 to x_n, which can be altered by the solver, so the objective function f(x) comes as close as possible to a given value Z.
So far I've mainly used the GLOP_LinearSolver, which only is able to minimize or maximize the objective function. To work around that, I've wanted to minimize the absolute square of f(x)-Z, but the GLOP_LinearSolver does not include an absolute value or a square operator (from my understanding none of the OR-Tools solvers do).
My question is: Is it possible to realise this goal seeker with Google OR-Tools? If yes: What would be a workaround for my problem? If no: What other package could I use?
The objective function
min |f(x) - Z|
can be reformulated as:
min d1 + d2
f(x) + d1 - d2 = Z
d1, d2 ≥ 0
As long as f(x)
is linear, this can be fed into any LP solver.
d1 and d2 are positive and negative deviations or slacks. We minimize the deviations, so we end up with f(x) as close to Z as possible. Note that in the optimal solution, only one of d1,d2 can be non-zero (not both). E.g. if f(x)=10 and Z=8 then d1=0,d2=2. If f(x)=7 and Z=8 then d1=1,d2=0.