Obtain linear approximation
AnsweredHello, I have the following question. I use addGenConstrExp and addGenConstrLogistic to linearly approximate an exponential and a logarithmic function. Is it possible that I can somehow output the approximation based on this so that I can use it for my model writeup?
-
Hi Lorenz,
Note that if you are using Gurobi v12 or later then you will need to set the FuncNonLinear parameter to 0, or the FuncNonLinear attribute on the general constraints to 0, as from v12 onwards handling these constraints via a piecewise linearization is not default behavior (it is typically not as good as dynamic outer approximation).
To view the PWL approximations you can set Presolve=0 and then create a presolved model via functions such as Model.presolve (Python) and GRBpresolvemodel (C) - you can find an equivalent function in whatever API you are using.
The presolve that occurs when we set Presolve=0 will only convert the general constraints (if FuncNonLinear=0). If you write the presolved model to an LP file you can inspect it.
- Riley
0 -
Riley Clement Thank you for your anwser. What is the difference between the linear approximation and the dynamic outer approximation? And is it also possible, assuming I approximate \( y=0.5+0.5(1-\exp^{-x})\) and \(x\) only goes up to \(x=3\) in my model, but I also want the general notation of the approximation up to \(x=10\) in my model, is that also possible?
0 -
Hi Lorenz,
What is the difference between the linear approximation and the dynamic outer approximation?
This is best explained by the Nonlinear Constraints section of our video Whats New in Gurobi 11.0 (13m10s). The chapter on Nonlinear Constraints in our reference manual will also be useful (you can probably skip the part on Expression Trees). Note that at the end of this section in our reference manual we say:
While users could perform piecewise-linear approximations themselves, there are several advantages to asking Gurobi to do it instead. First, Gurobi can often reduce the domains of variables, by using bound strengthening in presolve, or by exploiting repetition in periodic functions like sine or cosine. Smaller domains means fewer pieces to achieve the same accuracy. Gurobi also provides many options to make experimentation easier (for error control, piece length, etc.). These options can be quite difficult to implement and maintain.
And is it also possible, assuming I approximate …. and x only goes up to x=3 in my model, but I also want the general notation of the approximation up to x=10 in my model, is that also possible?
I'm not clear on what is meant here, but I will take a guess that you are adding a PWL function to the model to approximate the nonlinear function, but only defining the x points as far as x=3, and you're wanting to know what happens if a solution has x = 10? If this is the case, then you can think of the last piece in the PWL function being extended to infinity. I.e. the last two x and y points (x1,y1) (x2,y2) define a line that starts at (x1,y1) passes through (x2,y2) and keeps going indefinitely.
- Riley
0
Please sign in to leave a comment.
Comments
3 comments