如何利用OPL求解CPLEX中的Epsilon约束方法求解双/多目标问题?
谢谢!
在OPL CPLEX中可以直接使用多目标
int nbKids=200;
float costBus40=500;
float costBus30=400;
float costBus50=625;
dvar int+ nbBus40;
dvar int+ nbBus30;
dvar int+ nbBus50;
dvar float cost;
dvar float co2emission;
minimize
staticLex(cost,co2emission);
subject to
{
cost==costBus40*nbBus40 +nbBus30*costBus30+nbBus50*costBus50;
co2emission==nbBus50+nbBus40*1.1+nbBus30*1.2;
40*nbBus40+nbBus30*30+nbBus50*50>=nbKids;
}
execute DISPLAY_After_SOLVE
{
writeln("The minimum cost is ",cost);
writeln("CO2 emission is ",co2emission);
writeln("We will use ",nbBus40," 40 seats buses ",nbBus30,
" 30 seats buses and ", nbBus50," buses 50 seats");
}
,但如果你喜欢使用流量控制,你可以写
int nbKids=200;
float costBus40=500;
float costBus30=400;
float costBus50=625;
dvar int+ nbBus40;
dvar int+ nbBus30;
dvar int+ nbBus50;
dvar float cost;
dvar float co2emission;
minimize
cost+co2emission;
subject to
{
cost==costBus40*nbBus40 +nbBus30*costBus30+nbBus50*costBus50;
co2emission==nbBus50+nbBus40*1.1+nbBus30*1.2;
40*nbBus40+nbBus30*30+nbBus50*50>=nbKids;
}
execute DISPLAY_After_SOLVE
{
writeln("The minimum cost is ",cost);
writeln("CO2 emission is ",co2emission);
writeln("We will use ",nbBus40," 40 seats buses ",nbBus30,
" 30 seats buses and ", nbBus50," buses 50 seats");
}
main
{
var epsilon=0.01;
thisOplModel.generate();
// remove co2emission from the objective by setting coef 0
cplex.setObjCoef(thisOplModel.co2emission,0);
cplex.solve();
thisOplModel.postProcess();
var cost=thisOplModel.cost.solutionValue;
// add a new constraint that cost should not move up too much
thisOplModel.cost.UB=cost*(1+epsilon);
// keep only CO2 emission in the objective
cplex.setObjCoef(thisOplModel.co2emission,1);
cplex.setObjCoef(thisOplModel.cost,0);
cplex.solve();
thisOplModel.postProcess();
}
或者如果你想更新约束
的边界int nbKids=200;
float costBus40=500;
float costBus30=400;
float costBus50=625;
dvar int+ nbBus40;
dvar int+ nbBus30;
dvar int+ nbBus50;
dvar float cost;
dvar float co2emission;
minimize
cost+co2emission;
subject to
{
cost==costBus40*nbBus40 +nbBus30*costBus30+nbBus50*costBus50;
co2emission==nbBus50+nbBus40*1.1+nbBus30*1.2;
40*nbBus40+nbBus30*30+nbBus50*50>=nbKids;
ctMaxCost:cost<=maxint;
}
execute DISPLAY_After_SOLVE
{
writeln("The minimum cost is ",cost);
writeln("CO2 emission is ",co2emission);
writeln("We will use ",nbBus40," 40 seats buses ",nbBus30,
" 30 seats buses and ", nbBus50," buses 50 seats");
}
main
{
var epsilon=0.01;
thisOplModel.generate();
// remove co2emission from the objective by setting coef 0
cplex.setObjCoef(thisOplModel.co2emission,0);
cplex.solve();
thisOplModel.postProcess();
var cost=thisOplModel.cost.solutionValue;
// add a new constraint that cost should not move up too much
thisOplModel.ctMaxCost.UB=cost*(1+epsilon);
// keep only CO2 emission in the objective
cplex.setObjCoef(thisOplModel.co2emission,1);
cplex.setObjCoef(thisOplModel.cost,0);
cplex.solve();
thisOplModel.postProcess();
}