Decision Optimization

Decision Optimization

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

 View Only
  • 1.  piecewise function

    Posted Tue July 31, 2012 02:12 AM

    Originally posted by: CDN3_Daniel_Cramer


    Hello there,

    I got a problem using the discontinuous piecewise-linear function...

    dvar float x;
    dvar float signx;
     
    minimize signx;
       subject to {
     
       x == 5;
       signx == piecewise{0->0; 4->0; 0->10; -0.5->10; 0->20; -0.75->20; 0} (0,0) x;
    }
    


    I want to model sales discount. A discount should be allowed after reaching a limit in the function.
    For an amount of 5 - the price should be 4 and the whole costs 20.
    For an amount of 15 - the price should be 3.5 and the whole costs 52.5.
    and so on...

    But there is a mistake -- I am not able to realize, that the function starts in (0,0).
    Otherwise, the amount of the objective isn't right, too...

    Do you have any conclusions??

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: piecewise function

    Posted Tue July 31, 2012 05:54 AM

    Originally posted by: CDN3_Daniel_Cramer


    After hours, I implemented the example in the help file...
    mod
    
    
    {string
    } products   = ...; 
    {
    
    int
    }    time       = ...;   
    
    int   NBdiscount = ...; 
    
    float discount[products][1..NBdiscount] = ...; 
    
    float breakpoint[products][1..NBdiscount-1] = ...;   
    
    float d[products][time]       = ...; 
    
    float s[products]                         = ...; 
    
    float h[products]                       = ...; 
    
    float g[products]                       = ...;   
    
    float Wert[k in products]   = sum(t in time) d[k][t];   dvar int+           q[products][time]; dvar int+                y[products][time]; dvar 
    
    boolean      gamma[products][time];   dexpr 
    
    float Lagerkosten = sum(k in products, t in time) (h[k] * y[k][t]); dexpr 
    
    float Versandkosten = sum(k in products, t in time) (s[k] * gamma[k][t]); dexpr 
    
    float Bestellpreis = sum(t in time, k in products) piecewise (i in 1..NBdiscount-1) 
    { discount[k][i] -> breakpoint[k][i]; discount[k][NBdiscount] 
    } (5,4) q[k][t];   minimize Lagerkosten + Versandkosten + Bestellpreis;   subject to 
    { forall(k in products, t in time) q[k][t] <= Wert[k] * gamma[k][t];   forall(k in products, t in time : t > 0) y[k][t-1] + q[k][t] - y[k][t] == d[k][t];   forall (k in products) y[k][0] == d[k][0];   forall (k in products) q[k][0] == 0; 
    };
    


    dat
    
    products = 
    { 
    "12" 
    }; time = 
    {0 1 2 3 4 5 6 7 8 9 10 11 
    };   NBdiscount = 7;   discount = #[ 
    "12"   : #[1:0 2:4 3:0 4:-0.5 5:0 6:-0.75 7:0]#]#; breakpoint = #[ 
    "12"   : #[1:0 2:0 3:100 4:100 5:500 6:500]#]#;   g = [2,]; s = [1]; h = [0.05];   d = #[
    "12" :  #[0:0 1:0 2:0 3:0 4:500 5:0 6:0 7:0 8:100 9:0 10:0 11:0]#      ]#;
    


    q is a dvar int+ and should be multiplied with the value in the discontinous piecewise-function.
    OPL chooses the right value from the .dat - but it isn't multiplied with q...
    Any tips?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: piecewise function

    Posted Thu August 02, 2012 12:11 PM
    Hi,

    q is the parameter in the pwl function. When q moves, then the pwl moves. This is not a multiplication by q.

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer