Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2

Similar presentations


Presentation on theme: "Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2"— Presentation transcript:

1 Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2
alloy 2 alloy 1 alloy 1 alloy 1 fresh 1 fresh 2 fresh 2 fresh 2 armor 2 armor 2 armor 2 armor 1 brave 2 brave 3 brave 1 brave 1 wreak 2 wreak 3 wreak 1 wreak 2 PERL stories - use in ACM - creating scripts - LTS, BOT fjord 1 fjord 2 fjord 1 fjord 5 This term's first class to guess another's word earns 1 problem... This term's last class to have its word guessed earns 1 problem...

2 You may submit problems until the end of exams…
Course Schedule Jan Welcome! DP + other problems ~ 4 problems Feb Lab session ~ 4 problems Feb Discussion session on bin search problems ~ 4 problems Feb Paul Dorsey ~ 4 problems Feb Lab session plus a FW "reminder"! ~ 4 problems Mar Discussion session on other graph algs. ~ 4 problems Mar Lab session on graph + geometry problems ~ 4 problems Mar Spring break... – no CS 189 class Mar Discussion session on something new... ~ 4 problems Mar Lab session ~ 4 problems we don't meet through April... ≥ 32 problems total You may submit problems until the end of exams…

3 IOCCC example of the day...
International Obfuscated C Coding Contest one program to rule them all!

4 IOCCC... ?

5 What's the maximum flow possible, from src to sink?
Max Flow ! B 12 D 16 20 sink or target t s 10 4 9 7 source 13 4 C E 14 capacity What's the maximum flow possible, from src to sink? Ford-Fulkerson algorithm

6 Max Flow B D t s C E Capacity Graph
TO Max Flow Capacity Graph s B C D E t s - 16 13 10 12 4 14 9 7 20 B (Step #1) Use depth- or breadth-first search to find any path from s to t. C FROM D E B 12 D t 16 20 sink t s 10 4 9 7 source 13 4 C E 14

7 Max Flow B D t s C E What's left ? Capacity Graph
TO Max Flow Capacity Graph s B C D E t s - 16 13 10 12 4 14 9 7 20 B (Step #1) Use depth- or breadth-first search to find any path from s to t. C FROM D E B 12 D t 16 20 sink t s 10 4 9 7 source 13 4 C E 14 What's left ?

8 Max Flow B D t s C E What's left ! Old capacities
- 16 13 10 12 4 14 9 7 20 B (Step #1) Use depth- or breadth-first search to find any path from s to t. C FROM D E B 0/12 D t 4/16 8/20 sink t s 10 4 9 7 source 13 4 C E 14 TO s B C D E t s - 4 13 12 10 14 9 7 8 Residual capacities! B What's left ! C FROM D What are the red edges? E t

9 TO Max Flow s B C D E t s - 16 13 10 12 4 14 9 7 20 B (Step #1) Use depth- or breadth-first search to find any path from s to t. C FROM D E B D t 4 12 8 sink 12 12 t s 10 4 9 7 source 13 4 C E 14 TO s B C D E t (Step #2) Continue with the remaining capacities until no path exists! s - 4 13 12 10 14 9 7 8 B C FROM D E t

10 Max Flow max flow: 23 B D s t C E
(Step #1) Use depth- or breadth-first search to find any path from s to t. B 12/12 D 11/16 19/20 sink s 0/10 1/4 t 0/9 7/7 source 12/13 4/4 C E 11/14 (Step #2) Continue with the remaining capacities until no path exists! max flow: 23

11 Get into the flow! edmonds_karp def max_flow(C, source, sink):
A little bit of name contention… This is the algorithm. edmonds_karp def max_flow(C, source, sink): n = len(C) # C is the capacity matrix F = [[0] * n for i in range(n)] # F is the flow matrix # residual capacity from u to v is C[u][v] - F[u][v] while True: path = BFS(C, F, source, sink) if not path: break # no path - we're done! # find the path's flow, that is, the "bottleneck" edges = [C[u][v]-F[u][v] for u,v in path] path_flow = min( edges ) print "Augmenting by", path_flow for u,v in path: # traverse path to update flow F[u][v] += path_flow # forward edge up F[v][u] -= path_flow # backward edge down return sum([F[source][i] for i in range(n)]) # out from source

12 A brief BFS algorithm using the Capacity matrix
Useful alone, too A brief BFS algorithm using the Capacity matrix def BFS(C, F, source, sink): queue = [source] # the BFS queue paths = {source: []} # stores 1 path per graph node while queue: u = queue.pop(0) # next node to explore (expand) for v in range(len(C)): # for each possible next node # path from u to v? and not yet at v? if C[u][v] - F[u][v] > 0 and v not in paths: paths[v] = paths[u] + [(u,v)] if v == sink: return paths[v] queue.append(v) # go from v in the future return None

13 And the code needed to run it…
Setting up… And the code needed to run it… if __name__ == "__main__": # make a capacity graph # node A B C D E F C = [ [ 00, 16, 13, 00, 00, 00 ], # A [ 00, 00, 10, 12, 00, 00 ], # B [ 00, 04, 00, 00, 14, 00 ], # C [ 00, 00, 9, 00, 00, 20 ], # D [ 00, 00, 00, 7, 00, 4 ], # E [ 00, 00, 00, 00, 00, 00 ] ] # F print "C is", C source = 0 # A sink = 5 # F max_flow_value = max_flow( C, source, sink ) print "max_flow_value is", max_flow_value Linked at the ACM website by the slides…

14 But is max flow good for anything?
that is, beyond solving "max flow" problems...

15 and some acceptable possibilities ...
Matching! and some acceptable possibilities ... we have four brides and six grooms a bipartite graph

16 and some acceptable possibilities ...
Matching! and some acceptable possibilities ... we have four brides and six grooms a maximal matching == no more matchings without rearrangement

17 and some acceptable possibilities ...
Matching! and some acceptable possibilities ... we have four brides and six grooms a maximum matching == no rearrangements will yield more matchings

18 Maximum matching is max flow...
connect a source to the left side... make all capacities = 1 put a sink on the right 1 1 all 1s all 1s 1 sink s 1 t source 1 1 what do the source and sink constraints ensure?

19 Max flow thought experiment...
Suppose this is the flow so far (3 units): 1 1 all 1s all 1s 1 sink s 1 t source 1 1 Draw what happens in the next step of the max-flow algorithm!

20 Max flow thought experiment...
... the path it finds ... 1 1 all 1s all 1s 1 sink s 1 t source 1 1 What is this single path doing?

21 Max flow thought experiment...
Done! 1 1 all 1s all 1s 1 sink s 1 t source 1 1 Maximum matching == 4

22 Try one or more of this week's problems!
this one is maximum matching! Try one or more of this week's problems!

23 Stake Height and width of the field Input 4 the pattern Output 3 Maximum number of cows such that no two share a column and no two share a row.

24 Stake as matching who are the brides? and the grooms?
and the constraints?

25 Try one or more of this week's problems!
this one is from last week... ? Try one or more of this week's problems!

26 Dijkstra, for single-source shortest paths
shortest dist from S For all nk , track <nk, Inf> Put <S,0> into your queue Q. While Q not empty: Remove Q's nearest node <nc,dc> For each edge [nc, nk, dc2k]: Let dk be nk's distance: <nk,dk> If dc + dc2k < dk: set dk = dc + dc2k Put <nk,dk> into Q...

27 Dijkstra, for single-source shortest paths
shortest dist from S For all nk , track <nk, Inf> Put <S,0> into your queue Q. While Q not empty: Remove Q's nearest node <nc,dc> For each edge [nc, nk, dc2k]: Let dk be nk's distance: <nk,dk> If dc + dc2k < dk: set dk = dc + dc2k Put <nk,dk> into Q...

28 Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2
alloy 2 alloy 1 alloy 1 alloy 1 fresh 1 fresh 2 fresh 2 fresh 2 armor 2 armor 2 armor 2 armor 1 brave 2 brave 3 brave 1 brave 1 wreak 2 wreak 3 wreak 1 wreak 2 PERL stories - use in ACM - creating scripts - LTS, BOT fjord 1 fjord 2 fjord 1 fjord 5 This term's first class to guess another's word earns 1 problem... This term's last class to have its word guessed earns 1 problem...


Download ppt "Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2"

Similar presentations


Ads by Google