I add constraint with '>=' but in the model it is <= 0
ユーザーの入力を待っています。I add some linear constr to the gurobi LP model as follow:
""" constraint (2)"""
for t in range(1, data.round_num + 1):
for p in range(1, data.parklot_num + 1):
con_name_2 = f'cons_(2)_{t}_{p}'
self.cons_RMP[con_name_2] = self.RMP.addConstr(sum(constrain_coef[f'{v}_{lot}_cons_2'][f'{t}_{p}']
* self.x[f'x_{v}_{lot}'] for v in
range(1, data.vehicle_num + 1) for lot in
range(1, data.parklot_num + 1))
<= 1, name=con_name_2)
""" constraint (3)"""
for t in range(2, data.round_num + 1):
for p in range(1, data.parklot_num + 1):
for q in range(1, data.parklot_num + 1):
if self.data.C[p - 1][q - 1] == 1:
con_name_3 = f'cons_(3)_{t}_{p}_{q}'
self.cons_RMP[con_name_3] = self.RMP.addConstr(
sum(constrain_coef[f'{v}_{lot}_cons_3'][f'{t}_{p}_{q}']
* self.x[f'x_{v}_{lot}'] for v in range(1, data.vehicle_num + 1) for lot in
range(1, data.parklot_num + 1))
>= data.C[p - 1][q - 1] - 2, name=con_name_3)
""" constraint (4)"""
for t in range(2, data.round_num + 1):
for p in range(1, data.parklot_num + 1):
for q in range(1, data.parklot_num + 1):
if self.data.C[p - 1][q - 1] == 1:
con_name_4 = f'cons_(4)_{t}_{p}_{q}'
self.cons_RMP[con_name_4] = self.RMP.addConstr(
sum(constrain_coef[f'{v}_{lot}_cons_4'][f'{t}_{p}_{q}']
* self.x[f'x_{v}_{lot}'] for v in range(1, data.vehicle_num + 1) for lot in
range(1, data.parklot_num + 1))
>= data.C[p - 1][q - 1] - 2, name=con_name_4)
""" constraint (5)"""
for t in range(1, data.round_num + 1):
con_name_5 = f'cons_(5)_{t}'
self.cons_RMP[con_name_5] = self.RMP.addConstr(sum(constrain_coef[f'{v}_{lot}_cons_5'][f'{t}']
* self.x[f'x_{v}_{lot}'] for v in
range(1, data.vehicle_num + 1) for lot in
range(1, data.parklot_num + 1))
== sum(data.In[k - 1, t - 1] for k in
range(1, data.vehicle_num + 1)), name=con_name_5)
""" constraint (6)"""
for t in range(1, data.round_num + 1):
for p in range(1, data.parklot_num + 1):
for q in range(1, data.parklot_num + 1):
if self.data.C[p - 1][q - 1] == 1:
con_name_6 = f'cons_(6)_{t}_{p}_{q}'
lhs = sum(constrain_coef[f'{v}_{lot}_cons_6'][f'{t}_{p}_{q}']
for v in range(1, data.vehicle_num + 1)
for lot in range(1, data.parklot_num + 1))
self.cons_RMP[con_name_6] = self.RMP.addConstr(lhs >= 0, name=con_name_6)
the model is output by the "write" function. I find for constrain(2)-(5), the operators are the same as I build, but for constraint(6), the operators are all <= 0, I have taken a part of it for reference.
cons_(6)_1_13_1: x_1 <= 0
cons_(6)_1_13_2: <= 0
cons_(6)_1_13_7: <= 0
cons_(6)_1_13_8: <= 0
cons_(6)_1_14_1: x_1 <= 0
cons_(6)_1_14_2: <= 0
cons_(6)_1_14_7: <= 0
cons_(6)_1_14_8: <= 0
cons_(6)_1_15_2: <= 0
cons_(6)_1_15_3: <= 0
cons_(6)_1_15_4: <= 0
cons_(6)_1_15_7: <= 0
cons_(6)_1_15_8: <= 0
cons_(6)_1_15_9: <= 0
cons_(6)_1_15_10: <= 0
cons_(6)_1_15_13: <= 0
cons_(6)_1_16_1: x_1 <= 0
0
-
正式なコメント
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Zichun,
Are the constraints the same?
Terms are sometimes re-arranged for an equivalent constraint.Cheers,
David0 -
Hi, I experience the same issue for example:
Constraint
x_Block.x_constraints.add( expr= x_Block.weight[h, n, n2] >= 0)
Computed IIS with flipped inequality sign in constraint
Minimize
Subject To
R6193:
x_Block.weight[3,0.0666740748972108,0.0666740748972108]
<= 0
Bounds
x_Block.weight[3,0.0666740748972108,0.0666740748972108] >= 0.0113540901668842
End0 -
Hi Sian,
Can you write out the LP file and find constraint R6193?
- Riley
0
投稿コメントは受け付けていません。
コメント
4件のコメント