Operatioanalyysi 2011, Harjoitus 2, viikko 38 H2t1, Exercise 1.1. H2t2, Exercise 1.2. H2t3, Exercise 2.3. H2t4, Exercise 2.4. H2t5, Exercise 2.5.
(Exercise 1.1.) 1 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible.
(Exercise 1.1.) 1 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. Päätösmuuttujat: x 1 = Artyn käyttämän punaisen värin määrä (ml) x 2 = Artyn käyttämän keltaisen värin määrä (ml)
(Exercise 1.1.) 2 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = punaisen määrä (ml), x 2 = keltaisen määrä (ml) Tavoitefunktio (minimoidaan kustannuksia):
(Exercise 1.1.) 2 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = punaisen määrä (ml), x 2 = keltaisen määrä (ml) Tavoitefunktio (minimoidaan kustannuksia): min z = 0,02x 1 + 0,03x 2 (e)
(Exercise 1.1.) 3 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = pun. (ml), x 2 = kelt. (ml), min z = 0,02x 1 + 0,03x 2, Rajoitteet:
(Exercise 1.1.) 3 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = pun. (ml), x 2 = kelt. (ml), min z = 0,02x 1 + 0,03x 2, Rajoitteet: x 1 + x 2 = 100 värin kokonaismäärä (ml)
(Exercise 1.1.) 3 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = pun. (ml), x 2 = kelt. (ml), min z = 0,02x 1 + 0,03x 2, Rajoitteet: x 1 + x 2 = 100 värin kokonaismäärä (ml) x 2 50 keltaista enintään 50ml
(Exercise 1.1.) 3 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = pun. (ml), x 2 = kelt. (ml), min z = 0,02x 1 + 0,03x 2, Rajoitteet: x 1 + x 2 = 100 värin kokonaismäärä (ml) x 2 50 keltaista enintään 50ml x 1 0.20(x 1 + x 2 ) punaista vähintään 20%
(Exercise 1.1.) 3 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = pun. (ml), x 2 = kelt. (ml), min z = 0,02x 1 + 0,03x 2, Rajoitteet: x 1 + x 2 = 100 värin kokonaismäärä (ml) x 2 50 keltaista enintään 50ml x 1 0.20(x 1 + x 2 ) punaista vähintään 20% x 2 0.20(x 1 + x 2 ) keltaista vähintään 20%
(Exercise 1.1.) 3 1.1. Model the following problem mathematically: Arty Artist needs to mix orange color. Arty decides that the color orange has at least 20% red and 20% yellow in it. A 100ml tube of color red costs e2 and a 100ml tube of color yellow costs e3. Arty needs 100ml of the color orange. He has infinity supply of the color red but only 50ml (half a tube) of the color yellow. Arty would like to mix the color orange as cheap as possible. x 1 = pun. (ml), x 2 = kelt. (ml), min z = 0,02x 1 + 0,03x 2, Rajoitteet: x 1 + x 2 = 100 värin kokonaismäärä (ml) x 2 50 keltaista enintään 50ml x 1 0.20(x 1 + x 2 ) punaista vähintään 20% x 2 0.20(x 1 + x 2 ) keltaista vähintään 20% x 1,x 2 0 merkkirajoitteet
(Exercise 1.1.) 4 Viedään rajoitteet siistiin muotoon x 1 + x 2 = 100 (color tot) x 2 50 (yellow max) x 1 0,20(x 1 + x 2 ) (red min) x 2 0,20(x 1 + x 2 ) (yellow min) x 1,x 2 0 (sign constraints)
(Exercise 1.1.) 4 Viedään rajoitteet siistiin muotoon x 1 + x 2 = 100 (color tot) x 2 50 (yellow max) x 1 0,20(x 1 + x 2 ) (red min) x 2 0,20(x 1 + x 2 ) (yellow min) x 1,x 2 0 (sign constraints) x 1 + x 2 = 100 (color tot) x 2 50 (yellow max) 0,8x 1 0,2x 2 0 (red min) 0,2x 1 + 0,8x 2 0 (yellow min) x 1,x 2 0 (sign constraints)
(Exercise 1.1.) 5 Lopullinen LP-malli min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints)
(Exercise 1.1.) 5 Lopullinen LP-malli min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints) c = [0.02, 0.03] ; A = [1,1; 0,1; 0.8,-0.2;-0.2,0.8]; b = [100,50,0,0] ; [xmin,zmin] = glpk(c,a,b,[0,0],[],"sull","cc",+1)
(Exercise 1.1.) 6 min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints)
(Exercise 1.1.) 6 min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints) c = [0.02, 0.03] ;
(Exercise 1.1.) 6 min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints) c = [0.02, 0.03] ; A = [1,1; 0,1; 0.8,-0.2;-0.2,0.8];
(Exercise 1.1.) 6 min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints) c = [0.02, 0.03] ; A = [1,1; 0,1; 0.8,-0.2;-0.2,0.8]; b = [100,50,0,0] ;
(Exercise 1.1.) 6 min z = 0,02x 1 + 0,03x 2 s.t. x 1 + x 2 = 100 (color tot) x 2 50 (color yellow max) 0,8x 1 0,2x 2 0 (color red min) 0,2x 1 + 0,8x 2 0 (color yellow min) x 1,x 2 0 (sign constraints) c = [0.02, 0.03] ; A = [1,1; 0,1; 0.8,-0.2;-0.2,0.8]; b = [100,50,0,0] ; [xmin,zmin] = glpk(c,a,b,[0,0],[],"sull","cc",+1)
(Exercise 1.1.) 7 c = [0.02, 0.03] ; A = [1,1; 0,1; 0.8,-0.2;-0.2,0.8]; b = [100,50,0,0] ; [xmin,zmin] = glpk(c,a,b,[0,0],[],"sull","cc",+1) ##argumentit******************** ## c <--> päätosmuuttujien kertoimet tavoitefunktiossa ## A <--> rajoiteryhmän kerroinkaavio ## b <--> rajoiteryhmän RHS ## [0,0] <--> päätösmuuttujien alarajat (x1 >= 0, x2 >= 0) ## [] <--> päätösmuuttujien ylärajat (ei ylärajoja) ## "SULL" <--> rajoite 1 tyyppiä S (strict) yhtälö ## <--> rajoite 2 tyyppiä U (upper) eli RHS on yläraja ## <--> raj. 3&4 tyyppiä L (lower) eli RHS on alaraja ## "CC" <--> x1 ja x2 ovat tyyppiä C (continuous) eli des.lukuja ## +1 <--> minimointitehtävä ##output************************ ## xmin = ## 80 ## 20 ## zmin = 2.2000
(Exercise 1.2.) 8 1.2. Mr. Quine sells gavagais. He will sell one gavagai for 10 Euros. So, one might expect that buying x gavagais from Mr. Quine would cost 10x Euros. This linear pricing rule rule may not be true, however. Explain at least three reasons why not.
(Exercise 1.2.) 8 1.2. Mr. Quine sells gavagais. He will sell one gavagai for 10 Euros. So, one might expect that buying x gavagais from Mr. Quine would cost 10x Euros. This linear pricing rule rule may not be true, however. Explain at least three reasons why not. a) Määräalennukset: Vaikka pari ensimmäistä gavagaisia maksaisikin 10 euroa, niin isomman erän saattaa saada pienemmällä yksikköhinnalla. Silloin lauseke c = 10x antaa liian ison hinnan. b) Kiinteät kustannukset: Jos Mr. Quine laskutta todellisten kustannusten perusteella. Silloin 10 euroa on kiinteä kustannus + yhden gavagaisin muuttuvat kustannukset. Oikea lauseke voisi olla esim. (c = FC + VAC x = 2 + 8x). Koska emme nyt tiedä kiinteiden kustannusten suuruutta, niin oikea lauseke jää arvoitukseksi.
(Exercise 1.2.) 9 c) Toimitusongelmat: Kaava saattaa olla oikea, mutta x:n arvo saattaa olla rajoitettu. Jos Mr. Quine pystyy itse tuottamaan vain osan tilauksesta ja hän hankkii puuttuvan osan tilauksesta muualta, niin ylimääräinen vaiva ja toisen tuottajan korkeampi hinnoittelu saattaa saada aikaan sen, että yksikköhinta nousee. Silloin kaava c = 10x antaa liian alhaisen hinnan. d) Skaalaetu: Jos Mr. Quine on tyypillisesti tuottanut pari gavagaisia kuukaudessa, ja hän nyt saakin 20 gavagaisin tilauksen, niin hänen on mahdollista kehittää tuotantomenetelmiä niin, että yksikköhinta laskee. Silloin lauseke c = 10x antaa liian korkean hinnan.
(Exercise 2.3.) 10 2.3. The function npv assumes that the rate of return r is constant over time. Modify the function so that it takes as an input variable a vector of rate of returns that change from one period to another.
(Exercise 2.3.) 10 2.3. The function npv assumes that the rate of return r is constant over time. Modify the function so that it takes as an input variable a vector of rate of returns that change from one period to another. function v = npv(cf,r) ## Function v = npv(cf,r) returns the Net Present Value (npv) of ## the cash flow cf. The cash flow cf is received at the end of ## each period. The rate of return over the period is r. The ## parameter r is scalar. The cash flow cf is a (column) vector. T = length(cf); # The number of periods. pv = zeros(t,1); # Initialize present values (pv) at zero. for t=1:t pv(t) = cf(t) / (1+r)^t; # Set the pv s. endfor v = sum(pv); # npv is the sum of pv s. endfunction
(Exercise 2.3.) 11 ## (H2t3) Exercise 2.3. tiedostossa my_npv.m function v = my_npv(cf,r) T = length(cf); # The number of periods. if T!=length(r) error("virhe: cf ja r eri mittaisia."); end #<UUSI# #<UUSI# #<UUSI# pv = zeros(t,1); # Initialize present values (pv) at zero. for t=1:t pv(t) = cf(t) / (1+r(t))^t; # Set the pv s. # ^^^-----------------------#MUUTOS# endfor v = sum(pv); # npv is the sum of pv s. endfunction
(Exercise 2.3.) 12 Muutama kommentti edellisiin kahteen kalvoon alkuperäinen funktio npv on talletettu tekstitiedostoon npv.m uusi korjattu funktio on nimeltään my_npv ja se tulee tallettaa tekstitiedostoon my_npv.m Alun tarkistus ei ole nyt välttämätön, mutta tämän kaltaisia tarkistuksia on syytä yleensä tehdä. Oleellinen muutos on nyt se, että r:ää kohdellaan nyt vektorina. Muuttujaa ei tarvitse esitellä. Tulkki päättelee muuttujan tyypin, kun sitä ensimmäisen kerran käytetään.
(Exercise 2.4.) 13 2.4. Solve the LP max z = 4x 1 + 3x 2 s.t. 2x 1 + 3x 2 6 3x 1 + 2x 2 3 2x 2 5 2x 1 + x 2 4 x 1,x 2 0 (a) by using glpk, (b) by using stu_lp_solver.
a) (Exercise 2.4.a) 14 ## (H2t4a) Exercise 2.4.a) c = [4, 3] ; A = [2, 3; -3, 2; 0, 2; 2, 1]; b = [6, 3, 5, 4] ; [x_max,z_max]=glpk(c,a,b,[0,0],[],"uuuu","cc",-1) ##output************************************************* ## x_max = ## 1.5000 ## 1.0000 ## z_max = 9
b) (Exercise 2.4.b) 15 ## (H2t4b) Exercise 2.4.b) c = [4,3] ; A = [2,3;-3,2;0,2;2,1]; b = [6,3,5,4] ; [z_max,x_max,status] = stu_lp_solver(c,a,b) ##output************************************************* ## z_max = 9 ## x_max = ## 1.5000 ## 1.0000 ## status = bounded
(Exercise 2.5.) 16 2.5. Solve the LP max z = 2x 1 + 9x 2 s.t. x 1 + 2x 2 500 x 1 + x 2 100 x 1,x 2 0 (a) by using glpk, (b) by using stu_lp_solver.
a) (Exercise 2.5.a) 17 ## (H2t5a) Exercise 2.5.a) c = [2, 9] ; A = [1, 2; 1, 1]; b = [500, 100] ; [x_max,z_max]=glpk(c,a,b,[0,0],[],"ul","cc",-1) ##output************************************************* ## x_max = ## ## 0 ## 250 ## ## z_max = 2250
b) (Exercise 2.5.b) 18 Normaalimuoto max z = 2x 1 + 9x 2 s.t. x 1 + 2x 2 500 x 1 x 2 100 x 1,x 2 0
b) (Exercise 2.5.b) 18 Normaalimuoto max z = 2x 1 + 9x 2 s.t. x 1 + 2x 2 500 x 1 x 2 100 x 1,x 2 0 ## (H2t5b) Exercise 2.5.b) c = [2, 9] ; A = [1, 2; -1, -1]; b = [500, -100] ; [z_max,x_max,status] = stu_lp_solver(c,a,b) ##output************************************************* ## z_max = 2250 ## x_max = ## ## 0 ## 250 ## ## status = bounded