【发布时间】:2021-04-19 19:21:49
【问题描述】:
我正在尝试解决我已经使用 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)) forall C1 in C
其中 C1 是每个子集。
有没有办法在摩泽尔做到这一点?
【问题讨论】:
标签: indexing set integer-programming mosel