Gurobi says the model is infeasible, yet I can come up with a solution by hand
回答済みHello. Here is my model. My apologies if its hard to follow. Gurobi says its infeasible.
from gurobipy import Model, GRB
import json
f = Model()
num_steps = 3
steps = [*range(num_steps)]
steps_for_C = [*range(num_steps + 1)]
A = f.addVar(0, float('inf'), name = 'A')
B = f.addVar(0, float('inf'), name = 'B')
C = {}
for step in steps_for_C:
C[step] = f.addVar(0, float('inf'), name="C[%i]" % step)
D = {}
for step in steps_for_C:
D[step] = f.addVar(0, 1, name="D[%i]" % step)
E = {}
for step in steps_for_C:
E[step] = f.addVar(0, float('inf'), name="E[%i]" % step)
F = {}
for step in steps_for_C:
F[step] = f.addVar(0, float('inf'), name="F[%i]" % step)
H = {}
for step in steps_for_C:
H[step] = f.addVar(0, float('inf'), name="H[%i]" % step)
J = {}
for step in steps_for_C:
J[step] = f.addVar(0, float('inf'), name="J[%i]" % step)
G = {}
for step in steps:
G[step] = f.addVar(0, 80, name="G[%i]" % step)
for step in steps:
L = 100
f.addConstr(D[0] == 1., name = 'C == 1')
f.addConstr(C[0] == 0.8*A, name = 'C initial')
f.addConstr(C[step + 1] == C[step] * 0.9999 + E[step+1] - F[step+1], name = 'C update')
f.addConstr(H[step] == E[step] - F[step], name = 'H constr')
f.addGenConstrAbs(J[step], H[step], name = 'J constr')
f.addConstr(D[step + 1] == D[step] - (0.75 * J[step+1] - 0.02 * C[step+1] + 0.02) * 0.001, name = 'D constr')
f.addConstr(C[step] <= 0.8*A*D[step+1], name = 'C max')
f.addConstr(C[step] >= 0.2*A, name = 'C min')
f.addConstr(E[step] <= B, name = 'E less than B')
f.addConstr(E[step+1] <= 0.8*A*D[step+1] - C[step], name = 'E limit')
f.addConstr(F[step] <= B, name = 'F less than B')
f.addConstr(F[step+1] <= C[step] - 0.2*A, name = 'F limit')
f.addConstr(-L + G[step] - E[step] + F[step] == 0, name = 'p constraint')
f.setObjective(A, GRB.MINIMIZE)
f.params.FeasibilityTol = 0.01
f.params.NonConvex = 2
f.optimize()
However, I can easily come up with a solution by hand, as in:
A = 10
B = 2
D = 1
C = 8
F = 2
E = 0
for step in [1,2,3]:
J = abs(PB_charging - PB_discharging)
D -= ((0.75 * J - 0.02 * C + 0.02) * 0.001 + step/1000)
C = C * 0.9999 + E - F
G = E - F + L
print('G is: ', G)
print('D is: ', D)
print('C is: ', C)
print('----------')
Since I can come up with a solution by hand, why is the model infeasible? Am I missing something here? Perhaps the order in which I arrange my constraints? Any help is appreciated.
-
正式なコメント
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?.
投稿コメントは受け付けていません。
コメント
2件のコメント