簡體   English   中英

如何在 CPLEX 中從同一 CP model 運行多個實例(數據集)?

[英]How to run multiple instances (datasets) from same CP model in CPLEX?

我正在嘗試通過在 cplex (12.6) 中“使用 CP”來制作迭代代碼。
我將此腳本用於 OPL model。
我需要更改下面的代碼以執行 CP model?

主模塊

{string} datafile = ...;
int timeLimit = ... ;

main {  
  
  thisOplModel.generate();
  var Data = thisOplModel.dataElements;  

  var fResult = new IloOplOutputFile();
  fResult.open("D_Forte_Var_faible_m_2.csv");

 function computeSubMIP(s) {
       var subSource = new IloOplModelSource("MIP (nouveau).mod");
       var subDef = new IloOplModelDefinition(subSource);
       var subCplex = new IloCplex();
       var subDataSource = new IloOplDataSource(s);
       // Parametrage Cplex
       subCplex.tilim = Data.timeLimit;
       // Imports des donnees dans modele OPL
       var Opl0 = new IloOplModel(subDef, subCplex);
       Opl0.addDataSource(subDataSource);
       Opl0.generate();
      if ( subCplex.solve() ) {
          //fResult.write(subCplex.getBestObjValue(), " ; ");
          fResult.write(subCplex.getObjValue(), " ; ");
          fResult.writeln(subCplex.getSolvedTime(), " ; "); 
          Opl0.postProcess();             
       } else {
          writeln("ERROR IN SUB MIP COMPUTATION !!");
        }
     subDataSource.end();  
     Opl0.end();
     subCplex.end();
     subSource.end();
}
  for ( var s in Data.datafile){  
     fResult.write(s, " ; "); 
     computeSubMIP(s);
 }
 fResult.close();
}

如何使用 OPL?

更改一些數據並在約束規划中重新生成並再次求解

main {
  var source = new IloOplModelSource("cposubvalue.mod");
  var cp = new IloCP();
  var def = new IloOplModelDefinition(source);
 
 
 
  for(var k=1;k<=10;k++)
  {
  var opl = new IloOplModel(def,cp);
    
  var data2= new IloOplDataElements();
  data2.maxOfx=k;
  opl.addDataSource(data2);
  opl.generate();

  if (cp.solve()) {  
     opl.postProcess();
     writeln("OBJ = " + cp.getObjValue());
  } else {
     writeln("No solution");
  }
 opl.end();
}  
 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM