Académique Documents
Professionnel Documents
Culture Documents
Previous Lecture:
2-d arraymatrix
Todays Lecture:
More examples on matrices Optional reading: contour plot (7.2, 7.3 in Insight)
10
36 35 37
22 20 21
15 12 16
62 66 59
Announcement:
12 13
Last names A-L in Uris Hall Room G01 Last names M-Z in Baker Lab Room 200
Lecture 13
Bidirectional links are blue. Unidirectional link is black as it leaves page j, red when it arrives at page i.
14
Not efficient: each blue line gets drawn twice. See ShowRandomLinks.m
Lecture 13 16
A Cost/Inventory Problem
Problems A customer submits a purchase order that is to be filled by a single factory. 1. How much would it cost a factory to fill the order? 2. Does a factory have enough inventory/capacity to fill the order? 3. Among the factories that can fill the order, who can do it most cheaply?
19 Lecture 14 20
A company has 3 factories that make 5 different products The cost of making a product varies from factory to factory The inventory/capacity varies from factory to factory
Lecture 14
Lecture slides
CS1112 Lecture 14
Cost Array
10
36 35 37
22 20 21
15 12 16
62 66 59
38
5 19 29
99 83 21
34 12 56
42 42 87
12 13
Inv
82 51
Purchase Order C
10 12 13
36 35 37
22 20 21
15 12 16
62 66 59
PO
12 29 5 PO 1 0 12 29 5
The value of PO(j) is the number of product js that the customer wants
Lecture 14
23
Lecture 14
24
10
36 35 37
22 20 21
15 12 16
62 66 59
Encapsulate
function TheBill = iCost(i,C,PO) % The cost when factory i fills the % purchase order nProd = length(PO); TheBill = 0; for j=1:nProd TheBill = TheBill + C(i,j)*PO(j); end
12 13
12 29 5
Lecture 14
28
Lecture slides
CS1112 Lecture 14
inf a special value that can be regarded as positive infinity x y z w = = = < 10/0 1+x 1/x inf assigns inf to x assigns inf to y assigns 0 to z is always true if w is numeric
Lecture 14
29
Lecture 14
30
Inventory/Capacity Considerations What if a factory lacks the inventory/capacity to fill the purchase order? Such a factory should be excluded from the findthe-cheapest computation.
Yes No Yes
Inv
82 51
PO
12 29 5
Lecture 14
31
Lecture 14
32
38
5 19 29
99 83 21
34 12 56
42 42 87
Inv
82 51
DO is true if factory i can fill the order. DO is false if factory i cannot fill the order.
Lecture 14 33
PO
12 29 5
Lecture 14
34
Lecture slides
CS1112 Lecture 14
Still True
38 5 19 29 99 83 21 34 12 56 42 42 87
Encapsulate
function DO = iCanDo(i,Inv,PO) % DO is true if factory i can fill % the purchase order. Otherwise, false nProd = length(PO); DO = 1; for j = 1:nProd DO = DO && ( Inv(i,j) >= PO(j) ); end
Lecture 14 41
Inv
82 51
DO
PO
12 29 5
Encapsulate
function DO = iCanDo(i,Inv,PO) % DO is true if factory i can fill % the purchase order. Otherwise, false nProd = length(PO); j = 1; while j<=nProd && Inv(i,j)>=PO(j) j = j+1; DO should be true when end A j < nProd DO = _________; B j == nProd C j > nProd
Lecture 14 43
Lecture 14
45
Yes No Yes
12 13
PO
12 29 5
As computed by iCost
Lecture 14
As computed by iCanDo
48
Lecture slides