Happy Milk example with concave cost functions 10/21/01 19:55:55 PAGE 1 GAMS Rev 121 Linux/Intel 2 3 option limrow=0, limcol=0; 4 5 * abscissae and ordinates of the piecewise-linear cost function 6 set pieces /1*3/; 7 8 set region /A,B/ 9 milkType /raw,hifat,lofat/ 10 costfuncDefs /grad1, grad2, break, maxmilk/ 11 productType /cream, milk/ 12 13 table butterfat(region,milkType) 14 raw hifat lofat 15 A .05 .80 .01 16 B .035 .80 .005; 17 18 19 * cost DECREASES after the breakpoint; cannot use an LP model 20 21 table costfunc(region,costfuncDefs) 22 grad1 grad2 break maxmilk 23 A .56 .555 500 5000 24 B .44 .43 700 5000; 25 26 * define the piecewise linear cost functions via abscissae and ordinates 27 28 parameter Xpurchase(region,pieces), Xcost(region,pieces); 29 loop(region, 30 Xpurchase(region,'1') = 0; 31 Xcost(region,'1') = 0; 32 Xpurchase(region,'2') = costfunc(region,'break'); 33 Xcost(region,'2') = costfunc(region,'break') * costfunc(region,'grad1'); 34 Xpurchase(region,'3') = costfunc(region,'maxmilk'); 35 Xcost(region,'3') = Xcost(region,'2') + 36 costfunc(region,'grad2')*(Xpurchase(region,'3') - Xpurchase(region,'2')); 37 ) 38 39 display Xcost, Xpurchase; 40 41 parameter 42 separationCost(region) / A .05, B .06 / 43 maxDemand(productType) / cream 300, milk 2000 / 44 minRichness(productType) / cream .50, milk .02 / 45 prices(productType) / cream 4.50, milk .80 /; 46 47 sos2 variables gamma(region,pieces); 48 variables 49 purchase(region) 50 amtsAfterSeparation(region,milkType) 51 amtsMixed(region,milkType,productType) 52 amtProduct(productType), 53 saleableProduct(ProductType), 54 purchaseCost(region), 55 totalCost, 56 sales, 57 profit; 58 59 positive variable purchase, 60 amtsAfterSeparation, amtsMixed, amtProduct, 61 saleableProduct, purchaseCost, totalCost, sales; 62 63 equations 64 EQpiecewise(region) constraints on the SOS2 65 EQpurchase(region) figure purchase from the pieces 66 EQcost(region) figure purchase cost 67 fatConservationSeparation(region) fat conserved in separation 68 volumeConservationSeparation(region) volume conserved in separation 69 volumeMixed(region,milkType) mix at most what's available 70 totalProduct(productType) volume of each final product 71 qualityProduct(productType) min fat content of final product 72 howMuchCanYouSell(productType) amt sold may be <= amt produced 73 productionCost total cost of production 74 revenue sales revenue 75 objective; 76 77 * constraints on the SOS2 variabes that model the piecewise linear function 78 EQpiecewise(region).. 79 sum(pieces, gamma(region,pieces)) =e= 1; 80 81 EQpurchase(region).. 82 purchase(region) =e= 83 sum(pieces, gamma(region,pieces)*Xpurchase(region,pieces)); 84 85 EQcost(region).. 86 purchaseCost(region) =e= 87 sum(pieces, gamma(region,pieces)*Xcost(region,pieces)); 88 89 * ensure that the total amount of fat in the products of separation equals 90 * the total fat in the raw milk purchased 91 92 fatConservationSeparation(region).. 93 purchase(region)*butterfat(region,"raw") =e= sum(milkType, 94 amtsAfterSeparation(region,milkType) * butterfat(region,milkType)); 95 96 * ensure that volume is conserved in separation 97 98 volumeConservationSeparation(region).. 99 purchase(region) =e= sum(milkType, amtsAfterSeparation(region,milkType)); 100 101 * ensure that the amounts of separated product contributed to 102 * final product satisfy a volume conservation constraint 103 104 volumeMixed(region,milkType).. 105 sum(productType, amtsMixed(region,milkType,productType)) =l= 106 amtsAfterSeparation(region,milkType); 107 108 * calculate the amount of each final product 109 110 totalProduct(productType).. 111 amtProduct(productType) =e= sum((region,milkType), 112 amtsMixed(region,milkType,productType)); 113 114 * ensure that each final product has the required content of fat 115 116 qualityProduct(productType).. 117 sum((region,milkType), 118 butterfat(region,milkType) * amtsMixed(region,milkType,productType)) 119 =g= minRichness(productType) * amtProduct(productType); 120 121 * from the amounts produced, extract the (possibly smaller) amount 122 * that can actually be sold. 123 124 howMuchCanYouSell(productType).. 125 saleableProduct(productType) =l= amtProduct(productType); 126 127 * get total cost by adding purchase cost to separation cost 128 productionCost.. 129 totalCost =e= 130 sum(region, purchaseCost(region)) + 131 sum(region, (amtsAfterSeparation(region,"hifat") 132 + amtsAfterSeparation(region,"lofat")) 133 * separationCost(region)); 134 135 * calculate total sales revenue 136 137 revenue.. 138 sales =e= sum(productType, 139 saleableProduct(productType) * prices(productType)); 140 141 objective.. 142 profit =e= sales - totalCost; 143 144 145 model milky / all /; 146 147 * set upper bound on sales 148 149 saleableProduct.up(productType) = maxDemand(productType); 150 151 option mip=cplex; 152 153 * important to set the RELATIVE precision small (setting optca doesn't help!) 154 milky.optcr = 1.e-6; 155 156 solve milky using mip maximizing profit; 157 158 display purchase.l, amtsAfterSeparation.l, amtProduct.l, profit.l; 159 160 COMPILATION TIME = 0.000 SECONDS 0.7 Mb LNX200-121 Happy Milk example with concave cost functions 10/21/01 19:55:55 PAGE 2 E x e c u t i o n GAMS Rev 121 Linux/Intel ---- 39 PARAMETER Xcost 2 3 A 280.000 2777.500 B 308.000 2157.000 ---- 39 PARAMETER Xpurchase 2 3 A 500.000 5000.000 B 700.000 5000.000 Happy Milk example with concave cost functions 10/21/01 19:55:55 PAGE 3 Model Statistics SOLVE milky USING MIP FROM LINE 156 GAMS Rev 121 Linux/Intel MODEL STATISTICS BLOCKS OF EQUATIONS 12 SINGLE EQUATIONS 25 BLOCKS OF VARIABLES 10 SINGLE VARIABLES 35 NON ZERO ELEMENTS 97 GENERATION TIME = 0.000 SECONDS 1.3 Mb LNX200-121 EXECUTION TIME = 0.000 SECONDS 1.3 Mb LNX200-121 Happy Milk example with concave cost functions 10/21/01 19:55:55 PAGE 4 GAMS Rev 121 Linux/Intel S O L V E S U M M A R Y MODEL milky OBJECTIVE profit TYPE MIP DIRECTION MAXIMIZE SOLVER CPLEX FROM LINE 156 **** SOLVER STATUS 1 NORMAL COMPLETION **** MODEL STATUS 1 OPTIMAL **** OBJECTIVE VALUE 938.1000 RESOURCE USAGE, LIMIT 0.010 1000.000 ITERATION COUNT, LIMIT 22 10000 GAMS/Cplex Mar 21, 2001 LNX.CP.CL 20.0 019.019.039.LNX For Cplex 7.0 Cplex 7.0.0, GAMS Link 19 Proven optimal solution. ---- EQU EQpiecewise constraints on the SOS2 LOWER LEVEL UPPER MARGINAL A 1.0000 1.0000 1.0000 -2.5000 B 1.0000 1.0000 1.0000 -7.0000 ---- EQU EQpurchase figure purchase from the pieces LOWER LEVEL UPPER MARGINAL A . . . 0.5550 B . . . 0.4300 ---- EQU EQcost figure purchase cost LOWER LEVEL UPPER MARGINAL A . . . -1.0000 B . . . -1.0000 ---- EQU fatConservationSeparation fat conserved in separation LOWER LEVEL UPPER MARGINAL A . . . -8.7000 B . . . -8.6797 ---- EQU volumeConservationSeparation volume conserved in separation LOWER LEVEL UPPER MARGINAL A . . . -0.1200 B . . . -0.1262 ---- EQU volumeMixed mix at most what's available LOWER LEVEL UPPER MARGINAL A.raw -INF . . 0.5550 A.hifat -INF . . 7.1300 A.lofat -INF . . 0.2570 B.raw -INF . . 0.4300 B.hifat -INF . . 7.1300 B.lofat -INF . . 0.2296 ---- EQU totalProduct volume of each final product LOWER LEVEL UPPER MARGINAL cream . . . 0.1167 milk . . . 0.1878 ---- EQU qualityProduct min fat content of final product LOWER LEVEL UPPER MARGINAL cream . . +INF -8.7667 milk . . +INF -6.9200 ---- EQU howMuchCanYouSell amt sold may be <= amt produced LOWER LEVEL UPPER MARGINAL cream -INF . . 4.5000 milk -INF . . 0.3262 LOWER LEVEL UPPER MARGINAL ---- EQU productio~ . . . -1.0000 ---- EQU revenue . . . 1.0000 ---- EQU objective . . . 1.0000 productionCost total cost of production revenue sales revenue objective ---- VAR gamma LOWER LEVEL UPPER MARGINAL A.1 . . +INF 2.5000 A.2 . 0.8207 +INF EPS A.3 . 0.1793 +INF EPS B.1 . . +INF 7.0000 B.2 . 0.9767 +INF EPS B.3 . 0.0233 +INF EPS ---- VAR purchase LOWER LEVEL UPPER MARGINAL A . 1306.6667 +INF . B . 800.0000 +INF . ---- VAR amtsAfterSeparation LOWER LEVEL UPPER MARGINAL A.raw . 42.6667 +INF . A.hifat . 64.0000 +INF . A.lofat . 1200.0000 +INF . B.raw . 800.0000 +INF . B.hifat . . +INF . B.lofat . . +INF . ---- VAR amtsMixed LOWER LEVEL UPPER MARGINAL A.raw .cream . 42.6667 +INF . A.raw .milk . . +INF -0.0212 A.hifat.cream . 64.0000 +INF . A.hifat.milk . . +INF -1.4062 A.lofat.cream . . +INF -0.0527 A.lofat.milk . 1200.0000 +INF . B.raw .cream . . +INF -0.0065 B.raw .milk . 800.0000 +INF . B.hifat.cream . . +INF . B.hifat.milk . . +INF -1.4062 B.lofat.cream . . +INF -0.0691 B.lofat.milk . . +INF -0.0072 ---- VAR amtProduct LOWER LEVEL UPPER MARGINAL cream . 106.6667 +INF . milk . 2000.0000 +INF . ---- VAR saleableProduct LOWER LEVEL UPPER MARGINAL cream . 106.6667 300.0000 . milk . 2000.0000 2000.0000 0.4738 ---- VAR purchaseCost LOWER LEVEL UPPER MARGINAL A . 727.7000 +INF . B . 351.0000 +INF . LOWER LEVEL UPPER MARGINAL ---- VAR totalCost . 1141.9000 +INF . ---- VAR sales . 2080.0000 +INF . ---- VAR profit -INF 938.1000 +INF . **** REPORT SUMMARY : 0 NONOPT 0 INFEASIBLE 0 UNBOUNDED Happy Milk example with concave cost functions 10/21/01 19:55:55 PAGE 5 E x e c u t i o n GAMS Rev 121 Linux/Intel ---- 158 VARIABLE purchase.L A 1306.667, B 800.000 ---- 158 VARIABLE amtsAfterSeparation.L raw hifat lofat A 42.667 64.000 1200.000 B 800.000 ---- 158 VARIABLE amtProduct.L cream 106.667, milk 2000.000 ---- 158 VARIABLE profit.L = 938.100 EXECUTION TIME = 0.000 SECONDS 1.3 Mb LNX200-121 USER: Computer Sciences Dept. G010628:1627AS-LNX University of Wisconsin-Madison DC2621 **** FILE SUMMARY INPUT /afs/cs.wisc.edu/u/s/w/swright/public/html/635/examples/happymilk-concave.gms OUTPUT /afs/cs.wisc.edu/u/s/w/swright/public/html/635/examples/happymilk-concave.lst