Sunteți pe pagina 1din 8

a more advanced way to solve this in AMPL is as follows.

First, create a model (say model.mod):

set COLOR = {"Cyan","Magenta","Yellow"};


param
param
param
param
param
param

stage1_req {COLOR} >=0;


stage2_req {COLOR} >=0;
demand {COLOR} >=0;
profit {COLOR} >=0;
stage1_avail >=0;
stage2_avail >=0;

var x {COLOR} >= 0;


maximize Total_Profit: sum {p in COLOR} profit[p]*x[p];
demand_Cap{p in COLOR}: x[p] <=demand[p];
subject to stage1_Cap: sum {p in COLOR} stage1_req[p]*x[p] <=stage1_avail;
subject to stage2_Cap: sum {p in COLOR} stage2_req[p]*x[p] <=stage2_avail;

Then, create a data file (say data.dat):


param:
"Cyan"
"Magenta"
"Yellow"

stage1_req stage2_req
demand
profit:=
0.53
0.55
80000
0.72
0.52
0.57
97000
0.79
0.4
0.54
99000
0.75;

param stage1_avail= 72000;


param stage2_avail= 75600;

Finally, type this in the console:


model model.mod;
data data.dat;
solve;
display x, Total_Profit;

To maximize this function using summation notation in SAS, use this code:

proc optmodel;
set Color={'c','m','y'};

set Stage={'s1','s2'};
number ProcessTime{Color,Stage}=
[0.53 0.55
0.52 0.57
0.4 0.54];
number AvailableTime{Stage}=[72000 75600];
number Demand{Color}=[80000 97000 99000];
number Profit{Color}=[0.720 0.790 0.75];
var Amount{Color} >= 0;
maximize TotalProfit = sum{i in Color}Profit[i]*Amount[i];
con TimeConst{j in Stage}: sum{i in
Color}Amount[i]*ProcessTime[i,j]<=AvailableTime[j];
con DemandConst{i in Color}: Amount[i]<=Demand[i];
solve;
print Amount;
quit;

and then hit the run button at the top of the window.

Explanation
The simplest way to solve this in AMPL is to type this code in the console:

var x1 >= 0 ;
var x2 >= 0 ;
var x3 >= 0 ;
maximize Profit: 20*x1+15*x2+17*x3 (0.49*(3.1*x1+10.0*x2+5.6*x3)+0.84*(9.4*x1+8.2*x2+1.1*x3));
subject to time_Cap_M1: (3.1*x1+10.0*x2+5.6*x3)<=480;
subject to time_Cap_M2: (9.4*x1+8.2*x2+1.1*x3)<=540;
solve ;
display x1, x2, x3, Profit;

The simplest way to solve this in SAS is to use this code:

proc optmodel;
var x1 >= 0 ;
var x2 >= 0 ;
var x3 >= 0 ;
maximize Profit= 20*x1+15*x2+17*x3 (0.49*(3.1*x1+10.0*x2+5.6*x3)+0.84*(9.4*x1+8.2*x2+1.1*x3));
con time_Cap_M1: (3.1*x1+10.0*x2+5.6*x3)<=480;
con time_Cap_M2: (9.4*x1+8.2*x2+1.1*x3)<=540;
solve ;
print x1 x2 x3 Profit;
quit;

and then hit the run button at the top of the window.

A more advanced way to solve this in AMPL is as follows.

First, create a model (say model.mod):

set PRODUCTS = {"P1","P2","P3"};


set MACHINE = {"M1","M2"};
param
param
param
param

operating_time {PRODUCTS,MACHINE} >=0;


cost {MACHINE} >=0;
time_avail {MACHINE} >=0;
price {PRODUCTS} >=0;

var X {PRODUCTS} >= 0;


maximize Total_Profit: (sum {p in PRODUCTS} price[p]*X[p])-(sum {m in MACHINE}
cost[m]*(sum{p in PRODUCTS}operating_time[p,m]*X[p]));
time_Cap{m in MACHINE}:sum{p in PRODUCTS}
operating_time[p,m]*X[p]<=time_avail[m];

Then, create a data file (say data.dat):


param operating_time: "M1" "M2" :=
"P1"
3.1
9.4
"P2"
10.0
8.2
"P3"
5.6
1.1
;
param:
"M1"
"M2"

cost time_avail:=
0.49
480
0.84
540;

param:
"P1"
"P2"
"P3"

price
20
15
17 ;

:=

Finally, type this in the console:


model model.mod;
data data.dat;
solve;
display X, Total_Profit;

To maximize this function using summation notation in SAS, use this code:

proc optmodel;
set PRODUCTS = {'P1','P2','P3'};

set MACHINE = {'M1','M2'};


number operating_time {PRODUCTS,MACHINE}=
[3.1 9.4
10.0 8.2
5.6 1.1];
number cost {MACHINE}=
[0.49 0.84];
number time_avail {MACHINE}=
[480 540];
number price {PRODUCTS}=
[20
15
17];
var X {PRODUCTS} >= 0;
maximize Total_Profit= (sum {p in PRODUCTS} price[p]*X[p])-(sum {m in MACHINE}
cost[m]*(sum{p in PRODUCTS}operating_time[p,m]*X[p]));
con time_Cap{m in MACHINE}: sum{p in PRODUCTS}
operating_time[p,m]*X[p]<=time_avail[m];
solve;
print X;
quit;

A very simple way to solve this problem in AMPL is to use the following code:

reset;
option solver gurobi;
var x1 integer >=0;
var x2 integer >=0;
maximize z: 8*x1+20*x2;
s.t. c1: x1+x2<=11;
s.t. c2: 3*x1+2*x2<=30;
s.t. c3: 1*x1+3*x2<=28;
solve;
display x1, x2, z;

The answers we are looking for are obtained, then, by multiplying x1 and x2 by 10, and
multiplying z by 100.

A very simple way to solve this problem in SAS is to use this code:

proc optmodel;
var x1 integer >=0;
var x2 integer >=0;
maximize z= 8*x1+20*x2;
con c1: x1+x2<=11;
con c2: 3*x1+2*x2<=30;
con c3: 1*x1+3*x2<=28;
solve;
print x1 x2 z;
quit;

The answers we are looking for are obtained, then, by multiplying x1 and x2 by 10, and
multiplying z by 100.

A more sophisticated way to solve this in AMPL, defining lot size as a variable that can be
changed later down the line, would be as follows:

reset;
option solver gurobi;
param lot = 10;
var XHL integer >=0;
var XSL integer >=0;
var XH = XHL * lot;
var XS = XSL * lot;
maximize Z: (80/lot)*XHL+(200/lot)*XSL;
s.t. Plant: XHL+XSL<=(110/lot);
s.t. A: 3*XHL+2*XSL<=(300/lot);
s.t. B: 1*XHL+3*XSL<=(280/lot);
solve;
display XH, XS;
display Z * lot ^ 2;

This gives us a value of 10 for


, 90 for

, and 18800 for the profit (given by Z * lot ^ 2).

A more complex way to solve this problem in SAS is to use this code:

proc optmodel;
number lot = 10;
var XHL integer >=0;

var XSL integer >=0;


impvar XH = XHL * lot;
impvar XS = XSL * lot;
maximize Z= (80/lot)*XHL+(200/lot)*XSL;
con Plant: XHL+XSL<=(110/lot);
con A: 3*XHL+2*XSL<=(300/lot);
con B: 1*XHL+3*XSL<=(280/lot);
impvar ZZ = Z*lot^2;
solve;
print XH XS;
print ZZ;
quit;

To solve this problem in AMPL, we can use the code from the previous question, but using a
value of 5 for the lot size. So, instead of...

param lot = 10;

...we would use...

param lot = 5;

This gives us a value of 25 for


, 85 for and 19000 for the profit.

S-ar putea să vă placă și