Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Piecewise- cannot extract expression

    Posted 03/24/15 06:41 PM

    Originally posted by: Chipper


    Hi,

    I am trying to use the piecewise functionality, but I get this error:

    Description Resource Path Location Type
    CPLEX(default) cannot extract expression: forall(m in 1..5, p in PRODUCTS, t in TERMINALS, cp in PARTNERS) TotalCost[(m)][p][t][cp] ==
    piecewise (i in 1..2) { TierPrice_Breakpoints[(m)][p][t][cp][i] -> Tier_Breakpoints[(m)][p][t][cp][i]; TierPrice_Breakpoints[(m)][p][t][cp][3] }(0,0) Total_Mass[(m)][p][t][cp].

     

    This is the part of the code where I am using the piecewise:

    forall (m in Months, p in Products, t in Terminals, cp in Partners) {
      TotalCost[m][p][c][cp]== piecewise(i in 1..n){TierPrice_Breakpoints[m][p][t][cp][i]->Tier_Breakpoints[m][p][t][cp][i];
               TierPrice_Breakpoints[m][p][t][cp][n+1]}(0,0)(Total_Mass[m][p][t][cp]);
    }

    Where TotalCost[m][p][c][cp] is a decision variable, and Total_Mass[m][p][t][cp] too.

    What am I doing wrong? If I use stepwise instead of piecewise (and removing the (0,0), the code is working ok.

    Any help will be appreciate.

    Thanks!


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Piecewise- cannot extract expression

    Posted 03/24/15 08:00 PM

    Originally posted by: EdKlotz


    I don't see any obvious mistake, but I suggest that you start simple and work up to those 4 and 5 dimensional indices.  Try getting it to work with Total Costs that just depend on m, then m and p, and so on.  Try simplifying the expression by replacing the assignment to the TotalCost decision variable with just a minimize statement.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Piecewise- cannot extract expression

    Posted 03/25/15 01:41 AM

    Originally posted by: Chipper


    Thanks so much! I am still trying to make it works :$

    Any advice or idea on how to use the piecewise /stepwise functionality, if I want to apply different production cost to different tier? I mean, I have defined 5 tiers, each one has a linear cost associated. I need to consider two types of cost:

    - In function of the production volume (in which tier it is), the cost of that tier will apply to the whole production volume.

    Cost_Production=piecewise (i in 1..4) {Cost (i) -> Tier (i); Cost(5)} Production_Vol;

    - In this case I need to apply the cost of each tier, instead of the final tier. I mean, If the Production_Vol optimal is in the third tier, I need to apply the Cost 1 for the volume up to the Tier 1; plus Cost 2 for the volume (Tier 2-Tier1) plus the Cost 3 for the (Production_Vol - Tier3).

    I am struggling trying to find a formulation, so any help or advice will be welcome.

    Can I use a stepwise to get which is the tier optimal (max_tier) . And use it in a filter to calculate the volume in each tier, so I can  multiply for the inputs cost directly in a decision expression variable?

    MaxDelta== stepwise(i in 1..n){i->TIER_Breakpoints[i];(n+1)} Vol_Step;
      

    forall(i in Tier: i==1){
        Vol_tier_Step[i] == minl(TIER_Breakpoints[i],Vol_Step);
    }   
    forall(i in Tier: i<=MaxDelta && i>=1){
            Vol_tier_Step[i] == (minl(TIER_Breakpoints[i],Vol_Step)-TIER_Breakpoints[i-1]);      
    }

    Thanks.

    Regards!


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: Piecewise- cannot extract expression

    Posted 03/25/15 02:12 AM

    Since this seems to be an OPL syntax problem you may also want to try to raise your problem on the Forum dedicated to OPL.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: Piecewise- cannot extract expression

    Posted 03/25/15 02:24 AM

    Originally posted by: Chipper


    Thanks, and sorry to ask in the wrong forum. I am new here.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: Piecewise- cannot extract expression

    Posted 03/25/15 02:50 AM

    No problem at all.

    Could it be that there is something wrong with your data and that causes the extraction error? I have modified the example provided here to match your case and everything seems to work fine:

    range Months = 1..2;
    range Products = 1..2;
    range Terminals = 1..2;
    range Partners = 1..2;
    
    int n=2;
    
    float breakpoint[Months][Products][Terminals][Partners][1..n]=[[[[[100,200],[100,200]],[[100,200],[100,200]]],
                                                                    [[[100,200],[100,200]],[[100,200],[100,200]]]],
                                                                   [[[[100,200],[100,200]],[[100,200],[100,200]]],
                                                                    [[[100,200],[100,200]],[[100,200],[100,200]]]]];
    float slope[Months][Products][Terminals][Partners][1..n+1]=[[[[[1,2,-3],[1,2,-3]],[[1,2,-3],[1,2,-3]]],
                                                                 [[[1,2,-3],[1,2,-3]],[[1,2,-3],[1,2,-3]]]],
                                                                [[[[1,2,-3],[1,2,-3]],[[1,2,-3],[1,2,-3]]],
                                                                 [[[1,2,-3],[1,2,-3]],[[1,2,-3],[1,2,-3]]]]];
    dvar float x[Months][Products][Terminals][Partners];
    dvar float y[Months][Products][Terminals][Partners];
    
    maximize sum(m in Months,p in Products,t in Terminals,cp in Partners) y[m][p][t][cp]; 
    
    subject to
    {
      forall(m in Months,p in Products,t in Terminals,cp in Partners) {
        y[m][p][t][cp] == piecewise(i in 1..n) 
          {slope[m][p][t][cp][i] -> breakpoint[m][p][t][cp][i]; slope[m][p][t][cp][n+1]}(0,0) x[m][p][t][cp];
      }    
    }
    

    Maybe you can start from this code snippet, transform it to yours step by step and see where things go wrong? Or check whether you can spot a significant difference to your code?

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: Piecewise- cannot extract expression

    Posted 03/27/15 12:43 AM

    Originally posted by: Chipper


    Thanks Daniel.

    It looks very similar, so I need to spend time checking what is wrong in the data probably.

    I appreciate your feedback!

    Cheers! 


    #DecisionOptimization
    #MathematicalProgramming-General