将解决方案池从脚本日志导出到 excel Cplex

Export solution pool from scripting log to excel Cplex

我正在为我的论文写一个合并模型。通过使用解决方案池,我能够看到所有可行的、非最优的解决方案。但是,我不太熟悉这个命令,所以我需要一些帮助才能将这些输出写入 excel。这是我的代码的相关部分,其中 y 是一个二元变量,如果订单 n 在终端 j 合并,在时间 t 从非合并卡车 g 合并到合并卡车 h:

dvar int+ y[gateway_terminal, truck, cons_truck, time, order] in 0..1; 
{tuple_y} output_y = {<i,g,h,t,n,y[i,g,h,t,n]> | i in gateway_terminal, g in truck, h in cons_truck, t in time, n in order: y[i,g,h,t,n] == 1}; //tuple to show optimal outcome in excel

//ALTERNATIVE FEASIBLE (NON_OPTIMAL) SOLUTIONS
execute 
{
writeln("Total cost equals to ", total_cost, " and the consolidated orders are ", output_y);
}

main { cplex.solnpoolintensity = 4;
thisOplModel.generate();
cplex.solve();
if (cplex.populate()) {
  var nsolns = cplex.solnPoolNsolns;
  
  writeln("Number of solutions found = ", nsolns);
  writeln();
  for (var s=0; s<nsolns; s++) {
    thisOplModel.setPoolSolution(s);
    thisOplModel.postProcess();
  }
 }
}

有人知道我如何将这些信息导出到 excel 吗?非常感谢您的帮助!亲切的问候

你可以在流控中生成.dat文件,然后用这个.dat写入Excel.

让我用 https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/

中的 2 个例子作为例子
  • Get several solutions

  • Excel spreadsheets

     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;
     }
     tuple t
     {
      int n40;
      int n30;
     }
    
     t sol=<nbBus40,nbBus30>;
     execute
     {
      writeln("nbBus40 = ",nbBus40," and nbBus30 = ",nbBus30," and the cost is      ",costBus40*nbBus40  +nbBus30*costBus30);
     }
    
      main {
        var outputfile=new IloOplOutputFile("sols.dat");
        outputfile.writeln("sols={");
    
      cplex.solnpoolintensity=4;
    
         thisOplModel.generate();
         cplex.solve();
          if (cplex.populate()) {
             var nsolns = cplex.solnPoolNsolns;
    
    
            writeln("Number of solutions found = ",nsolns);
            writeln();
            for (var s=0; s<nsolns; s++) {
             thisOplModel.setPoolSolution(s);
              thisOplModel.postProcess();
             outputfile.writeln(thisOplModel.sol,",");
            }
         }
          outputfile.writeln("};");
          outputfile.close();
     }
    

构建sols.dat

sols={
 <6 2>,
 <9 0>,
 <7 1>,
 <8 1>,
 <7 2>,
 <10 0>,
 <9 1>,
 <8 2>,
 <6 3>,
 <5 4>,
 <7 3>,
 <11 0>,
 <9 2>,
 <6 4>,
 <4 5>,
 <5 5>,
 <7 4>,
 <10 1>,
 <3 6>,
 <9 3>,
 <12 0>,
 <8 3>,
 <5 6>,
 <10 2>,
 <9 4>,
 <6 5>,
 <4 6>,
 <4 7>,
 <4 8>,
 <4 9>,
 <4 10>,
 <4 11>,
 <11 1>,
 <11 2>,
 <11 3>,
 <11 4>,
 <11 5>,
 <11 6>,
 <8 0>,
};

然后你可以使用

tuple t
    {
      int n40;
      int n30;
    }
    
     {t} sols=...;

用 sols.dat 写入 Excel 那些解决方案