Minimization Constraint not working
回答済みI have following constraint wish to be added into the optimization:

In python I coded as following:
I have a cell_map to keep the correct i sequence, and the i+1 is the next_i, I read https://support.gurobi.com/hc/en-us/community/posts/360074541152-How-to-write-a-maximize-constraint-using-gurobipy and make the third term as a new constraint as constatint2 inner.
for cell_pair in cell_map:
prev_i, i, next_i = cell_pair # get neighboring cells
if next_i != 0:
for t in T:
if i not in special_cells:
# Constraint 2
m.addConstr(a[next_i, t] == w / v * (N[next_i] - n[next_i, t]), name='constatint2 inner')
m.addConstr(f[next_i, t] == min_(n[i, t], N[next_i], a[next_i, t]),
name=f"constraint2_{next_i}_{t}")
The problem is after I run the model and check the constraint with m.display(), only the 'constraint2 inner' is showing and the minimize constraint constraint 2 is not showing, after further checking the results, the constraint 2 is not working. Did I make any mistakes?
-
Hi Peirong,
This may simply be a case of needing to call m.update() to update the model.
However please note that the display() function is now deprecated and undocumented and we recommend that you do not use it. The preferred way of inspecting a model is to write it to a LP file and then use a text editor to inspect the file.
If you write it to a LP file and still encounter an obstacle then please let us know.
- Riley
0 -
Hi Riley,
Really Appreciate your valuable suggestion. I believe the m.display() cause me the problem. Now with
m.write("myModel.lp")I can see the constraint 2 in the .lp file.
General Constraints
constraint2_1_1: f[2,1] = MIN ( n[1,1] , a[2,1] , 20 )Thank you!
-Slade
0
サインインしてコメントを残してください。
コメント
2件のコメント