Function addGenConstrLog buggy
AnsweredThe function model.addGenConstrLog seems super buggy. I'm trying small test example and it says log(x) = 23.03 for x = 9, though it is correct for larger x. It doesn't matter what values I use for the func parameters, I still get same result regardless.
public static void main(String[] args) throws GRBException {
GRBEnv env = new GRBEnv();
GRBModel model = new GRBModel(env);
model.set(GRB.IntParam.Presolve, 0);
GRBVar x = model.addVar(0, GRB.INFINITY, 0, GRB.CONTINUOUS, "x");
GRBLinExpr expr1 = new GRBLinExpr();
expr1.addTerm(1, x);
model.addConstr(expr1, GRB.EQUAL, 9, "expr1");
GRBVar y = model.addVar(GRB.INFINITY, GRB.INFINITY, 0, GRB.CONTINUOUS, "y");
model.addGenConstrLog(x, y, "", "");
GRBLinExpr obj = new GRBLinExpr();
obj.addTerm(1, y);
model.setObjective(obj);
model.set(GRB.IntAttr.ModelSense, GRB.MINIMIZE);
model.optimize();
double xval = x.get(GRB.DoubleAttr.X);
double yval = y.get(GRB.DoubleAttr.X);
double objval = model.get(GRB.DoubleAttr.ObjVal);
System.out.println(xval + " " + yval + " " + objval);
model.dispose();
env.dispose();
}
Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (win64)
Optimize a model with 1 rows, 2 columns and 1 nonzeros
Model fingerprint: 0xd2b4f56a
Model has 1 general constraint
Variable types: 2 continuous, 0 integer (0 binary)
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [1e+00, 1e+00]
Bounds range [0e+00, 0e+00]
RHS range [9e+00, 9e+00]
Variable types: 1102 continuous, 1 integer (0 binary)
Root relaxation: objective 2.302552e+01, 4 iterations, 0.00 seconds
Nodes  Current Node  Objective Bounds  Work
Expl Unexpl  Obj Depth IntInf  Incumbent BestBd Gap  It/Node Time
* 0 0 0 23.0255194 23.02552 0.00%  0s
Explored 0 nodes (4 simplex iterations) in 0.02 seconds
Thread count was 8 (of 8 available processors)
Solution count 1: 23.0255
No other solutions better than 23.0255
Optimal solution found (tolerance 1.00e04)
Warning: max constraint violation (9.0000e+00) exceeds tolerance
Warning: max general constraint violation (9.0000e+00) exceeds tolerance
Best objective 2.302551935769e+01, best bound 2.302551935769e+01, gap 0.0000%
9.0 23.025519357687067 23.025519357687067

Hi, Sam!
We created a support ticket to investigate further. Thanks for bringing this to our attention.
0 
Dear Sam,
The unexpected behavior you observed is the result of disabling presolve without providing a reasonable bound to
x
(in your example0<=x<=+inf
). Gurobi outputs good approximations forln(x)
when the upper bound ofx
is set to, for example, 1000.In any case, it's usually a good idea to keep the presolve on when having PWL approximators such as
model.addGenConstrLog()
, as it can strengthen bounds.I hope this information helps.
0
Please sign in to leave a comment.
Comments
2 comments