我不知道如何在CPLEX中写下以下条件?

时间:2018-05-01 00:27:50

标签: optimization conditional-statements cplex

∀d1,d2∈D:∃(p [i]∈P[d1])∩(p [j]∈P[d2])∩(l∈p[i]∩l∈p[j])

我想写这个条件,但我不知道怎么做!

我写的就是你能看到的,这是对的吗?

{int} path[Demands][K_sp]=...; ( we have k_sp shortest pathes for each demand, that each shortest path includes index of links) {int} Path[Demands]=...; (i insert all of index links for k_sp shortest paths a demand in this array) forall (i in Demands, j in Demands : i!=j && card(Path[i] inter Path[j])!=0) D[i][j]+D[j][i]==1;

2 个答案:

答案 0 :(得分:0)

以下可以帮到你吗?

{int} D=asSet(1..10);
{int} allP=asSet(1..20);

dvar boolean x[d in D][p in allP]; // for each D , is p in P[d] ?


subject to
{
forall(d1,d2 in D) 1<=sum(p in allP) ((x[d1][p]==1) && (x[d2][p]==1));
}

assert forall(d1,d2 in D) or(p in allP) ((x[d1][p]==1) && (x[d2][p]==1));

问候

答案 1 :(得分:0)

你可以使用逻辑约束:

{int} D=asSet(1..10);
{int} allP=asSet(1..20);

dvar boolean x[d in D][p in allP]; // for each D , is p in P[d] ?
dvar boolean DD[d1 in D][d2 in D];

subject to
{
forall(ordered d1,d2 in D) DD[d1][d2]== (1<=sum(p in allP) ((x[d1][p]==1) && (x[d2][p]==1)));
forall(ordered d2,d1 in D) DD[d1][d2]== 1-(1<=sum(p in allP) ((x[d1][p]==1) && (x[d2][p]==1)));
}

问候