Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

problem loop for

ALEX FLEISCHER

ALEX FLEISCHERThu April 07, 2016 12:06 PM

  • 1.  problem loop for

    Posted Tue April 05, 2016 06:48 AM

    Originally posted by: Rym


    Hi 

    For changing  my result in every step of the loop for ,i should set  the value of the range a to a static parameter that i think isn't normal think


    int v = ...;
    range V = 1..v;
    int VM[V] = ...;
    int a[1..300];

    main
    {
      var masterDef = thisOplModel.modelDefinition;
      var masterCplex = cplex;
        var masterOpl = new IloOplModel(masterDef, masterCplex); 
      var masterData = thisOplModel.dataElements;
     
     
      for(var h=1;h<=10;h++)
      {

      var masterOpl = new IloOplModel(masterDef, masterCplex); 
      masterData.v=h;
      masterData.VM=thisOplModel.a;
      for(var q=1;q<=h;q++)
    {
      masterData.VM[q]=1+(Opl.rand() % (4 - 1 + 1));
    }  
      masterOpl.addDataSource(masterData);
      masterOpl.generate(); 
       }

    }

     

     

    thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: problem loop for

    Posted Thu April 07, 2016 12:06 PM

    Hi,

    indeed I would do the same:

    .mod

    int v = ...;
    range V = 1..v;
    int VM[V] = ...;
    int a[1..20];

    execute
    {
    writeln("VM=",VM);
    }

    subject to
    {

    }

    main
    {
      var masterDef = thisOplModel.modelDefinition;
      var masterCplex = cplex;
        var masterOpl = new IloOplModel(masterDef, masterCplex);
      var masterData = thisOplModel.dataElements;
     
     
      for(var h=1;h<=10;h++)
      {

      var masterOpl = new IloOplModel(masterDef, masterCplex);
      masterData.v=h;
      masterData.VM=thisOplModel.a;
      for(var q=1;q<=h;q++)
    {
      masterData.VM[q]=1+(Opl.rand() % (4 - 1 + 1));
    }  
      masterOpl.addDataSource(masterData);
      masterOpl.generate();
       }

    }

     

    .dat

     

    v=4;
    VM=[1,2,3,4];

    that gives

     

    VM= [1 2 3 4]
    VM= [3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [2 2 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [2 1 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [2 3 2 1 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [4 3 3 4 4 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [4 1 4 1 1 1 4 0 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [2 2 3 4 2 4 1 2 0 0 0 0 0 0 0 0 0 0 0 0]
    VM= [4 3 4 3 1 4 3 4 2 0 0 0 0 0 0 0 0 0 0 0]
    VM= [4 2 3 3 1 2 1 4 3 1 0 0 0 0 0 0 0 0 0 0]

    if you do not want this a then you could use a set instead of an array like at https://www.ibm.com/developerworks/community/forums/html/topic?id=84f171d3-48fe-4d6a-bfed-5d0837185b5e&ps=25

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer