Cplex中的模型累积VRP

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

我是Cplex IBM ILOG CPLEX Optimization Studio的新手,目前正在像下面这样编写累积VRP模型(参考:DOI:10.5772 / 5812):

enter image description here

这是我的代码:

{string} CIUDADES = ...;
 int READY_TIME[CIUDADES] = ...;
 int DUE_TIME[CIUDADES] = ...;
 int SERVICETIME[CIUDADES] = ...;
 int DISTANCIA[CIUDADES, CIUDADES] = ...;
 int CLIENTES=11;
 int Penalizacion = 10;
 int DEMANDAS[CIUDADES] = ...;
 int NROCIUDADES[CIUDADES] = ...;
int PESO_VACIO = 6350;
int PESO_LLENO = 3650;
int VELOCIDAD_MINIMA = 20;
int VELOCIDAD_MAXIMA = 90;
int UMBRAL_RETRASO = 300;
int aux = 0;
int CARGAT = sum(ci in CIUDADES) DEMANDAS[ci];
int vehiculos =1;

//DV
dvar int X[CIUDADES,CIUDADES] in 0..1;
dvar int Y[CIUDADES, CIUDADES] in 0..(CARGAT+PESO_VACIO);

minimize
    sum(ci in CIUDADES) 
        sum(cj in CIUDADES)
          DISTANCIA[ci,cj]*Y[ci,cj];

subject to {
    restriccion1: 
            sum(ci in CIUDADES) 
                X["Kingston_upon_Hull",ci]==1;  

    restriccion2: 
            sum(ci in CIUDADES) 
                X[ci,"Kingston_upon_Hull"]==1;

    forall(cj in CIUDADES) {
    restriccion3: 
            sum(ci in CIUDADES: ci!=cj) 
                (X[ci,cj])==1;
}

    forall(ci in CIUDADES) {
    restriccion4: 
            sum(cj in CIUDADES: ci!=cj) 
                (X[ci,cj])==1;
}   

forall(ci in CIUDADES) {
    restriccion5: 
            ((sum(cj in CIUDADES: ci!=cj) 
                (Y[cj,ci]))
                -
            (sum(cj in CIUDADES: ci!=cj) 
                (Y[ci,cj])))
            == DEMANDAS[ci];

}   

forall(ci in CIUDADES) {
    restriccion6:
     Y[ci,"Kingston_upon_Hull"]== PESO_VACIO*X[ci,"Kingston_upon_Hull"];
}   

forall(ci in CIUDADES, cj in CIUDADES) {
    restriccion7:
     Y[ci,cj] <= ((77777777)-DEMANDAS[ci])*X[ci,cj];

}

forall(ci in CIUDADES, cj in CIUDADES) {
    restriccion8:
     Y[ci,cj] >= ((PESO_VACIO)-DEMANDAS[cj])*X[ci,cj];
}

forall(ci in CIUDADES) {
    restriccion9:
     Y["Kingston_upon_Hull",ci]== (PESO_VACIO+CARGAT)*X["Kingston_upon_Hull",ci];
}
}

但是使用CPLEX编译时,得到以下结果:

/ solution (feasible relaxed sum of infeasibilities) with objective 5671
// Quality Incumbent solution:
// MILP objective                                 6.6464998100e+09
// MILP solution norm |x| (Total, Max)            1.02485e+05  1.20210e+04
// MILP solution error (Ax=b) (Total, Max)        0.00000e+00  0.00000e+00
// MILP x bound error (Total, Max)                0.00000e+00  0.00000e+00
// MILP x integrality error (Total, Max)          0.00000e+00  0.00000e+00
// MILP slack bound error (Total, Max)            5.67100e+03  5.67100e+03
Y = [[0
             0 0 0 0 0 0 0 0 0 12021]
             [0 0 10186 0 0 0 0 0 0 0 0]
             [0 0 0 9372 0 0 0 0 0 0 0]
             [0 0 0 0 0 0 0 0 8752 0 0]
             [0 10907 0 0 0 0 0 0 0 0 0]
             [0 0 0 0 11218 0 0 0 0 0 0]
             [6350 0 0 0 0 0 0 0 0 0 0]
             [0 0 0 0 0 0 6863 0 0 0 0]
             [0 0 0 0 0 0 0 0 0 7989 0]
             [0 0 0 0 0 0 0 7431 0 0 0]
             [0 0 0 0 0 11385 0 0 0 0 0]];
X = [[0 0 0 0 0 0 0 0 0 0 1]
             [0 0 1 0 0 0 0 0 0 0 0]
             [0 0 0 1 0 0 0 0 0 0 0]
             [0 0 0 0 0 0 0 0 1 0 0]
             [0 1 0 0 0 0 0 0 0 0 0]
             [0 0 0 0 1 0 0 0 0 0 0]
             [1 0 0 0 0 0 0 0 0 0 0]
             [0 0 0 0 0 0 1 0 0 0 0]
             [0 0 0 0 0 0 0 0 0 1 0]
             [0 0 0 0 0 0 0 1 0 0 0]
             [0 0 0 0 0 1 0 0 0 0 0]];

并使用oplrun -p folder在Windows中通过cmd进行编译,我得到以下信息:

Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de2ae    
Infeasibility row 'restriccion1':  0  = 1.
Presolve time = 0.02 sec. (0.76 ticks)  

我的程序为变量Xij和Yij赋值,但未优化目标函数。我在哪里有错误?您的帮助将不胜感激。

谢谢!

mathematical-optimization cplex
1个回答
0
投票

在IDE中,您的放松是因为您的模型不可行,在命令行中您只会收到一条很小的消息。

如果您想通过命令行查看放松,则执行oplrun -relax

非常简单example

让我们继续

https://www.linkedin.com/pulse/what-optimization-how-can-help-you-do-more-less-zoo-buses-fleischer/

并解决新的问题:不可行!

让我们假设我们面临一个新的挑战:总共使用不到7辆巴士。

然后我们写

int nbKids=300;
float costBus40=500;
float costBus30=400;

dvar int+ nbBus40;
dvar int+ nbBus30;

minimize
 costBus40*nbBus40  +nbBus30*costBus30;

subject to
{
 ctAllKidsNeedToGo:
     40*nbBus40+nbBus30*30>=nbKids;

 ctMaxTotalBuses:
     nbBus30+nbBus40<=7;
}

ctAllKidsNeedToGo和ctMaxTotalBuses是约束的标签。

但是然后问题变得不可行,因为即使有7辆40个座位的公共汽车,您也只能容纳280 = 7 * 40个孩子,而这个孩子少于300个孩子。

[启动此模型时,我们会发生冲突

这意味着我们在这两个约束内有冲突,并且有放松,这意味着如果我们将7辆公共汽车放松为8辆公共汽车,那么我们就有了可行的解决方案。

这对于这个小例子不是很有用,但是对于真实模型,这可能是关键。

有关更多信息,请参见CPLEX文档的IDE教程中的放松不可行的模型

NB:

您还可以通过脚本中的流控制获取该信息:

int nbKids=300;
float costBus40=500;
float costBus30=400;

dvar int+ nbBus40;
dvar int+ nbBus30;

minimize
 costBus40*nbBus40  +nbBus30*costBus30;

subject to
{
 ctAllKidsNeedToGo:
     40*nbBus40+nbBus30*30>=nbKids;

 ctMaxTotalBuses:
     nbBus30+nbBus40<=7;
}

main
{
thisOplModel.generate();
if (!cplex.solve())
{
writeln(thisOplModel.printRelaxation());
writeln(thisOplModel.printConflict());
}
}

给予

ctMaxTotalBuses
    relax [-Infinity,7] to [-Infinity,8] value is -Infinity

ctAllKidsNeedToGo
  is in conflict
ctMaxTotalBuses
  is in conflict
© www.soinside.com 2019 - 2024. All rights reserved.