最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

iteration - How to update a matrix in iterative optimization using cplex opl? - Stack Overflow

programmeradmin2浏览0评论

I am solving an iterative optimization problem in cplex opl using the main function. However, I am getting errors while printing a matrix value. Please help me in solving this issue.

int Nod=41;  
range NodRange = 1..Nod;

int nr=140;  
range RRange = 1..nr;

int TSlot = 96;  
range TRange = 1..TSlot;

int ncs=6;
range csrange=1..ncs;

int piles=12;
range np=1..piles; 

int nv=3;
range nvrange=1..nv;

 main {
    var source = new IloOplModelSource("subvalue.mod");
    var cplex = new IloCplex;
    var def = new IloOplModelDefinition(source);
    
    var pa= new int [np][TRange];
    
    for(var v=1;v<=3;v++)
    {
      var opl = new IloOplModel(def, cplex);
      var data = new IloOplDataSource("MultipleEtoCS.dat");
      var data2=new IloOplDataElements();
      
      data2.cev=v;
      opl.addDataSource(data2);
      opl.addDataSource(data);
      opl.generate();
      
      if (!cplex.solve()) {
      writeln("No solution exists. Stopping.");
    }else{
        opl.postProcess();
        writeln(" solution is =" + cplex.getObjValue());
        for (var j in opl.csrange){
          if(j<=opl.sreq)
            opl.pa[opl.vpile[v]][opl.cslot+1+j]=+1;
         }              
               
  }
    
}
    
     opl.end();
}

How to print the pa matrix. I am getting the error as a scripting parser error. In the code sreq[nvrange],vpile[nvrange] and cslot[nvrange] are integer decision variables, defined in the subvalue.mod file. How can I implement this logic correctly to print the pa matrix for all values of v.

I am solving an iterative optimization problem in cplex opl using the main function. However, I am getting errors while printing a matrix value. Please help me in solving this issue.

int Nod=41;  
range NodRange = 1..Nod;

int nr=140;  
range RRange = 1..nr;

int TSlot = 96;  
range TRange = 1..TSlot;

int ncs=6;
range csrange=1..ncs;

int piles=12;
range np=1..piles; 

int nv=3;
range nvrange=1..nv;

 main {
    var source = new IloOplModelSource("subvalue.mod");
    var cplex = new IloCplex;
    var def = new IloOplModelDefinition(source);
    
    var pa= new int [np][TRange];
    
    for(var v=1;v<=3;v++)
    {
      var opl = new IloOplModel(def, cplex);
      var data = new IloOplDataSource("MultipleEtoCS.dat");
      var data2=new IloOplDataElements();
      
      data2.cev=v;
      opl.addDataSource(data2);
      opl.addDataSource(data);
      opl.generate();
      
      if (!cplex.solve()) {
      writeln("No solution exists. Stopping.");
    }else{
        opl.postProcess();
        writeln(" solution is =" + cplex.getObjValue());
        for (var j in opl.csrange){
          if(j<=opl.sreq)
            opl.pa[opl.vpile[v]][opl.cslot+1+j]=+1;
         }              
               
  }
    
}
    
     opl.end();
}

How to print the pa matrix. I am getting the error as a scripting parser error. In the code sreq[nvrange],vpile[nvrange] and cslot[nvrange] are integer decision variables, defined in the subvalue.mod file. How can I implement this logic correctly to print the pa matrix for all values of v.

Share Improve this question asked Mar 15 at 11:22 SUBHADARSHINI PANDASUBHADARSHINI PANDA 433 bronze badges 2
  • Hi , what errors do you get ? – Alex Fleischer Commented Mar 15 at 16:10
  • Hi. I am getting two errors ,Scripting runtime error: cannot convert to a number, " [2 0 0]" for the line : if(j<=opl.sreq) and Scripting parser error: missing expression for the line var pa= new int [np][TimeRange]; – SUBHADARSHINI PANDA Commented Mar 15 at 17:59
Add a comment  | 

1 Answer 1

Reset to default 1

I get your error with

int sreq[1..2]=[1,2];
int j=1;
execute
{
  opl=thisOplModel;
  if (j<=opl.sreq) writeln("KO");
  
}

And that's normal since sreq is an array and j a value

If I write

int sreq[1..2]=[1,2];
int j=1;
execute
{
  opl=thisOplModel;
  if (j<=opl.sreq[2]) writeln("OK");
  
}

Then it's ok and I see "OK"

And to create new arrays in scripting let me share a small example I wrote

{int} s={1,2};
int a[1..2]=[3,4];
range r=1..4;

int ar[j in 1..4]=j;

execute
{
 
  // Scripting variables are local to the scripting block
  var ar=new Array(4);
  
  ar[1]=s;
  ar[2]=a;
  ar[3]=new Date();
  ar[4]=new Array(2);
  ar[4][1]="hello";
  ar[4][2]=2;
  writeln("ar = (in the first execute block)",ar);
  for(var i in r) writeln("ar[",i,"] = ",ar[i]);
  writeln("ar[4][1] = ",ar[4][1]);
  writeln("ar[4][2] = ",ar[4][2]);
}

execute
{
  writeln("ar = (in the second execute block)",ar);
}
发布评论

评论列表(0)

  1. 暂无评论