My LP model does not give expected answer
回答済みimport gurobipy as gp
from scipy.optimize import linprog
import numpy as np
lp_m = gp.Model()
w = np.array([1., 5., 1.])
halfspaces = np.array([
[1.*w[0], 1.*w[1], 1.*w[2], -10 ],
[ 1., 0., 0., -4],
[ 0., 1., 0., -4],
[ 0., 0., 1., -4],
[-1., 0., 0., 0],
[ 0., -1., 0., 0],
[ 0., 0., -1., 0]
])
A = halfspaces[:,0:3]
b = -1*halfspaces[:,-1]
cost = np.zeros(A.shape[1])
opt_x = lp_m.addMVar((A.shape[1],), name="x")
lp_m.setObjective(cost@opt_x)
lp_m.addConstr(A@opt_x <= b)
lp_m.optimize()
print(opt_x.X) # [0. 0. 0.]
res = linprog(c=cost, A_ub=A, b_ub=b, method='interior-point')
print(res.x) # [1.65708642 1.040279 1.65708642]
I want to use gurobi instead of scipy, but I am not getting the same answer which I get in scipy, Could someone help me what went wrong here?
0
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
This is a cross-post to stackoverflow - LP model does not give expected answer.
0
投稿コメントは受け付けていません。
コメント
2件のコメント