Gurobi fails to find feasible solutions for a simple optimization problem with sin function
AnsweredI am testing the nonconvex optimization capability of Gurobi. I found Gurobi even fails to find a feasible solution for a very simple problem with sin function.Can anyone help me with this problem?
The optimization problem is: min x ; s.t. sin(x) <= -0.1, -pi <= x <= pi. The code is given as follows:
import numpy as np
import gurobipy as gp
from gurobipy import GRB
model = gp.Model()
x = model.addMVar(shape=(1, 1), vtype=GRB.CONTINUOUS, name="x")
y = model.addMVar(shape=(1, 1), vtype=GRB.CONTINUOUS, name="y")
gc1 = model.addGenConstrSin(x, y)
model.addConstr(y <= -0.1 )
model.addConstr(x >= -np.pi)
model.addConstr(x <= np.pi)
model.setObjective(x, GRB.MINIMIZE)
model.optimize()
print(x.X)
The output is given below:
Set parameter Username
Academic license - for non-commercial use only - expires 2025-06-03
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: 13th Gen Intel(R) Core(TM) i9-13900HX, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 3 rows, 2 columns and 3 nonzeros
Model fingerprint: 0x56424c07
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 [1e-01, 3e+00]
Presolve removed 1 rows and 0 columns
Presolve time: 0.00s
Explored 0 nodes (0 simplex iterations) in 0.00 seconds (0.00 work units)
Thread count was 1 (of 32 available processors)
Solution count 0
Model is infeasible
Best objective -, best bound -, gap -
0
-
Hi Tong,
Gurobi variables have a default lower bound of 0. If you want x to be able to take negative values you will need to specify a lower bound when creating the variables.
- Riley
0 -
Hi Riley,
I got the right result after adding bounds for both x and y. Thanks so much.
- Tong
0
Please sign in to leave a comment.
Comments
2 comments