Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

ALEX FLEISCHER

ALEX FLEISCHERWed December 22, 2010 05:53 AM

ALEX FLEISCHER

ALEX FLEISCHERWed December 22, 2010 05:56 AM

ALEX FLEISCHER

ALEX FLEISCHERMon September 02, 2013 03:54 AM

ALEX FLEISCHER

ALEX FLEISCHERMon September 02, 2013 04:41 AM

ALEX FLEISCHER

ALEX FLEISCHERMon September 02, 2013 05:16 AM

Archive User

Archive UserMon September 02, 2013 06:01 AM

Archive User

Archive UserMon September 02, 2013 04:17 PM

ALEX FLEISCHER

ALEX FLEISCHERTue September 03, 2013 05:22 AM

Archive User

Archive UserTue September 03, 2013 05:53 AM

ALEX FLEISCHER

ALEX FLEISCHERTue September 03, 2013 06:09 AM

ALEX FLEISCHER

ALEX FLEISCHERTue September 03, 2013 07:34 AM

Archive User

Archive UserTue September 03, 2013 07:48 AM

ALEX FLEISCHER

ALEX FLEISCHERTue September 03, 2013 08:07 AM

Archive User

Archive UserTue September 03, 2013 08:22 AM

ALEX FLEISCHER

ALEX FLEISCHERTue September 03, 2013 11:35 AM

Archive User

Archive UserTue September 03, 2013 12:35 PM

Archive User

Archive UserWed September 04, 2013 09:24 AM

  • 1.  OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue December 21, 2010 02:02 PM

    Originally posted by: DanielFelixFerber


    Hi

    I have a simple model which solution I intend to read from the OPL Java API.

    
    
    {triple
    } domain = ...; dvar float+ A[domain][rangeA][rangeB]; dvar float+ B[domain][rangeA][rangeB]; dvar float+ C[domain][rangeA][rangeB];   dexpr 
    
    float sumExpr[<c,p,a> in domain][t in rangeA][i in rangeB] = A[<c,p,a>][t][i] + B[<c,p,a>][t][i] + C[<c,p,a>][t][i];
    


    The sumExpr seems to work within constraints or other parts in the model.
    But when I try to call the OPL Java API to get values from sumExpr, or when I try to read sumExpr with OPL Script, I get the message:
    ERROR[GENERATE_103]: OPL cannot extract expression: sumExpr[<0,0,0>][0][0].
    ERROR[GENERATE_104] at 41:1-8 model.mod: OPL cannot extract model:
    Out of Scope Index c out of scope in sumExpr[display of map item is not available][display of map item is not available][display of map item is not available] = num-exprs[<c, p, a>][int(0) ][int(0) ] + num-exprs[<c, p, a>][int(0) ][int(0) ] + num-exprs[<c, p, a>][int(0) ][int(0) ].

    
    
    
    float aaaa = sumExpr[<0,0,1>][0][0]; 
    // ok, works   execute 
    { writeln(domain); 
    // prints {<0 0 0> <0 0 1> <0 1 0> <0 1 1> <1 0 0> <1 0 1> <1 1 0> <1 1 1>} var a = domain.find(0,0,1); writeln(a); 
    // prints <0 0 1> writeln(aaaa); 
    // prints expected value from sumExor writeln(A[a][0][0]); 
    // prints expected value writeln(B[a][0][0]); writeln(C[a][0][0]); writeln(sumExpr[a][0][0]); 
    // error! why? or writeln(sumExpr); 
    // error! 
    }
    


    Is this also related to APAR: http://www-01.ibm.com/support/docview.wss?uid=swg1RS00272 ?

    Is there something I am missing? Or some alternative?

    Best regards,
    Daniel Felix Ferber
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Wed December 22, 2010 05:53 AM
    Hi

    have you tried to rewrite into

    {code}

    dexpr float sumExprcpa in domaint in rangeAi in rangeB =
    Ahttp://<cpa.c,cpa.p,cpa.a>[t][i] + Bhttp://<cpa.c,cpa.p,cpa.a>[t][i] + Chttp://<cpa.c,cpa.p,cpa.a>[t][i];

    [code}

    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Wed December 22, 2010 05:56 AM
    Hi,

    I meant

    have you tried to rewrite into

    dexpr float sumExpr[cpa in domain][t in rangeA][i in rangeB] =
            A[<cpa.c,cpa.p,cpa.a>][t][i] + B[<cpa.c,cpa.p,cpa.a>][t][i] + C[<cpa.c,cpa.p,cpa.a>][t][i];
    


    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Wed December 22, 2010 10:46 AM

    Originally posted by: DanielFelixFerber


    Hi Alex,

    Yes, I considered rewriting it as you suggested and it worked in my simple example. However, on the real model, it causes other issues as I mentioned in Can not mix pattern and index - why? , since the sumExpr is used within other expressions and constraints with sumExpr[<c,p,a>] index, which is not compatible with the cpa in domain declaration.

    I found two alternatives: Rewrite the dexpr as dvar + constraints. Or create a matrix of constants that after solving will get a copy of the values returned by the dexpr, as in:
    subject to { ... }
    float sumExprCopyThatWorks[<c,p,a> in domain][rangeA][rangeB] = sumExpr[<c,p,a>][rangeA][rangeB];
    

    In fact, both alternatives require more memory and/or more processing.

    The issue happens only when trying to retrieve values of sumExpr from Java API or from OPL Script. It works as expected within other expressions and constraints in OPL.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Wed December 22, 2010 10:52 AM

    Originally posted by: DanielFelixFerber


    BTW, I have the feeling that often OPL does 'not understand' a statement that is expected as correct. The solution then is to rewrite another part of the model, on a trial and error.

    Not only this approach is quite time consuming, but also is also might require rewriting code that is already well understood, well tested and perhaps even in production. Applying a small enhancement on an existing larger model might become a nightmare if suddenly OPL does 'not understand' a dexpr anymore, as it happened to me.

    Best regards,
    Daniel Felix Ferber
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Sun September 01, 2013 03:48 PM

    Originally posted by: Puppy26


    Hi Alex,

    I got the same problem as above.

    In my case, I need to retrieve the sum of the supply in warehouse. The value will be in matrix form 5*5 and it should be multiplied by certain number(say for example 50).

     

    dexpr float DepotValue =  CDSupply [c][d]* DSCFixed;

    dexpr float RG = Revenue * ECDemanded;

    dexpr float TC  =  

     sum (d in Depots, t in Terminals) TermintoDepotCost [t][d] * TDSupply [t][d] +
     sum (t in Terminals, d in Depots) DepottoTerminCost [d][t] * DTSupply [d][t] + 
     sum( d in Depots) DepottoDepotCost[d][d] * DDSupply [d][d] + DepotValue;

    maximize RG-TC ;

    I need the program should find the value of CDSupply which will be matrix of 5*5  [[0 0 0 0 1][0 0 0 1 0][0 0 1 0 0][0 1 0 0 0][1 0 0 0 0]] and multiply it by 50 and feed the value to dexpr float TC to calculate.

    Could you please let me know how I should proceed further. 

    Many thanks!

    Regards,

    Prabhu


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 03:54 AM

    Hi,

     

    do not hesitate to attach your model.

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 04:06 AM

    Originally posted by: Puppy26


    Hi Alex,

    Please find the attachments for the code.

    I have rewrote the code like mentioned below. But still I couldn't get the value for DepotValue[c][d].

    dexpr float DepotValue[c in Consignees][d in Depots] = CDSupply[c][d] * DSCFixed;

    I'm still not getting the output for DepotValue[c][d] in the results section. Moreover If I add DepotValue[c][d] in TC, I'm getting error as "Index out of bound for array DepotValue" and another error as "OPL cannot extract expression: CDSupply [c][d]*50.

    Actually I need the final output of the calculation(like DepotValue[c][d]= 100).

    Many Thanks!

    Prabhu

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 04:41 AM

    Hi,

     

    your error is linked to a parenthesis problem in your model.

    You should replace

    sum( d in Depots) DepottoDepotCost[d][d] * DDSupply [d][d]+ DepotValue[c][d] ;

    by


     sum( d in Depots, c in Consignees) (DepottoDepotCost[d][d] * DDSupply [d][d]+ DepotValue[c][d]) ;

     

    in the TC dexpr expression

     

    regards

     

    Alex Fleischer


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 05:08 AM

    Originally posted by: Puppy26


    Hi Aöex,

    Thanks a lot. It works perfectly now.

    Just to add 1 more doubt. I tried to add few more parameters to DepotValue like

    dexpr float DepotValue[c in Consignees][d in Depots] = (ISDepot + CDSupply[c][d]+ TDSupply [t][d] - DSSupply [d][s] - DTSupply [d][t] - DDSupply [d][d]) * DSCFixed;

    I know I couldn't add them directly but I tried in some other way but I'm getting an error as index out of bound for TDSupply.

    Could you please help me in this regards.

    Many thanks in advance!

    Prabhu


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 05:16 AM

    Hi

     

    then you should write

    dexpr float DepotValue [c in Consignees] [d in Depots][t in Terminals] =  
    (ISDepot + CDSupply[c][d]+ TDSupply [t][d] - DSSupply [d][s] - DTSupply [d][t] - DDSupply [d][d]) * DSCFixed;

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 06:01 AM

    Originally posted by: Puppy26


    Hi Alex,

    thats really awesome Alex.. It works so perfect.

    Thanks a ton..

    Right now, I have developed the model for a single time period which means all the Depots are opened throughout the operation.

    Now, I want to model the project for multiple time period. say for example 6 months.

    My plan is to construct the model in such a way set of Depots(3 Depots out of 5 Depots) should be opened on all the time period of 6 months and last 2 depots should be opened for first 3 months and last 3 months the depots should be closed hence there won't be any supply from and to those closed depots in the last 3 months.

    I have been trying to model this for 3 weeks but getting errors always.

    Could you please help me. hope my above explanation is clear and If you want I can give you more explanation.

    Please do help me.

    Many thanks!

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon September 02, 2013 04:17 PM

    Originally posted by: Puppy26


    Hi,

    With some help, I played around the formula and found some solution for my above question but the results is partially correct and partially wrong.

    To limit the Depot opening, I used below equation.

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=2;

     

    In the result, It shows there is no movements between Consignees and Depots but in the case of movement between Depot and shipper, Depot and depot, I'm getting results as I expected. 

    In the case of Depot and Terminals, there is always some movements even though depot is closed. I'm going crazy with this results. Could you please look around the code I have attached and let me know where I made the mistakes.

    Many Thanks!

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 05:22 AM

    Hi,

     

    have you noticed that you get a relaxed solution and that some constraints have been relaxed since your model is not feasible ?

    To make a constraint a hard constraint do not use any label constraint for that constraint.

     

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 15.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 05:53 AM

    Originally posted by: Puppy26


    Hi Alex,

    yeah you're right.

    I get the relaxed solution when I include

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=2; this constraint.

     

    If I remove this constraint, the solution is perfect. Is there any other way to limit the opening of depot like I want the constraint to open only 3 depot out of 5 depots in the model.

     

    If the 2 depots are closed, there shouldn't be any movement from/to the closed depots.

     

    Any clue or tips will be very helpful.

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 16.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 06:09 AM

    Hi,

     

    instead of

    forall (c in Consignees, d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=5;

     

    I would simply write


        DepotLimit:
          sum (d1 in Depots) Open [d1]<=5;

     

    With your data, you seem to need 5 depots

     

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 17.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 06:18 AM

    Originally posted by: Puppy26


    Well, thanks for your feedback Alex but I need to limit the depot opening to 3 out of 5 Depots.

    I tried with your example but in the results it shows all the depots are opened. I want only 3 depots to be opened.

    Hope you understand this situation.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 18.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 07:34 AM

    Hi

    even if you remove all constraints and keep ony

    ctEachShipperHasOneDepot:

    ctUseDepottoShippers:

    and

    DepotLimit:

    the model is not feasible and you need to open 5 depots.

     

    Have you tried to turn

    forall (d in Depots)
          ctEachShipperHasOneDepot:
            sum (s in Shippers)
              DSSupply [d][s] ==1;

     

    into

    forall (s in Shippers)
          ctEachShipperHasOneDepot:
            sum (d in Depots)
              DSSupply [d][s] ==1;

     

    ?

     

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 19.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 07:48 AM

    Originally posted by: Puppy26


    Hi,

    Why is that it is not feasible to close few depots? How can I close two depots and turn off/cancel the corresponding links from/to those depots?

     

    If I turn around the Depots and Shippers as you mentioned, the result is not the one I expected. If I turn around, i'm getting result as one depot supply goods to two shippers which is wrong. I want one depot to supply one shipper.

    Is it my logic is wrong in the code?

    Please do correct me.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 20.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 08:07 AM

    well, you have to relax something, that is for sure.

     

    Would you agree with

     

    forall (c in Consignees)
         ctEachDepotHasOneConsignee:
           sum (d in Depots)
             CDSupply[c][d] <=1;
             
       
       forall (d in Depots)
          ctEachShipperHasOneDepot:
            sum (s in Shippers)
              DSSupply [d][s] <=1;
              
            forall (d in Depots)
          ctEachDepotHasOneDepot:
            sum (d1 in Depots)
              DDSupply [d][d1] <=1;

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 21.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 08:22 AM

    Originally posted by: Puppy26


    Hi,

    Well, thanks for your new idea. I tried as you mentioned.

    In this case, I'm getting the objective but my doubt is why there is no movements between Consginees and Depot? Also even though we gave DSSupply [d][s] <=1 like this why I'm getting single depot supplying two shippers. The result I got for DSSupply is [[0 1 1 0 0][0 0 0 1 0][0 0 0 0 0][0 0 0 0 0][1 0 0 0 1]].

    In all the possible case I tried, there is no movements between Consignees and Depots! Why is that?? If I dont limit the depot opening,I'm getting proper results for all the constraints. I get some strange answers only when I try to limit the depot opening using the constraint

    forall ( d in Depots)
        DepotLimit:
          sum (d1 in Depots) Open [d1]<=3;

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 22.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 11:35 AM

    Hi

    forall (d in Depots)
          ctEachShipperHasOneDepot:
            sum (s in Shippers)
              DSSupply [d][s] <=1;

     

    means all depots have maximum one supplier but this supplier can be for more than one depot.

    Unless you have a relaxed solution, a depot should not e used by 2 shippers


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 23.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Tue September 03, 2013 12:35 PM

    Originally posted by: Puppy26


    HI Alex,

    Thanks a lot for your feedback and it works well.. one more solution to this problem would be 

     

    forall(d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] <=1;

    and

    forall(d in Depots)

        ctUseContoDepot:

          sum (c in Consignees) CDSupply[c][d] <= Open [d];

    by

    forall(d in Depots)

         ctEachDepotHasOneConsignee:

           sum (c in Consignees)

             CDSupply[c][d] =Open [d];

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 24.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Wed September 04, 2013 09:24 AM

    Originally posted by: Puppy26


    Hi Alex,

    I have almost crossed all the steps in constructing the constraints and now got struck in the final stage of coding.

    Now my situation is like this

    Say for an example, I have 6 years of operations. In the first 3 years, all the three depots are opened and hence there are all the movements between consignees, shippers, depots and terminals.

    From the beginning of 4th years till 6th years, only 2 depots are opened which means 1 depot is closed and hence there is only movements for the opened depots.

    I just dont know how to construct the constraint for opening and closing of depots. The logic is once the depot is closed, it's closed forever. Right now, I have made it like

    Once closed, a mine stays closed

    forall (m in Mines, y in 1..NbYears-1)

    ctstaysclosed: Open[m][y]<=Open[m][y+1];

    But I'm not getting the result as I expect :(

    I have attached the model I have developed. Please do correct me if I'm wrong and advice me.

    Many thanks!!

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 25.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Sun April 02, 2017 10:36 PM

    Originally posted by: Hakeem-Ur-Rehman


    HI, everyone. 

    please help me.... I am getting the error; OPL cannot extract expression; in the following constraint...  

     

         forall (<j,l> in allproductstage:l<=L-1, t in macroperiods)
            WIP_Balancing: {   
              inventory[<j,l>][t-1] + sum(<s,t> in micro_macroperiods) productionquantity[<j,l>][<s,t>] == 
              inventory[<j,l+1>][t] + sum(<j,i> in immediatesuccessor, <s,t> in micro_macroperiods) 
              BOM[<j,i>]*productionquantity[<i,l+1>][<s,t>];
            }   

    with best regards,

    Hakeem-Ur-Rehman

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 26.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Mon April 03, 2017 01:03 AM

    Hi,

    you do a forall t in macroperiods but then you use t-1 as an index, this could lead to an out of scope.

    Can you try to change

    forall (<j,l> in allproductstage:l<=L-1, t in macroperiods)

    into

    forall (<j,l> in allproductstage:l<=L-1, t in macroperiods:(t-1) in macroperiods)

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 27.  Re: OPL cannot extract expression, OPL cannot extract model: Out of Scope Index

    Posted Wed April 05, 2017 12:16 AM

    Originally posted by: Hakeem-Ur-Rehman


    Thanks, Alex. I will try that 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer