Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Passing solution to the another model

    Posted 06/17/14 05:54 AM

    Originally posted by: disjunctive


    Hi,

    There are some related questions with my problem  in the forum but i think i am missing a point. Here is my question:

    First, i need solve the master problem to obtain the solutions, say A[i][j] and B[i][k]. Then the subproblem requires these solutions with some modifications. I mean, let X[i] is the needed parameter for the subproblem and for all i, X[i] is calculated as follows:

    if A[i][j] equals to 1 for j'th indices then X[i] equals to j.

    I couldn't figure out how i can add X[i] to the data of the subproblem. I am using same data file for both problems. Should i identify the X in the data file? I did like this:

    var subData=thisOplModel.dataElements;

    var subData1= new IloOplDataElements();

    for( i in Range)

    for(j in Range2)

    { if(A[i][j]==1) { 

    subData1.X[i]= masterOpl.A[i][j];

    subOpl.addDataSource(subData1) ;}}

    subOpl.addDataSource(subData);

    When i run the program, it give an error and said there is no X.

    If you are able to help me, i will be very grateful.

    Thank you.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Passing solution to the another model

    Posted 06/17/14 10:03 AM

    Hi,

    I gave an example at

     

    https://www.ibm.com/developerworks/community/forums/html/topic?id=df612d06-4c0a-4873-b655-42b66422e733&ps=25

     

     

    sub.mod

    float maxOfx = ...;
    dvar float x;

    maximize x;
    subject to {
      x<=maxOfx;
    }

    and then the main model is

    main {
      var source = new IloOplModelSource("sub.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
     
     var globalValue=0;
     
      for(var k=11;k<=15;k++)
      {
      var opl = new IloOplModel(def,cplex);
        
      var data2= new IloOplDataElements();
      data2.maxOfx=globalValue;

      opl.addDataSource(data2);
      opl.generate();

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

     

    and this gives

    OBJ = 0
    OBJ = 10
    OBJ = 20
    OBJ = 30
    OBJ = 40

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Passing solution to the another model

    Posted 06/17/14 10:57 AM

    Originally posted by: disjunctive


    Thank you Alex, but i saw that example. When i write like below, it gives an error and says X does not exist.

    var subData=new IloOplDataSource("subproblem.dat");

    subOpl.addDataSource(subData);

    var subData1= new IloOplDataElements();

    for( i in Range)

    for(j in Range2)

    { if(A[i][j]==1) { 

    subData1.X[i]= j;

    subOpl.addDataSource(subData1) ;}}

    I define the X in the subproblem.dat file with X=[0,0]. I really don't know what is wrong. Why does it say that X does not exist?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Passing solution to the another model



  • 5.  Re: Passing solution to the another model

    Posted 06/17/14 01:11 PM

    Originally posted by: disjunctive


    Many thanks Alex. I think it worked. However, now it says X is identified before. 

    Shouldn't i initialize the parameter in dat. file? I'm sorry for this simple question, but i'm confused.

    Thank you again.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Passing solution to the another model

    Posted 06/17/14 02:28 PM

    Originally posted by: disjunctive


    It's done, thanks Alex.

    What I want to know is why we need to initialize the X (or any second-stage parameter) with first-stage parameter? When we do like this, we need to add unnecessary parameter X to the first-stage. Am I right? If we don't write like follow: 

    subData1.X=masterOpl.X (or another variable with same size)

    it says X does not exist. Can we handle this situation in a different way?

    Best Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Passing solution to the another model

    Posted 06/17/14 02:52 PM

    Hi

     

    in

    var data2= new IloOplDataElements();
    data2.y=thisOplModel.a;
    data2.y[1][1]=k;

    The second and third lines are needed

    The first copies the structure and the second the values

    This is my way at least!

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer