Simple Quadratic Problem In Gurobi Not Producing Optimal Result?
Solution 1:
I would never piecewice linearize z
, but always z*x
. If you have a piecewise linear expression for z
only, then z*x
is nonlinear (and in a nasty way). If you however write down a piecewise linear expression for z*x
then the whole thing becomes linear. Note that discontinuities in the piecewise functions require attention.
It is important to understand mathematically what you are writing down before you pass it on to a solver.
Solution 2:
Piecewise
in Pyomo
is intended to interpolate linearly between some bounds given by another variable. This means that if you give the bounds given as you're trying, your interpolating as this (sorry for such a bad graph) which basically means that you're placing a line between x=5 and x=10 a line given by Z= 31 - 2.1X
, and another line between 10 and 11. In fact, Gurobi is computing the optimal result, since x its a NonNegativeReal and in such a line Z= 31 - 2.1X
, x=7.37
give as result Z=15.53
.
Now, I understand that you want rather a step function than a interpolation, something similar to this (sorry for such a bad graph, again), then you need to change your DOMAIN_PTS
and RANGE_PTS
in order to correctly model what you want
# Break points for step-functionDOMAIN_PTS = [5.,5., 10., 10.,11.]
RANGE_PTS = [20.5,10., 10., 9., 9.]
In this way, you're interpolating between f(x)=20.5: 5<=x<=10
and so on.
Post a Comment for "Simple Quadratic Problem In Gurobi Not Producing Optimal Result?"