带有流控制的CPLEX的保存结果(通过重新生成更改数据来解决)

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

[浏览了stackoverflow + IBM论坛+ Alex Fleischer的How to Linkedin页面之后,我设法用脚本运行问题,并在每次迭代(流控制)时更改参数。但是,我想将每次迭代的输出保存到唯一的excel文件中。我通读了参考书和手册/用户指南,但仍不确定如何实现。

使用脚本之前,我在.dat文件中为要保存的每个变量使用了SheetWrite。

我在运行脚本时如何做到这一点,以便在每次迭代时将其保存到新的Excel文件中? (我有大约7次运行的有限次数的迭代,因此每次运行只需要7个文件)

提前感谢..

main{
 var status = 0;
 thisOplModel.generate();
 var produce = thisOplModel;
 var best;
 var curr = Infinity;
 var maxdisp = produce.allowedwindisp;

 var ofile = new IloOplOutputFile("testresult.txt");

 while ( maxdisp>=1 ) {
    best = curr;
    writeln();
    writeln("Solve with maxdisp = ",maxdisp);
    if ( cplex.solve() ) {
    curr = cplex.getObjValue();
    writeln("OBJECTIVE: ",curr);
    ofile.writeln("Objective with maxdisp = ", maxdisp, " is ", curr);        
    } 
    else {
      writeln("No solution!");
      break;
    }

    // prepare next iteration
    var def = produce.modelDefinition;
    var data = produce.dataElements;

    if ( produce!=thisOplModel ) {
    produce.end();
    }

    produce = new IloOplModel(def,cplex);
    maxdisp--;
    data.allowedwindisp = maxdisp;
    produce.addDataSource(data);
    produce.generate();
    }    
    ofile.close();
    status;}

这是我在每次迭代中更改变量的操作,但是我不确定如何链接以从每次迭代中写入新的Excel文件。

optimization mathematical-optimization cplex opl flow-control
1个回答
0
投票

我在https://www.ibm.com/developerworks/community/forums/html/topic?id=755b8aa9-4f7c-42a9-9790-2f4ef160ae68处回答了类似的问题

您应该在子模型dat部分中使用SheetWrite,并且不要忘记在主脚本中调用opl.postProcess

© www.soinside.com 2019 - 2024. All rights reserved.