Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Modifying NON SCALAR data from “main” scripting

  • 1.  Modifying NON SCALAR data from “main” scripting

    Posted 08/07/13 11:19 AM

    Originally posted by: CplexUser1453


    Hello

    I am trying to see if I can implement a decomposition using OPL script and I have run into the following problem: I need to modify non scalar data.

    I have found examples of how to modify scalar data (http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r4/index.jsp, https://www.ibm.com/developerworks/community/forums/html/topic?id=243675ee-3045-41b5-ada9-d1613686b44c&ps=25) but somehow I am incapable of modifying non scalar stuff. The link above says :

    "Only external data can be modified by script. [...] So you would need to create a .dat file that contains the data to update"

    However, I am getting an error when supplying the data that is supposed to be updated. Here is a very simple example :

    var m1Source = new IloOplModelSource("model.mod");
    var m1Cplex = new IloCplex();
    var m1Def = new IloOplModelDefinition(m1Source);
    var m1Opl = new IloOplModel(m1Def,m1Cplex);

    var defaultData           = new IloOplDataSource("defaultData.dat");

    var subProblemData = new IloOplDataSource("subProblemData.dat");

    m1Opl.addDataSource(defaultData);

    m1Opl.addDataSource(subProblemData);


    I get an error on the last line that the data element that I want to update has already been defined ("La donnée elementaire "X" a déjà été définie.)

    subProblemData.dat contains the following data :

    X =   [1, 2, 3, 4];

    while the original data is a

    {int} X

    initialized with values [1, 2, 3, 4,5,6]

    (Obviously,  my example is just an illustration and may not make much sense by itself  - what I am really trying to do is decomposing a large MILP problem that is defined in a single .mod file. The decomposition requires updating the non scalar data and I would like to do it without touching the .mod file)

    Is there any way to solve this problem, or what I am trying to do is not possible with OPL script?

    Thanks a lot!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Modifying NON SCALAR data from “main” scripting

    Posted 08/29/13 11:49 AM

    Hi,

     

    let me give you a small example.

    Sub model sub.mod

    float maxOfx = ...;
    {int} y=...;

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

    dvar float x;

    maximize x;
    subject to {
      x<=maxOfx+sum(i in y)i;
    }

     

    and then the main .mod is

    {int} s={};

    main {
      var source = new IloOplModelSource("sub.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
     
     
      for(var k=11;k<=15;k++)
      {
      var opl = new IloOplModel(def,cplex);
        
      var data2= new IloOplDataElements();
      data2.maxOfx=k;
    data2.y=thisOplModel.s;
    data2.y.add(6);
    data2.y.add(k);
      opl.addDataSource(data2);
      opl.generate();

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

     

    and the display is

    y= {6 11}
    Tried aggregator 1 time.
    LP Presolve eliminated 1 rows and 2 columns.
    All rows and columns eliminated.
    Presolve time = 0.00 sec. (0.00 ticks)
    OBJ = 28
    y= {6 11 12}
    Tried aggregator 1 time.
    LP Presolve eliminated 1 rows and 2 columns.
    All rows and columns eliminated.
    Presolve time = 0.02 sec. (0.00 ticks)
    OBJ = 41
    y= {6 11 12 13}
    Tried aggregator 1 time.
    LP Presolve eliminated 1 rows and 2 columns.
    All rows and columns eliminated.
    Presolve time = 0.00 sec. (0.00 ticks)
    OBJ = 55
    y= {6 11 12 13 14}
    Tried aggregator 1 time.
    LP Presolve eliminated 1 rows and 2 columns.
    All rows and columns eliminated.
    Presolve time = 0.00 sec. (0.00 ticks)
    OBJ = 70
    y= {6 11 12 13 14 15}
    Tried aggregator 1 time.
    LP Presolve eliminated 1 rows and 2 columns.
    All rows and columns eliminated.
    Presolve time = 0.02 sec. (0.00 ticks)
    OBJ = 86

     

    I hope this helps

     

    Regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer