如何在 Cplex 中编写约束

问题描述 投票:0回答:2

我有负载节点“n”。每个负载节点“n”连接三条线路。为每一行定义一个变量“x”。我必须以这样的方式编写一个约束,使变量“x”值的范围位于 0.5<=x<=1 for one of three lines and for the rest of two lines its range is in between 0<=x<=0.5. it may also happen that the value of this variable for all three lines lies between the range 0<=x<=0.5. Suggest to me how to write this constraint in OPL CPLEX.

之间

我正在尝试的代码

forall(三行节点中的 n){

forall (行中的 l:lineconect[l].tonode == n) {

0.5+1e-6<=alpha[l]<=1; // but this code is not correct.

}

}

constraints cplex
2个回答
0
投票
if (hasLineInUpperRange && hasLineInLowerRange) {

} else if (hasLineInUpperRange) {
    // All lines should be in the upper range
    forall (l in linesConnectedToNode) {
        0.5 <= alpha[l] <= 1;
    }
} else {
    forall (l in linesConnectedToNode) {
        0 <= alpha[l] <= 0.5;
    }
}

}

在此代码中 decalare bool 和值 hasLineInLowerRange 、hasLineInUpperRange 为 false


0
投票

逻辑约束可以有所帮助:

range nodes=1..4;
range lines=1..3;


dvar float+ x[nodes][lines] in 0..1;

dexpr int nbInRange[n in nodes]=sum(l in lines) (0<=x[n][l]<=0.5);


subject to
{
  forall(n in nodes) nbInRange[n]>=2;
}
© www.soinside.com 2019 - 2024. All rights reserved.