Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Problem in main script

    Posted Mon February 29, 2016 07:19 AM

    Originally posted by: Rym


    I generate my model n times in loop for. 

    In the loop for (ittération) I would to make the sum between each countPV cell of the last ittération   and the newest .

    In main script, i can't mak the sum etween two arrays cell per cell.

     

    My model:

     

    {int} contPM;

    int VMmin=1;
    int VMmax=4;
    int VM[i in V]=VMmin+rand(VMmax-VMmin+1);
    string S[VMmin..VMmax]=["s","m","l","xl"];
    string vms[i in V]=S[VM[i]];
    {string} VMTypes={S[v] | v in VMmin..VMmax};

     

    //PreProcess
     ....

    //the model/problem definition

    dvar boolean lumda[V][P];
    dexpr int O = sum( i in V, j in P) lumda[i][j];
    dexpr int OPPMVMS[vmtype in VMTypes][ptype in P]=sum( j in P, i in V:j==ptype&&vms[i]==vmtype) lumda[i][j];
    maximize O;

    //constraints

    ....


    tuple PM
    {
      int npm;
      string nvm;
      }
    {PM} indexes={<i,j> | i in P,j in VMTypes};
    int countPV[ <i,j> in indexes]=OPPMVMS[j][i]; 
     
    {int} countPM={j | i in V,j in P:lumda[i][j]==1 };
    int pm= card(countPM);

    main

     

    {var res = new Array();

    var min=10;
    var max=30;
    var mix=max-min+1;

    for(var j=1;j<120;j=j+(min+(Opl.rand(mix))))
    {

    for (var i=1; i<=NbI;i++)
    {
      writeln("######Ittération number ", i,"#######");


       var masterDef = thisOplModel.modelDefinition;
       var masterCplex = cplex;
       var masterData = thisOplModel.dataElements;   
       // Creating the master-model
       var masterOpl = new IloOplModel(masterDef, masterCplex);
       masterData.v=j;
       masterOpl.addDataSource(masterData);
       writeln("solving with ",j,"  vms");
       masterOpl.generate();

        if ( masterCplex.solve() )
           {

    I want to store in an array of same size that countVP the sum of each cell of countPV  for  the n ittérations:

    res[i]=res[i]+masteOpl.countPV[i]
          }

     

    else

    {}

     

    }end n ittérations

    for(var i in res)

    //the average

    res[i]=res[i]/Number of ittérations

    }end second loop for

          }

    }

    Thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Problem in main script

    Posted Mon February 29, 2016 12:20 PM

    Hi,

    let me give you a small example:

    You have sub.mod

    float maxOfx = ...;
    dvar float x[1..10];

    maximize sum(i in 1..10)x[i];
    subject to {
      forall(i in 1..10) x[i]<=maxOfx;
    }

    and sub.dat

     

    maxOfx=10;

    then

     range r=1..10;
     int sumofresults[i in 1..10]=0;
     
     main {
      var source = new IloOplModelSource("sub.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
     
      var maxOfx=0;
     
      for(var k=1;k<=10;k++)
      {
      maxOfx=k;  
     
     
      var opl = new IloOplModel(def,cplex);
      var data= new IloOplDataElements();
     
      writeln(maxOfx);
      data.maxOfx=maxOfx;
      opl.addDataSource(data);
      opl.generate();

      if (cplex.solve()) {
      opl.postProcess();  
     
         for(var i in thisOplModel.r) thisOplModel.sumofresults[i]+=opl.x[i]*1.0;
      } else {
         writeln("No solution");
      }

     
     
    }  

    writeln("sumofresults=",thisOplModel.sumofresults)
     
    }

     

    will put results into an array

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Problem in main script

    Posted Tue March 01, 2016 04:26 PM

    Originally posted by: fch77


    Why do I get the following runtime error with the example you provided?

        Element "maxOfx" not defined.

     

    Thanks.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Problem in main script

    Posted Wed March 02, 2016 12:47 AM

    Hi,

    let us call main.mod the third code I wrote.

    You should do

    oplrun main.mod

    or in the IDE launch a run configuration with only main.mod

    Is that what you did ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Problem in main script

    Posted Wed March 02, 2016 11:09 AM

    Hi,

    is it working now ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Problem in main script

    Posted Wed March 02, 2016 01:50 PM

    Originally posted by: fch77


    Yes, it is working. Thanks for your help.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer