打印限制Gurobi Python [英] print constraints Gurobi Python
问题描述
我在Python中使用Gurobi,并为给定的 S
添加约束,如下所示:
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)
我想为每个集合的值打印这些约束S
和 V
在屏幕上。
例如,如果 S = {1,3,4}
和 V = {1,2,3,4,5 ,6}
,那么我的约束将是 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 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?
推荐答案
没有内置函数可以执行此操作。最好的选择是调用 Model.write()
将模型导出为LP文件。
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.
这篇关于打印限制Gurobi Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!