Homework_3_20659318_HW3_IP

advertisement
Hai HW3
Problem 11.8
#Problem 11.8, set packing example
option solver cplex;
var Xames binary;
var Xbeloit binary;
var Xnormal binary;
var Xavon binary;
maximize totalprofit: 115 * (Xames)+ 90 * (Xbeloit)+ 150 * (Xnormal) + 126 * (Xavon);
subject to SalesMN: Xames + Xbeloit = 1;
subject to SalesIA: Xames + Xbeloit + Xnormal = 1;
subject to SalesMO: Xames + Xnormal = 1;
subject to SalesWI: Xbeloit + Xnormal = 1;
subject to SalesIN: Xnormal + Xavon =1;
subject to SalesKY: Xavon = 1;
solve;
display Xames, Xbeloit, Xavon, Xnormal,totalprofit > Output5.txt;
Solution
Xames = 0
Xbeloit = 1
Xavon = 1
Xnormal = 0
totalprofit = 216
Problem 11.10
option solver cplex;
# variables for Ames location for states: MN, IA, and MO
var MTu binary;
var MW binary;
var MF binary;
var TuW binary;
var TuF binary;
var ThF binary;
minimize totalcost: 300 * (MTu + MW + TuW + ThF) + 500 * ( MF + TuF);
Page 1 of 5
Hai HW3
subject to Monday: MTu + MW + MF >= 1;
subject to Tuesday: MTu + TuW + TuF >= 1;
subject to Wednesday: MW + TuW >= 1;
subject to Thursday: ThF >= 1;
subject to Friday: MF + TuF + ThF >= 1;
solve;
display MTu, MW, MF, TuW, TuF, ThF, totalcost> Output2.txt;
Solution
MTu = 1
MW = 1
MF = 0
TuW = 0
TuF = 0
ThF = 1
totalcost = 900
Problem 11.10 Part (c&d)
option solver cplex;
# added y variables represent the days uncovered. If y=1 that means that day wasn't covered with a
model. The idea is to min the total days uncovered.
var MTu binary;
var MW binary;
var MF binary;
var TuW binary;
var TuF binary;
var ThF binary;
var y1 binary;
var y2 binary;
var y3 binary;
var y4 binary;
var y5 binary;
minimize DaysUncovered: y1 + y2 + y3 + y4 + y5;
subject to Max2Models: MTu + MW + MF + TuW + TuF + ThF= 2;
subject to Monday: MTu + MW + MF + y1 >= 1;
subject to Tuesday: MTu + TuW + TuF + y2 >= 1;
subject to Wednesday: MW + TuW + y3 >= 1;
subject to Thursday: ThF + y4 >= 1;
subject to Friday: MF + TuF + ThF + y5 >= 1;
solve;
display MTu, MW, MF, TuW, TuF, ThF, DaysUncovered> Output3.txt;
Solution
MTu = 0
MW = 0
MF = 0
TuW = 1
Page 2 of 5
Hai HW3
TuF = 0
ThF = 1
DaysUncovered = 1
Problem 11.12
option solver cplex;
# binary variables for all the existing arcs. Ones that are not possible according to the table, not included
in model.
var X11 binary;
var X12 binary;
var X24 binary;
var X25 binary;
var X32 binary;
var X33 binary;
var X43 binary;
var X44 binary;
var X51 binary;
var X53 binary;
var X61 binary;
var X62 binary;
var X65 binary;
minimize deviation: 0.5 *(X11 + X12) + 0.5 * (X24 + X25)+ 0.6 * (X32 + X33) + 1.3 * (X43 + X44) + 0.7 *
(X51 + X53) + 1.2 * ( X61 + X62 + X65);
subject to C1: X11+X51+X61=1;
subject to C2: X12+X32+X62=1;
subject to C3: X33+X43+X53=1;
subject to C4: X24+X44=1;
subject to C5: X25+X65=1;
solve;
display X11,X12,X24,X25,X32,X33,X43,X44,X51,X53,X61,X62,X65,deviation > Output4.txt;
Solution
X11 = 1
X12 = 1
X24 = 1
X25 = 1
X32 = 0
X33 = 1
X43 = 0
X44 = 0
X51 = 0
X53 = 0
X61 = 0
X62 = 0
X65 = 0
deviation = 2.6
Problem 11.28
Page 3 of 5
Hai HW3
# The X variable represents the amount of units produced for that particular quarter.
option solver cplex;
var P1 >=0, <=50;
var P2 >=0, <=50;
var P3 >=0, <=50;
var P4 >=0, <=50;
# I variables indicate the inventory left at the end of the quarter, and going to the next. Notice, there is
no
# var for I4 since the assumption is that there is no beg inventory and no ending
var I1 >=0;
var I2 >=0;
var I3 >=0;
var B1 binary;
var B2 binary;
var B3 binary;
var B4 binary;
minimize cost: 100*(I1 + I2 + I3)+200*(P1 + P2 + P3 + P4)+ 2000 * (B1 + B2 + B3 + B4);
subject to Q1: P1-I1 >= 40;
subject to Q2: I1 + P2 - I2 >= 20;
subject to Q3: I2 + P3 - I3 >= 60;
subject to Q4: I3 + P4 >= 15;
subject to LineUsedQ1: P1 <= 50 * B1;
subject to LineUsedQ2: P2 <= 50 * B2;
subject to LineUsedQ3: P3 <= 50 * B3;
subject to LineUsedQ4: P4 <= 50 * B4;
solve;
display P1,P2,P3,P4,I1,I2,I3, B1,B2,B3,B4,cost > Output6.txt;
Solution
P1 = 40
P2 = 30
P3 = 50
P4 = 15
I1 = 0
I2 = 10
I3 = 0
B1 = 1
Page 4 of 5
Hai HW3
B2 = 1
B3 = 1
B4 = 1
cost = 36000
Page 5 of 5
Download