【问题标题】:Cplex opl Flow control: displaying solutionCplex opl Flow control:显示解决方案
【发布时间】:2020-09-19 13:33:25
【问题描述】:

我目前正在尝试解决 Benders 分解的问题。我正在使用已安装文件中现有示例中的示例。我无法理解的是如何或在何处显示决策变量的解决方案。我正在使用如下代码。我的问题是指最后一部分,我希望程序显示三个决策变量的解决方案:x[][][] 是 float+,y[][] 是二进制,theta[] 是二进制。使用 printSolution 是一个正确的决定吗?在其他方法中,我还发现了 getObjCoef()。使用 getObjCoef 方法时,我该如何制定?

我愿意提供任何帮助。 问候

      main{
    thisOplModel.generate();

    var masterDef = thisOplModel.modelDefinition; 
    var masterCplex =cplex;
    var masterData= thisOplModel.dataElements;
     var subCplex = new IloCplex ();
     var subOpl = new IloOplModel(masterDef, subCplex);

    subOpl.addDataSource(masterData);
    subOpl.generate();
    subCplex.bendersstrategy = 1;

    subCplex.newLongAnnotation("cpxBendersPartition");
    for (var s in thisOplModel.other_scenarios){    
        for (var d in thisOplModel.demands){
            for (var a in thisOplModel.arcs){
        
                subCplex.setLongAnnotation("cpxBendersPartition", subOpl.x[s][d][a], subOpl.bendersPartitions[s]);
                 }          
        }   
    }

    **if (subCplex.solve()) {
         writeln("Total Cost = " + subCplex.getObjValue());    
 
       writeln("solution:" + subOpl.printSolution());
 
      } else {
         writeln("No solution");}**

    cplex.exportModel("bendersv2.lp");
    subCplex.writeBendersAnnotation("bendersv2.ann");
    subCplex.delLongAnnotation("cpxBendersPartition");
    subOpl.end();//clean up of memory
    subCplex.end();//clean up of memory
    }

【问题讨论】:

    标签: output opl


    【解决方案1】:

    printSolution 将为您提供完整的解决方案,但在脚本中您也可以简单地编写

    writeln(x);
    

    将显示 x

    例如https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/

    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;
    } 
    
    main
    {
      thisOplModel.generate();
      cplex.solve();
      writeln(thisOplModel.printSolution());
      writeln(thisOplModel.nbBus40);
    }
    

    给予

    nbBus40 = 6;
    nbBus30 = 2;
    
    6
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      相关资源
      最近更新 更多