如何在找到每个可行的解决方案后停止DoCplex.CP求解器



Dears,

目前,我正在使用OPL DoCplex来解决使用CP的问题。基本模型是在OPL中构建的,然后我通过DoCplex将其调用到python中。我有以下问题:1-在OPL模型中,有一些决策表达式(dexpr(没有导入到python。我该怎么做,或者在哪里可以找到导入的dexpr(如果有的话(。2-在找到每个可行的解决方案后,我如何停止求解器?进行一些后处理,然后再次运行求解器。这可能吗?

提前感谢Mohamed

  1. 如果您希望在python代码中看到dexpr,则可以将其转换为元组集

  2. 您可以在OPL中使用流量控制并调用postProcess/

示例https://github.com/AlexFleischerParis/zooopl/blob/master/zooseveralcpo.mod

using CP;

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

dvar int+ nbBus40;
dvar int+ nbBus30;

minimize
costBus40*nbBus40  +nbBus30*costBus30;

subject to
{
40*nbBus40+nbBus30*30>=nbKids;
}
execute
{
writeln("nbBus40 = ",nbBus40," and nbBus30 = ",nbBus30," and the cost is ",costBus40*nbBus40  +nbBus30*costBus30);
}

main
{
cp.param.SearchType=24;
cp.param.workers=1;
thisOplModel.generate();
cp.startNewSearch();
while
(cp.next()) {  thisOplModel.postProcess(); }
} 

最新更新