如何在OPL代码中将目标更改为“最小化Max()-Min()”?

时间:2018-06-29 16:52:26

标签: cplex opl

我有一些OPL代码,可将决策变量的总和最小化。效果很好,我对此很满意,但我想更改目标以最大程度地减少决策变量的范围。

这是我的工作OPL代码:

// Decision Variables
dvar int Column0Row1;
dvar int Column0Row2;
dvar int Column0Row3;
dvar int OColumn0Row1;
dvar int Column1Row2;
dvar int Column1Row4;
dvar int OColumn0Row2;
dvar int OColumn1Row2;
dvar int Column2Row3;
dvar int Column2Row4;
dvar int OColumn0Row3;
dvar int OColumn2Row3;
dvar int Column3Row4;
dvar int OColumn1Row4;
dvar int OColumn2Row4;
dvar int OColumn3Row4;

// Objective
minimize Column0Row1 + Column0Row3 + Column1Row2 + Column1Row4 + OColumn0Row2 + Column2Row3 + Column3Row4 + OColumn2Row4;
// Constraints
subject to
{
    Column0Row1 == -OColumn0Row1;
    Column0Row1 >= 1;
    Column0Row2 <= -1;
    Column0Row3 == -OColumn0Row3;
    Column0Row3 >= 1;
    OColumn0Row1 <= -1;
    Column1Row2 == -OColumn1Row2;
    Column1Row2 >= 1;
    Column1Row4 == -OColumn1Row4;
    Column1Row4 >= 1;
    OColumn0Row2 == -Column0Row2;
    OColumn0Row2 >= 1;
    OColumn1Row2 <= -1;
    Column2Row3 == -OColumn2Row3;
    Column2Row3 >= 1;
    Column2Row4 <= -1;
    OColumn0Row3 <= -1;
    OColumn2Row3 <= -1;
    Column3Row4 == -OColumn3Row4;
    Column3Row4 >= 1;
    OColumn1Row4 <= -1;
    OColumn2Row4 == -Column2Row4;
    OColumn2Row4 >= 1;
    OColumn3Row4 <= -1;
    Column0Row1 + Column0Row2 + Column0Row3 == 0;
    OColumn0Row1 + Column1Row2 + Column1Row4 == 0;
    OColumn0Row2 + OColumn1Row2 + Column2Row3 + Column2Row4 == 0;
    OColumn0Row3 + OColumn2Row3 + Column3Row4 == 0;
    OColumn1Row4 + OColumn2Row4 + OColumn3Row4 == 0;
}

我想将目标更改为以下内容:

// Objective
minimize Math.Max(Column0Row1, Column0Row3, Column1Row2, Column1Row4, OColumn0Row2, Column2Row3, Column3Row4, OColumn2Row4) - Math.Min(Column0Row1, Column0Row3, Column1Row2, Column1Row4, OColumn0Row2, Column2Row3, Column3Row4, OColumn2Row4);

所以目标应该是:最高决策变量减去最低决策变量。

任何想法表示赞赏。

1 个答案:

答案 0 :(得分:1)

minimize maxl(Column0Row1, Column0Row3, Column1Row2, Column1Row4, OColumn0Row2, Column2Row3, Column3Row4, OColumn2Row4) - minl(Column0Row1, Column0Row3, Column1Row2, Column1Row4, OColumn0Row2, Column2Row3, Column3Row4, OColumn2Row4);

工作正常