Piecewise linear purchasing models

30 views
Skip to first unread message

chrisn...@hotmail.com

unread,
Sep 15, 2017, 1:57:33 PM9/15/17
to AMPL Modeling Language
Dear AMPL Community,

I am trying to develop a piecewise linear purchasing model, and I am facing two difficulties that I have been unable to solve up until now. 

Iwant the below objective function to be interpreted by AMPL as follows:

if the sum {g in G, t in T, u in CC,p in P} x[g,t,u,p]  >= parameter CC_threshold1, cost parameter r2_cogs[u,g] will be activated for all volume between parameters CC_threshold1 and CC_threshold2. For volume up until CC_threshold1, cost parameter r1_cogs[u,g] will apply. 

minimize total_cost: 
(sum {g in G, t in T, u in CC, p in P} ((<<CC_threshold1, CC_threshold2; r1_cogs[u,g], r2_cogs[u,g], r3_cogs[u,g]>> x[g,t,u,p]) + (x[g,t,u,p]*shipping[u,p]))* (1 + dues[u,p])) ;

I am basing the construction of my piecewise linear objective function on Figure 17-2: Piecewise-linear model with three slopes (transpl1.mod) of the AMPL user guide.
In the example given by AMPL, the "limit" or "threshold" parameters are given for all origin and distance combinations. This is different from my model in that I have a "total" limit where the idea is that if I reach a total threshold figure of CC_threshold1, a discount to my cost parameter will be applicable. 


A second objective that I am trying to accomplish is to activate a "total" discount scheme.

What I mean by this is that I want AMPL to interpret the below as follows:

if the sum {g in G, t in T, u in AC,p in P} y[g,t,u,p] >= parameter CC_threshold 2, cost parameter r3_cogs[u,g] will be applicable to all volume in y[g,t,u,p]. How can I accomplish this? 

(sum {g in G, t in T, u in AC, p in P} ((<<AC_threshold1, AC_threshold2; r1_cogs[u,g], r2_cogs[u,g], r3_cogs[u,g]>> y[g,t,u,p]) + (y[g,t,u,p]*shipping[u,p]))* (1 + dues[u,p]))

All the best from Chris 

Robert Fourer

unread,
Sep 18, 2017, 6:20:01 PM9/18/17
to am...@googlegroups.com

You can only apply the piecewise-linear notation <<...;...> to a variable.  But you can introduce a new variable that is constrained to equal a sum, and then apply the piecewise-linear notation to that variable.  As an example if you define

   var sumx;
   subject to sumxdef:
      sumx = sum {g in G, t in T, u in CC,p in P} x[g,t,u,p];

then your objective function can include a piecewise-linear function of sumx.

Bob Fourer
am...@googlegroups.com


Chris Nytun

unread,
Sep 20, 2017, 3:03:19 AM9/20/17
to AMPL Modeling Language
HI Bob,

Thanks for this. 
Say that I have now have the following piece- wise linear model:

var x {g in G, t in T, u in U, p in P} >= 0;    
var CC_total;
var CC_total2;

param CC_threshold;    
param CC_threshold2; 

param CC_penalty;      
param CC_penalty2;  
param CC_default_penalty, default 0; 

minimize total_cost:
(<<CC_default; CC_default_penalty, CC_penalty>> CC_total)        
+ (<<CC_default; CC_default_penalty, CC_penalty2>> CC_total2)
;
subject to CC_definition:
CC_total= CC_threshold - sum{g in G, t in T, u in CC, p in P} x[g,t,u,p];

subject to CC2_definition:
CC_total2= CC_threshold2 - sum{g in G, t in T, u in CC, p in P} x[g,t,u,p];

I now wish to ensure that that the penalty scheme applied above through the piece- wise linear functions are non- stacking. If x hits a value up until CC_threshold, only the first piece-wise function will activate. From CC_threshold up until CC_threshold 2, only the second piece-wise function will activate.

CC_threshold2 will always be > than CC_threshold. 

My best guess would be that I could accomplish this through the use of binary variables. Just no sure how. 

Thanks!

Chris

Robert Fourer

unread,
Sep 21, 2017, 11:02:57 AM9/21/17
to am...@googlegroups.com
It seems your objective is a function of "sum {g in G, t in T, u in CC, p in P} x[g,t,u,p]". Can you give a clearer description of this function? For instance "from 0 to brk1 it is linear with slope slp1, then from brk1 up to brk2 it continues linearly with slope slp2," etc. Or even draw a graph of the function. Your description in terms of non-stacking and activating is hard to follow because it only indirectly describes the function.

If your function turns out to be continuous then an AMPL piecewise-linear expression should suffice. But if it has a jump at some value of the sum, then you are likely to need a binary variable.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Chris Nytun
Sent: Wednesday, September 20, 2017 2:03 AM
To: AMPL Modeling Language
Reply all
Reply to author
Forward
0 new messages