RE: [AMPL 13918] Not "constant" objective function

16 views
Skip to first unread message

Robert Fourer

unread,
Apr 24, 2017, 9:30:13 AM4/24/17
to am...@googlegroups.com
Are you trying to specify a piecewise-linear function of variable firstA? There's an AMPL piecewise-linear notation that may help; see Chapter 17 of the AMPL book, http://ampl.com/BOOK/CHAPTERS/20-piecewise.pdf.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of czarek...@gmail.com
Sent: Saturday, April 22, 2017 7:40 PM
To: AMPL Modeling Language
Subject: [AMPL 13918] Not "constant" objective function

I would like to solve a task about minimizing cost of storing products. A part of objective function (which I minimize) looks as follows:

minimize f_celu: [....] 3.0*0.1*productionCostA[1]*100 + 3.0*0.15*productionCostA[1]*(firstA - 100) [....]

( productionCostA[1] = 54.97,
firstA is a production size - integer var )

The first summand is the cost of production of first 100 products and the second summand is the cost of production of the rest products.
But what when production will be less than 100?
I would like not to use something like that:

minimize f_celu: if firstA >= 100 then .... else ...
beacuse there are plenty of condtions.

Is there a better option to reach that?


czarek...@gmail.com

unread,
Apr 27, 2017, 2:45:15 PM4/27/17
to AMPL Modeling Language, 4...@ampl.com
Thank you for the link. I am reading the book, but I could not apply that to my task. Could you take a look on my model and tell my how should I rebuild it?
option solver cplex;
param productionCostA{1..3};
param productionCostB{1..3};


#Size of production of component A in first, second and third Monty (B analogical)
var productionA{1..3} integer;
var productionB{1..3} integer;


#minimizing cost = cost of production + cost of storing (0,1*productionCost for first 100 components + 0,15*productionCost for the rest components monthly) 
minimize f_celu: (sum{i in 1..3}productionA[i]*productionCostA[i]) + (sum{i in 1..3}productionB[i]*productionCostB[i]) + 3.0*0.1*productionCostA[1]*100 + 3.0*0.15*productionCostA[1]*(productionA[1] - 100) + 2.0*0.1*productionCostA[2]*100 + 2.0*0.15*productionCostA[2]*(productionA[2] - 100) + 0.1*productionCostA[3]*100 + 0.15*productionCostA[3]*(productionA[3] - 100) + 3.0*0.1*productionCostB[1]*100 + 3.0*0.15*productionCostB[1]*(productionB[1] - 100) + 2.0*0.1*productionCostB[2]*100 + 2.0*0.15*productionCostB[2]*(productionB[2] - 100) + 0.1*productionCostB[3]*100 + 0.15*productionCostB[3]*(productionB[3] - 100);



#sense
subject to sens1: productionA[1] >= 0;
subject to sens2: productionA[2] >= 0;
subject to sens3: productionA[3] >= 0;
subject to sens4: productionB[1] >= 0;
subject to sens5: productionB[2] >= 0;
subject to sens6: productionB[3] >= 0;



#To produce component A and B, there are needed some resources (Z1 and Z2). Below, there are constraints which reffer to availability of resources in first, second and third month. 

subject to supplyZ1first: 0 <= 0.2*productionA[1] + 0.7*productionB[1] <= 600;
subject to supplyZ1second: 0 <= 0.2*productionA[2] + 0.7*productionB[2] <= 700;
subject to supplyZ1third: 0 <= 0.2*productionA[3] + 0.7*productionB[3] <= 550;

subject to supplyZ2first: 0 <= 0.8*productionA[1] + 0.3*productionB[1] <= 1400;
subject to supplyZ2second: 0 <= 0.8*productionA[2] + 0.3*productionB[2] <= 900;
subject to supplyZ2third: 0 <= 0.8*productionA[3] + 0.3*productionB[3] <= 1200;


#Constraints which refer to number of components company has to produce in 3 months
subject to dealA: sum{i in 1..3}productionA[i] >= 1100;
subject to dealB: sum{i in 1..3}productionB[i] >= 1200;




data;
param productionCostA:=
1    54.97
2    40.0
3    49.95;

param productionCostB:=
1    35.31
2    44.94
3    31.32;

Kind regards,
Czarek

Robert Fourer

unread,
Apr 28, 2017, 9:38:58 AM4/28/17
to am...@googlegroups.com
You can use AMPL's piecewise-linear notation to express

0.1 * productionCost for first 100 components +
0.15 * productionCost for the rest of the components

as

<<100; 0.1,0.15>> productionCost

where productionCost is a variable that is defined to be >= 0. In your objective function you will need several terms like this, for variables productionCostA[1], productionCostA[2], etc.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of czarek...@gmail.com
Sent: Thursday, April 27, 2017 1:45 PM
To: AMPL Modeling Language
Cc: 4...@ampl.com
Subject: Re: [AMPL 13949] Not "constant" objective function

Thank you for the link. I am reading the book, but I could not apply that to my task. Could you take a look on my model and tell my how should I rebuild it?

option solver cplex;
param productionCostA{1..3};
param productionCostB{1..3};

#Size of production of component A in first, second and third Monty (B analogical)
var productionA{1..3} integer;
var productionB{1..3} integer;

#minimizing cost = cost of production + cost of storing (0,1*productionCost for first 100 components + 0,15*productionCost for the rest components monthly)
minimize f_celu: (sum{i in 1..3}productionA[i]*productionCostA[i]) + (sum{i in 1..3}productionB[i]*productionCostB[i]) + 3.0*0.1*productionCostA[1]*100 + 3.0*0.15*productionCostA[1]*(productionA[1] - 100) + 2.0*0.1*productionCostA[2]*100 + 2.0*0.15*productionCostA[2]*(productionA[2] - 100) + 0.1*productionCostA[3]*100 + 0.15*productionCostA[3]*(productionA[3] - 100) + 3.0*0.1*productionCostB[1]*100 + 3.0*0.15*productionCostB[1]*(productionB[1] - 100) + 2.0*0.1*productionCostB[2]*100 + 2.0*0.15*productionCostB[2]*(productionB[2] - 100) + 0.1*productionCostB[3]*100 + 0.15*productionCostB[3]*(productionB[3] - 100);

.......


Reply all
Reply to author
Forward
0 new messages