Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Error: can not assign expression

    Posted 02/06/15 12:00 AM

    Originally posted by: viva0521


    Hello,

    I am using lagrangian relaxation method to solve a MIP multi commodity flow problem. When I was trying to update my lagrangian multiplier with current flow, I got a problem here that can not update my lagrangian multiplier in main block as follows:

    ...

    main {
      var source = thisOplModel;
      var status = 0;
      thisOplModel.settings.mainEndEnabled = true;
      thisOplModel.generate();
      var GAP = 1.0e-6; //use to check if result is coverage
      var lagm1 = source.TableHWArcs[" <t.fromnode,t.tonode>:t.lagm | t in TableHWArcs "]; 
      var lagm2 = source.TableRWArcs[" <t.fromnode,t.tonode>:t.lagm | t in TableRWArcs "];
      var Cap1 = source.TableHWArcs [" <t.fromnode,t.tonode>:t.cap | t in TableHWArcs "]; 
      var Cap2 = source.TableRWArcs [" <t.fromnode,t.tonode>:t.cap | t in TableRWArcs "];
      var slack1 = source.TableHWArcs[" <t.fromnode,t.tonode>:t.slack | t in TableHWArcs "];
      var slack2 = source.TableRWArcs[" <t.fromnode,t.tonode>:t.slack | t in TableHWArcs "];
      var totalflow1 = 0;
      var totalflow2 = 0;
      
      
       var m1Def = thisOplModel.modelDefinition;
       var m1Cplex = cplex;
       var m1Data = thisOplModel.dataElements;   
       
       var best;
       var curr = Infinity;
       
       
            // Creating the m1 model
            var m1Opl = new IloOplModel(m1Def, ma1Cplex);
            m1Opl.addDataSource(m1Data);
            m1Opl.generate();
      
            // define m2 model
            var m2Source = new IloOplModelSource("MIPexm.mod");
            var m2Def = new IloOplModelDefinition(m2Source);
            var m2Cplex = new IloCplex();
      
          
            
            //first solve m1 model with initial data 
            if ( m1Cplex.solve() ) {
            m1Opl.postProcess();
            best = m1Cplex.getObjValue();
            writeln("OBJECTIVE: ",best);
            for(var i in RWArcs)for(o in Ori)for(d in Dest)
            writeln("y[i].add(i,j)[o][d]: ",m1Opl.y[i].add(i,j)[o][d].solutionValue);
            
            for(var i in HWArcs)for(o in Ori)for(d in Dest)
            writeln("x[i].add(i,j)[o][d]: ",m1Opl.x[i].add(i,j)[o][d].solutionValue);
            
            m1Opl.end();
            m1Def.end();
            m1Cplex.end();
            m1Source.end();  //m1 model is no longer needed 
          }
          //Ceating m2 model
            var m2Opl = new IloOplModel(m2Def,m2Cplex);
          
          //Using data elements from m1 model and pass its solution to m2 model
            var m2Data = thisOplModel.dataElements;
         
          m2Data.TableRWArcs.add(m1Data.TableRWArcs.flow,1,m2Opl.Use.solutionValue);
          m2Data.TableHWArcs.add(m1Data.TableHWArcs.flow,1,m2Opl.Use.solutionValue);
             
          
          
          //start iteration and the maximum number of iteration now is 20 
          var iter_limit = 20;
          for(var k=1; k<=iter_limit;k++) {
          var step = 1/k;
          writeln();
          writeln(" ITERATION: " , k ); 
          // update lagrangian multiplier
            for(var i in HWArcs){
            for(o in Ori)
            for(d in Dest){ 
            totalflow1 += x[i].add(i,j)[o][d];}
            slack1[i].add(i,j) = totalflow1 - Cap1[i].add(i,j) this expression cannot be assigned
            };
            
            for(var i in RWArcs)
            for(o in Ori)
            for(d in Dest){ 
            totalflow2 += y[i].add(i,j)[o][d];
            slack2[i].add(i,j) = totalflow2 - Cap2[i].add(i,j) this expression cannot be assigned
            };
          
            for(i in HWArcs)for(o in Ori)for( d in Dest) { 
               temp1[i].add(i,j) = lagm1[i].add(i,j); 
            if (temp1[i].add(i,j) + step * slack1[i].add(i,j) > 0)
              lagm1[i].add(i,j) = temp1[i].add(i,j) + (step * slack[i].add(i,j)) ;
            else 
              lagm1[i].add(i,j) = 0;
              };
              
             for(i in RWArcs)for(o in Ori)for( d in Dest) {  
              temp2[i].add(i,j) = lagm1[i].add(i,j); 
            if (temp2[i].add(i,j) + step * slack2[i].add(i,j) > 0 )
              lagm2[i].add(i,j) = temp1[i].add(i,j) + (step * slack[i].add(i,j)) ;
            else 
              lagm2[i].add(i,j) = 0; 
              };
            
            m2Data.addDataSource
            m2Opl.addDataSource(m2Data);  
            m2Opl.generate();
            if (m2Cplex.solve()  
            &&current = m2Cplex.getObjValue()&& (best - current) <= GAP) 
            {writeln();
            writeln("M2 OBJECTIVE: ",m2Cplex.getObjValue());
            } 
            else {
            writeln("No better solution, stop.");
            m2Data.end();
            m2Opl.end();         
            break;}
     
            m2Def.end();
            m2Cplex.end();
            m2Source.end();
       
       status;
       }
    }

    Would you please provide any suggestion? Thanks in advance! Also, I attached my mod and data file here if anyone can kindly help me to try this.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Error: can not assign expression

    Posted 02/06/15 03:33 AM

    Hi

    in your main even if you keep only

     

    main{

    var source = thisOplModel;

    var status = 0;

    thisOplModel.settings.mainEndEnabled = true;

    thisOplModel.generate();

    var GAP = 1.0e-6; //use to check if result is coverage

    var lagm1 = source.TableHWArcs[" <t.fromnode,t.tonode>:t.lagm | t in TableHWArcs "];

     

    writeln("lagm1=",lagm1);

    }

    You get

    200000

    {<1 1> <2 1> <3 1> <4 1> <5 1> <6 1> <7 0> <8 1> <9 0> <10 1>

    <11 0> <12 1> <13 0>}

    lagm1=undefined

    So no surprise if later on you get errors.

    You should fix

    lagm1 = source.TableHWArcs[" <t.fromnode,t.tonode>:t.lagm | t in TableHWArcs "];

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Error: can not assign expression

    Posted 02/06/15 03:49 AM

    Originally posted by: viva0521


    Alex, thanks for reply!

    So this would apply to my variable slack[<i,j>] as well?  Since my lagm1 is a column vector, do I need to define it as: 

    lagm1 = Array(source.TableHWArcs[" <t.fromnode,t.tonode>:t.lagm | t in TableHWArcs "];)

    Thanks!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Error: can not assign expression

    Posted 02/06/15 11:23 AM

    Hi

    main{

    var source = thisOplModel;

    var status = 0;

    thisOplModel.settings.mainEndEnabled = true;

    thisOplModel.generate();

    var GAP = 1.0e-6; //use to check if result is coverage

    var lagm1 =source.TableHWArcs;

    writeln(lagm1);

    }

    will display lagm1 which is a set

    You want to turn lagm1 into an array ?

    regards

     

     

     

     

     

     

     

     

     

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Error: can not assign expression

    Posted 02/06/15 12:15 PM

    Originally posted by: viva0521


    Alex,

    My TableHWArcs is a tuple set of all the information about arcs, the lagm1 here is essentially a set. However, I would like to associate the "from" "to" as index of lagm1. Thanks! 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Error: can not assign expression

    Posted 02/09/15 03:10 AM

    Hi

    so why not in the main do

     var lagm1=thisOplModel.Lagm1;

    ?

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Error: can not assign expression

    Posted 02/11/15 02:48 PM

    Originally posted by: viva0521


    Alex,

    Thanks. Now I can obtain the right data for these variables. But I still get the error: these expressions can not be assigned. I don't know what's going on there. Would you please help me this one? Thanks again!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Error: can not assign expression

    Posted 02/11/15 03:04 PM

    Hi

    can you post your new model ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Error: can not assign expression

    Posted 02/11/15 03:21 PM

    Originally posted by: viva0521


    Here attached are my new model, thanks!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Error: can not assign expression

    Posted 02/11/15 04:10 PM

    Hi

    slack1[i].add(i,j) = totalflow1 - Cap1[i].add(i,j)

    cannot work: slack1 is an opl array and cannot get bigger

    Scripting arrays have the add method, but not opl arrays

    Same issue with

    slack2[i].add(i,j) = totalflow2 - Cap2[i].add(i,j)

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Error: can not assign expression

    Posted 02/11/15 04:36 PM

    Originally posted by: viva0521


    Alex,

    The add method here is in order to obtain the arc information, since the arcs are in a tuple set including

    "<fromnode" "tonode>". e.g slack[<i,j>]. Is there any way  I can update the value of these opl arrays?

    Thanks!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: Error: can not assign expression

    Posted 02/12/15 08:08 AM

    Hi

    yes you can update values of the array.

    But you need to fix other errors in your script:

    For example in

    for(var i in RWArcs)for(o in Ori)for(d in Dest)

    you should add m1Opl.

    for(var i in m1Opl.RWArcs)for(o in m1Opl.Ori)for(d in m1Opl.Dest)

    Plus j does not exist ...

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer