JuMP model is feasible where gurobipy model is infeasible
AnsweredI am coming to gurobipy from JuMP (Julia) and having problems with feasibility.
I expect the following problem to be feasible but gurobi states it is not
```python
T = np.array([[ 0, -10, -10],
[ 0, 10, 30]])
As = np.array([
[-1,1],
[1,-1],
])
nc, nt = T.shape
nl = As.shape[0]
m = gp.Model()
D = m.addMVar(shape=(nc, nt), name="D")
gamma =m.addMVar(shape=(nc, nt), name="gamma", lb = -GRB.INFINITY, ub = 0)
Q = m.addMVar(shape=(nl, nt), name="Q", lb=0, ub = GRB.INFINITY)
m.addConstr(As@Q == T + D)
m.addConstr(gamma <= D, name= "D exceeds gamma")
m.setObjective(gp.quicksum(-gamma[i,t] for i in range(nc) for t in range(nt)), GRB.MINIMIZE)
m.optimize()
I have tried computing the IIS and relaxing feasibility but I have not found this helpful. Normally I would doubt myself but the equivalent problem in JuMP solves with the expected solution of 20
```julia
using JuMP, Gurobi
T= [
0 -10 -10
0 10 30
]
As= [
-1 1
1 -1
]
nc, nt = size(T)
nl = size(As,1)
m =Model(Gurobi.Optimizer)
@variable(m, D[1:nc, 1:nt])
@variable(m, gamma[1:nc, 1:nt] ≤ 0)
@variable(m, 0≤ Q[1:nl, 1:nt])
@constraint(m, As*Q .== T+D)
@constraint(m, gamma .≤ D)
@objective(m, Min, -sum(gamma))
optimize!(m)
```
JuMP is a high level package which then uses MathOptInterface.jl to interact with Gurobi.jl. I know they do some things under the hood to keep JuMP high-level, but I wouldn't expect that to make the problem feasible.
I expect I am using gurobi.py incorrectly.
Thanks,
Josh
0
-
Hi Josh,
Using gurobipy the default lower bounds for the variables are 0, see Model.addMVar().
If you change the lower bound for the D variables to -Infinity, the model becomes feasible.Cheers,
Marika1 -
Marika,
Thank you. A very silly mistake as I had realised this for gamma.
Josh
0
Please sign in to leave a comment.
Comments
2 comments