print constraints Gurobi Python

一曲冷凌霜 提交于 2019-12-07 14:16:03

问题


I'm using Gurobi in Python and for a given set S I'm adding the constraint as follows:

for i in S:
  m.addConstr(quicksum(x[i,j] for j in (set(V) - set(S))) >= 2)

I want to print these constraints for each value of the sets S and V on the screen. For an example, if S={1,3,4} and V= {1,2,3,4,5,6}, then, my constraint will be x[1,2]+x[1,5]+x[1,6]+x[3,2]+x[3,5]+x[3,6]+x[4,2]+x[4,5]+x[4,6]>=2 I want this constraint to be preinted on the screen. Can someone please help me to do it?


回答1:


There is no built-in function to do this. Your best option is to call Model.write() to export the model as an LP file.




回答2:


Use model.write("file.lp"). You can choose any name for file but the extension must be lp.



来源:https://stackoverflow.com/questions/45992765/print-constraints-gurobi-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!