我正在尝试解决我已经用 Python 库解决的问题的线性松弛,以查看它在 Xpress Mosel 中的行为是否相同。
我使用的一个索引集不是典型的 c=1..n 而是一组集,这意味着我已经采用了 1..n 集并创建了所有可能的子集组合(例如集合1..3 创建集合集{{1},{2},{3},{1,2},{2,3},{1,2,3}}
)。
在我的约束之一中,索引之一必须在这些子集中的每个子集中运行。Python中的相应代码如下(使用Gurobi库):
cluster=[1,2,3,4,5,6]
cluster1=[]
for L in range(1,len(cluster)+1):
for subset in itertools.combinations(cluster, L):
clusters1.append(list(subset))
ConstraintA=LinExpr()
ConstraintB=LinExpr()
for i in range(len(nodes)):
for j in range(len(nodes)):
if i<j and A[i][j]==1:
for l in range(len(clusters1)):
ConstraintA+=z[i,j]
for h in clusters1[l]:
restricao2B+=(x[i][h]-x[j][h])
model.addConstr(ConstraintA,GRB.GREATER_EQUAL,ConstraintB)
ConstraintA=LinExpr()
ConstraintB=LinExpr()
(如果上面的代码令人困惑,我怀疑是这样)我要编写的约束是:
z(i,j)>= sum_{h in C1}(x(i,h)-x(j,h))
C中的所有C1
其中 C1 是每个子集。
有没有办法在摩泽尔做到这一点?