如何在找到每个可行解后停止 DoCplex.CP 解算器?

How to stop DoCplex.CP solver after finding each feasible solution?

亲爱的,

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

提前致谢 穆罕默德

  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(); }
}