【问题标题】:How to run multiple .dat files in the same model with using flow control?如何使用流控制在同一模型中运行多个 .dat 文件?
【发布时间】:2021-01-16 11:46:30
【问题描述】:

我在 CPLEX 中有一个 MIP 模型。我尝试使用带有流量控制的启发式算法。每次解决问题时,我都需要使用多个“.dat”文件并获取决策变量解决方案值。我尝试使用“addDataSource”,但没有可用的解决方案错误。当我尝试在没有“addDataSource”的情况下解决时,我没有收到此错误。我该如何处理这个问题。

【问题讨论】:

    标签: cplex opl


    【解决方案1】:

    查看几个 dat 文件

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

    {string} datFiles={"zoodat.dat","zoodat2.dat"};
        
        main
        {
          var source = new IloOplModelSource("zoodat.mod");
          var cplex = new IloCplex();
          var def = new IloOplModelDefinition(source);
         
          for(datFile in thisOplModel.datFiles)
          {
             writeln("with ",datFile);
             var opl1 = new IloOplModel(def,cplex);
             var data1=new IloOplDataSource(datFile);
              opl1.addDataSource(data1);
            
              opl1.generate();
              cplex.solve();
              opl1.postProcess();
              writeln();
       
    
            }
    
     }
     
     /*
     
     which gives
     
     with zoodat.dat
    The minimum cost is 380
    We will use 6 40 seats buses and 2 30 seats buses 
    with zoodat2.dat
    The minimum cost is 500
    We will use 10 40 seats buses and 0 30 seats buses 
    */ 
    

    【讨论】:

    • 谢谢!我已经阅读了您之前为别人的问题写的答案,我尝试了一下。它确实可以获取目标函数值,但是当我尝试在同一模型和主模型中获取决策变量的解决方案值时,它不起作用。我没有得到解决方案错误。我想不通。
    • 如果在 opl1.postProcess();你写 writeln("--> ",opl1.nbBus40," bus 40 seat");你会得到 --> 10 辆公共汽车 40 个座位
    猜你喜欢
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    相关资源
    最近更新 更多