43644-TahaSMAppA - Appendix A AMPL Modeling Language A-1 #...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Appendix A AMPL Modeling Language A-1 # —————— ~-~—--———-———-—-—- mmmmm muscle set 1mm; set resource; # ————————————————————— m—parametas param unitpmfit {paint}; param rhs {resemte}; param aij {resouree,paint}; #—-—- -—--——-.———-—-~— wariabies var pruducfipafimi} >= 0; #-—— ------------------------ n—model maximlz" e profit: 5111115 in paint} “flitPI‘OfitfiI *Pwdufitfi]; subject to ; set I‘esuurce := ml n12 dam-a (1 market; param unitprofit := param rhszrz ml 24 m2 6 demand 1 market 2, param aij: atelier mtelim‘maa‘ine := m1 6 4 1112 K 2 demand -1 1 market 0 I solve; # .... ........ ............ "—011th E33113 dispiay profit, product”, # ----------------------- ——-—vafiab1e3 var proctucfipaint} >= 0; #—-—-——- ———————————————— m—mudel maximize pmfit: sum{' ' paint} mxitprofitfirptmmetfi}; subject to limitfi in wm’d in paint} aiifiailfimduc’ifi] <= IhSfi]; continued... A—2 set paint := exterier interior; peram unitpmfii := exten'or 5 interior 4; param rhs:= I 24 2 6 3 1 4 2; param aij: extefler interim := 1 6 4 2 l 2 3 -1 1 4 0 1; solve; #—-———-—-—-—-——- mmmmmmmmm m-Ulltplli results display profit, product; #_ ____________ mu... ~~~~~~ -—--sets 3 param the {resource}; param aij {resomcc,paint}; maxinfize profit: 5111115 in paint} unitprofitfij*pmduet{j]; subject to limitfi in resource}: 3111116 in paint} aij[i2j}*produet[fl <= rhsfi]; data; set paim := extefior interior; exterior 5 interior 4; parm '1 : ml 24 m2 6 demand 1 market 2; pm aij: extexier interior := 1111 6 4 1112 1 2 demand ~1 1 market i} I; solve; #_______ ___________ ———-—output results display profit, product; Set A221 5 Lb- # _________________________ __Sets # --------------------------------- --———‘3613 set paint; sat Input; set resource; set output; 1: .................................. umpmcturs #—«-————-— ———————————— —————-—param€tcrs param unitProfit§pairIt}; param unitCustfinput}; pamm dis {resource}; _ param 3ield{output,input}; param a1} {msoutce,patnt}; _ Specs {output}; 1‘: """"""""""""""""""""""" "V‘mamcs paxam minNeeds; var pmductlrpaint} >=0; #---—~--—--——--———-——-—-——--—-—-—~—~-—--variab1e5 var feedStufi'finput} >=O; var fathSe=3umfi in inpui}feed3tufi[j}; maximum profit # ———————————————————————— —-mudel subject to minimize castsmnfi in mmt}unitCUSt[i]*feL’dStufifi]; " ,_ A .. .. .. ' fhsli}; subjecttu :3 emerim' mating ;:_;;fi§;ogff:m2 “mm” mm" sumfi in mpmmelm}*reedsmafi]<=specs[i]*1a1mUse; ‘ exterior 5 interior 4-, set mpui := com 50}; param rhs:= set output := pretein fibar; m1 24 pen-am minNeeds:=300; “12 5 - paIam unitCost z= corn .3 303; .9; dflmand 1 param specs:= protein ~.3 fiber .05; #m:gafive bemuse nf<~= mama 2; pamm yield: com 50); := ‘ _ J . . A ,2 protein —.09 —.6 param a1}. :gwmr mtgnor . 4 {mar .92 ‘06; m2 1 2 demand -1 I salve; market 0 1; #—~ -------------------- --——output results :Olw; n display costjeedsmfi”, feedStmlirwalxt; ~--~—---—~----~------—--- I; ' . . . . mm, pram dlspla} daxmalbbduabahfl, ’ OUTPUT cost = 437.64? t ihedsmfi ibedStlflirc := com 470.588 8.326676—17 soy 329.412 -1.110226—16 > aadual = 0.547059 bbmal {*1 := fiber ~2.05116fl-15 prom 4.17647 Reduced oust shuws that both cum and soy 6133111116 positive values in the opfimmn solutinn. Dual price thr cunsn‘aim aa shows that a 1 unit immease in mixflQeeds increases 1116: total cost by $.55, appmximately. Set A.3a param n; param c{1..n}; var X{l..n}; rest{i in l..n}:(if i<=n~l then X[i}+x[i+1] else x[1]+x[n])>=c[i]; xr=0,xfla=o param T; param c{1..T}; var X{1..T}; subject to Period{t in 1..T}: (if t=1 then c else x{t}) + zit} — d[t] — (if t<T then x{t+1} else 0)=O; (a) 1 param m; param n; param k; param p; param q; param c # . . . . . . . . . . . . . . . . . . l . . . . .methed 1 set 81={1..m union m+k..n union n+p. .q} var x{Sl}; subject to limit: sum{j in Sl}x[j}>=c; ii . . . . . . . . . . . . . . l . . . . . . . . .method 2 set SZ={1..q diff (n1+1..nr+k-1 union n+1. .n+p~1)} var x{52}; subject to limit: sumb‘ in 52}x[j]>=c; 03) para m; param n; param c; param k; var x{i in m..2*n+k}; # . . . . . . . . . . . . . . . . . . . . . . . ..method 1 subject to CC: sum{i in m..2*n+k diff n+1..n+k—1} x[i}<=c; # . . . . . . . . . . . . . . . . . . . . . . . ..method 2 subject to CC: sum{i in m..2*n+k: i<=n or i>=n+k}x[i] <=c; 2 (See file a.4a—2.txt} set productsUsingComp{ 1.5}; param c{1..5}; #wmponent cost param a{1..5}; #min availability param d; #maximmn demand for each product var X{ 1.. 10,1..5}>=0; if units of product i that use component 1' minimize a sumfi in 1..5}(cfi}*(smn{i in productsUsingCampfi]}x{i,j])); subject t9 C {j in l .5} :sum{i in productsUsingCempm}X[i,j]>=a[i]; D§iin1..10}: sumfi in l..5}x{i§]<=d; data; set meductsUsingCOmp[l}:=1 2 5 10; set productsUsingComp[2]2=3 6 7 8 9; set productsUsnigCompB] :=1 2 3 5 6 7 9; set pruductsUsingComp[4]:=2 4 6 8 10; set productsUsingCempfS]:—=I 3 4 5 6 7 9 IO; param az=l 500 2 400 3 900 4 700 5 100; gamma—=1 9 24 36 45 5 8; peram d:=300; display productsUsingComp; solveflisplay X; Set A.4a 3 In the following code, the indexed set components InProduet is determined directly from the original data, which precludes the need to detennine the elements of componentsIanductfi], i= 1, 2. ..., 10, manually. set productsU singComp{ l . .5 }; set eempmentsInProduetfi in 1.. 10}: {j in 1.5:1 in preductsUsingCompm}; par-am c{l .10}; #compenent installation cost param a{ l .5}; #min availability pawn d; #maximum demand fer each precinct var x{1..10,1..5}>=0;# units if product i that use component j minimize z: sum{i in l..10}c[i}*(sum{j in compenentsInProduct[i]}x[i.j}); subject {0 C{j in 1.5} :smmfi in pmfiuctsUsingCompfi]}x[i,j]>=a[i1; D{iin1..10}: 5111113 in I..5}X[ij]<=d; data; set productsUsingCump[1}z=1 2 5 10; set productsUsmgComp[2}:=3 6 7 8 9; set productsUsingCump[3]:=l 2 3 S 6 7 9; set pmductsUsingCompHLQ 4 6 8 18; set producteUsinngpiS]:=I 3 4 5 6 7 9 10; pamm a:=1 500 2 400 3 900 4 700 5 100; paramcz=1123 32 46 54 69 72 35 910107; param d2=300; display; productsUsingComp,cemponentsIanduct; solvefiisplay X; A-5 Set A.5a Set A.5b 1 .. ......................................... 1 File RM3X.dat: The first row gives flies. unitprof i t. The first column in the z:— ——————— --’~ —————————————————— —-paramctefs ' - param Imitpmfifipaint}; remanyng 4 rows diffines rhs, and the second Pmm ms {mwcfi}; and thlrd columns glve aij. pmm aij {mswcemaim}; tn- ------------------------------- --variables var pruduat§paint} >= 0; 4 #—- ---------------------------------------- "model maximize profit: sumgj in paint} unitpmfitfi] *procfuctfj}; 4 5 4 subject to Iimitfi in resource}: 1 2 d3 sum} in Mint} aifiififimductfifimfhsfi]; ta; '1 1 set paint := exterior interior, 0 1 safe resource z= mi m2 demanfi market; {mm unitprofit I: exterior 5 2 interior 4; .— param rim: File RM3XX.dat: Colmm I gives rhs. if: :4 Coulmn 2 repeats unitprof i t {l} as many demand 1 times as the number of constraints. Coulmn 3 met 2’ repeats uni tpro f i t [2] as many times as pawn aij: grit-«rim Mgfim == 4 the number of constraints. Columns 3 and 5 $2 1 2 ' ' ' ‘ ; demand -1 1 gwe a1]. Lonvoluted data file. market a I; 24 5 6 4 4 6 S 1 4 2 1 5 -I 4 1 2 5 0 4 1 OUTPUT Objective value = 21 .00 £235.12; ““ "—5.355; _____ "EQEQS $.25; _____ “£335 _________ TEE?“ interior 1 .50 6. 00 ml 0.00 0.75 m2 0.00 0.50 demand 2.50 0.00 market 0.50 0.00 Set A.5c 1 Sets paint and resource cannot be read from the double—subscripted table RM4 a ij , and hence will not be defined for unitprofit and rhs. .2. # ---------------------- ———-—--—- ----- --—sets set resource; set paint; #—- ———————————————————————————————— ~~parameters param unitprofit{paint}; param rhs {resource}; param aij {resomce,paint}; gt. .............................. --variables var product{paint} >= 0; # .................................. u-model objective maydnfize profit: sum {j in paint} unitprofitm‘kprodnctb]; as; .............. «m—mnmodel constraints subject to limit {i in resource}: 53111 {i in Paint} aijlitil’kpfoductfi} <= rhsli]; # --------------------------- ——--—read tables table RM4profit IN: paint<-[COL1}, unitprofit~COL2; table RM431J IN: {resourcerpaint}, aij; #table RM4arrayAij IN : [i~resouree],{ j in pain1}<aij liJHi)>; # ————————————————————————————— «write tables table varData OUT: [paint},product,product.rc; table cenData OUT: [resource],limit.slaek~slac]glimit.dm1~DUal; read table RM4profit; \read table RM4rhs; read table RM4aij; #read table RM4an‘ayAij; 1g... ______________ __———-——— .... -—Solution command solve; # _____________________ m-write table files wn'te table varData; wn'te table conData; # ...................... —--/——---—-—-0utput lesults display profit, product, Iimitdual, productrc; # ............................... -—-end of model Set A.7a (a) let rhs["m1“]:=20; for {i in 1.100000} { solve; display rhs["ml“],preduct; ifrhs[“ml“]=35 then break; let rhs["m1"}:=rhs["ml"}+5; } (1)) let rhs["m1 “1:20; repeat while rhs["m1“]<=35 { solve; display rhsE"mI "Lproduct; let rhs{“m1"]:=rhs["ml"}+5; } (6) let rhs[“m1“]:=20; repeat until rhs["m1"]>35 { solve; display rhs{"m1"],product; let rhs["ml "]:=rhs["m1“]+5; } 1 ...
View Full Document

This note was uploaded on 11/06/2011 for the course ISE 421 taught by Professor Km during the Spring '11 term at King Fahd University of Petroleum & Minerals.

Page1 / 7

43644-TahaSMAppA - Appendix A AMPL Modeling Language A-1 #...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online