ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.

Slides:



Advertisements
Similar presentations
Jotto! JRsSRsElderly slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate 1 This term's last class to have its word.
Advertisements

Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
Lecture 5: Network Flow Algorithms Max-Flow Min-Cut Single-Source Shortest-Path (SSSP) Job Sequencing.
Jotto! JRsSRsElderly A word-guessing game similar to mastermind… slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Jotto! SophsJrsSrs audio 1audio 2audio 1 Frosh audio 2 graze 3graze 1 graze 2 alloy 1 alloy 2 fresh 2fresh 1fresh 2fresh 1 This term's first class to guess.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007.
The Maximum Network Flow Problem. CSE Network Flows.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures.
1 The Max Flow Problem. 2 Flow networks Flow networks are the problem instances of the max flow problem. A flow network is given by 1) a directed graph.
HW2 Solutions. Problem 1 Construct a bipartite graph where, every family represents a vertex in one partition, and table represents a vertex in another.
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
Maximum Flows Lecture 4: Jan 19. Network transmission Given a directed graph G A source node s A sink node t Goal: To send as much information from s.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
1 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f p output f Runs in time O(|f max | |E|) where f.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
Advanced Algorithms Piyush Kumar (Lecture 5: Weighted Matching) Welcome to COT5405 Based on Kevin Wayne’s slides.
CS 189 today Open-ended project option… A few more problems…… and one more algorithm! Jotto game finale?! Rest of the term No meeting on Tuesday, November.
ACM Welcome! Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct.
9/23/2015ACM-ICPC1 Maximum Flow Problem Source t fg e 42 Target (sink) flow capacity b s c a de 2/3/ actual flow 1/2/ 1/ 2/ 1.Actual flow  capacity.
Lecture 5: Network Flow Algorithms Single-Source Shortest-Path (SSSP) (Dijkstra's Algorithm) Max Flow - Min Cut (Ford-Fulkerson) Job Sequencing.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
Curricularizing the ACM... ? Zach Dodds ~ November 13, 2010.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
ACM today This week's problems… New and improved :-) ACM table slacking! not slacking… missing entries? let me know…
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
Week 12 - Monday.  What did we talk about last time?  Topological sort and cycle detection in directed graphs  Connectivity  Strong connectivity.
Network Flow Analysis of Algorithms.
and 6.855J March 6, 2003 Maximum Flows 2. 2 Network Reliability u Communication Network u What is the maximum number of arc disjoint paths from.
Announcements Finish up Network Flow today Then Review for Final on Monday ◦ HW#5 is due on Monday, let me or the TA’s know if you have trouble starting.
Algorithm Design and Analysis (ADA)
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 23.
EMIS 8374 The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
11/21/02CSE Max Flow CSE Algorithms Max Flow Problems.
Harbin, China 2010 finals ACM today… ! (2009) Knapsack DP for NP! Floyd-Warshall DP for APSP! Max Flow.
The Maximum Network Flow Problem
Contest Algorithms January 2016 Describe the maxflow problem, explain the Ford-Fulkerson, Edmonds-Karp algorithms. Look at the mincut problem, bipartite.
ACM today The Fall competition is getting organized… it's going to be lonely…
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
ACM so far… Sep 6 Welcome! and DP problems ~ 5 problems
The Steepest Ascent Hill Climbing Algorithm
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2
Maximum Flow Problem flow capacity Actual flow  capacity
Instructor: Shengyu Zhang
Jotto! Sophs Jrs Srs Profs pluot 1 pluot 2 pluot 1 pluot 2 squid 2
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Maximum Bipartite Matching
Presentation transcript:

ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2 Lab session on graph problems ~ 6 problems Oct 9 Scott Ellsworth on Google Irvine ~ 6 problems Oct 16 Discussion session on maxflow problems ~ 6 problems Oct 23 (9pm) Lab & local ACM qualifying contest ~ 6 problems Oct 30 Discussion session on geometry problems ~ 6 problems Nov 6 Lab session on geometry problems ~ 6 problems Nov 10 (Sat.) ACM Regional contest (in Riverside...) Nov 13 Final meeting Job-fair thoughts?

Our "sources" Aaron Gable, Amber Yust, and other alums… Cory Simmonsen Web technologies Build systems Distributed systems (scaling up) Testing! Working with a large existing codebase… What should be improved?

IT always seems mysterious to me… Hooray! Not sure about these, however…

Matrix of skillsets

Ford-Fulkerson algorithm What's the maximum flow possible, from src to sink? s B E D C 13 t source capacity Max Flow ! sink or target

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

s B E D C 13 s B C D E FROM sBCDE t t t 4/ / /20 4 TO Old capacities source sink (Step #1) Use depth- or breadth-first search to find any path from s to t. Max Flow What's left… s B C D E FROM sBCDE t t TO Residual capacities. and the red edges? Backwards capacities! 12

s B E D C 13 s B C D E FROM sBCDE t t t TO source sink (Step #1) Use depth- or breadth-first search to find any path from s to t. Max Flow s B C D E FROM sBCDE t t TO 12 (Step #2) Continue with the remaining capacities until no path exists! Old capacities Residual capacities. Backwards capacities. New capacities

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

Setting up… 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 And the code needed to run it… Linked at the ACM website by the slides…

Get into the flow! 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 A little bit of name contention… edmonds_karp This is the algorithm.

Useful alone, too 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 A brief BFS algorithm using the Capacity matrix

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

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

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

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

Maximum matching is max flow... s source connect a source to the left side... all 1s

Maximum matching is max flow... s source connect a source to the left side... make all capacities = all 1s

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

Max flow thought experiment... s source t sink all 1s Suppose this is the flow so far (3 units): Draw what happens in the next step of the max-flow algorithm! how to get from maximal matching to maximum matching…

Max flow thought experiment... s source t sink all 1s... the path it finds... What's going on here?

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

general problems:max-flow problems: cowcarn feeding optimilk sandcas timecards tswift difficult-to-classify problems: This week's problems Try max flow! soda (last week) tour (last week)

The challenge: is sometimes setting up the graph

How do we use the results? What is flowing? tswift There are four ingredients available ~ at these costs hay-flavored coffee spam chocolate There are four smoothie recipes available ~ with these rewards 4 ingredients (hay) & 4 smoothie recipes each recipe requires ingredients

source ingredient costs How do we use the results? What is flowing? tswift There are four ingredients available ~ at these costs hay-flavored coffee spam chocolate There are four smoothie recipes available ~ with these rewards Hay coffee Spam Choc. 4 ingredients (hay) & 4 smoothie recipes each recipe requires ingredients ingredients

source sink ingredient costs recipe rewards How do we use the results? What is flowing? tswift There are four ingredients available ~ at these costs hay-flavored coffee spam chocolate There are four smoothie recipes available ~ with these rewards Hay coffee Spam Choc. 4 ingredients (hay) & 4 smoothie recipes each recipe requires ingredients Hay- spam Spam- hay coffee Choco- hay ingredients recipes

source sink ingredient costs recipe rewards How do we use the results? What is flowing? tswift There are four ingredients available ~ at these costs hay-flavored coffee spam chocolate There are four smoothie recipes available ~ with these rewards Hay coffee Spam Choc. 4 ingredients (hay) & 4 smoothie recipes each recipe requires ingredients Hay- spam Spam- hay coffee Choco- hay One purple edge is missing… Which? ingredients recipes What should these capacities be?

general problems:max-flow problems: cowcarn feeding optimilk sandcas timecards tswift difficult-to-classify problems: This week's problems Try max flow! soda (last week) tour (last week)

This code only looks obfuscated!

Donut! donut.c International Obfuscated C Coding Contest This code IS obfuscated!

2011's winner… donut.c International Obfuscated C Coding Contest This code IS obfuscated!

Tools source Jobs sink tool costs task rewards How do we use the results? What is flowing? hardware There are four tools available ~ at these costs hammer TV coffee PC There are four tasks available ~ with these rewards hammer TV coffee PC 4 tools & 4 tasks each task requires some tools E4 waking folks in east sleep coding

dinner number of teams Input Output number of tables # of people in each team can an assignment be made without putting teammates together? 0101 capacity of each table again… end… tables with capacities teams with sizes seating assignments! no teammates

dinner's maxflow graph s source t sink How does the maxflow here relate to whether the seating is possible or not? Team Table fully connected with edge weights of 1 How do these edge weights reflect the problem constraints?

JRsSRsElderly slate 3 This term's first class to guess another's word earns 1 problem... slate 2slate 1 This term's last class to have its word guessed earns 1 problem... Sophs slate 1 flair 0flair 1flair 2flair 0 Pomona slate 3 flair 2 stems 3stems 1stems 2stems 1stems 2 loser 2loser 3loser 2loser 1 loser 3 stone 3stone 2stone 1 stone 2 guppy 1guppy 0guppy 1guppy 2guppy 0 Try max flow! lasso 1lasso 3lasso 1 lasso 2 pluot 1pluot 2pluot 1 pluot 0

old years…

hardware Tools source Jobs sink tool costs job rewards How can max flow help us here? What is flowing?

hardware Tools source Jobs sink tool costs job rewards How can max flow help us here? What is flowing?

number of cows Input total # of foods total # of drinks # of foods cow[i] likes # of drinks cow[i] likes foodsdrinks 0 Output # of cows that can receive both a food and a drink they like… 3 each can be used only once Likes foodsdrinks What is a cow-satisfying assignment here? dining

Jotto! SophsJrsSrs audio 1audio 2audio 1 Frosh audio 2 graze 3graze 1 graze 2 alloy 1 alloy 2 fresh 2 fresh 1 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... armor 2 armor 1armor 2 brave 3brave 1 brave 2 wreak 3wreak 1wreak 2 fjord 1fjord 5 fjord 1 fjord 2

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

Tools source Jobs sink task rewards tool costs How do we use mf to maximize our profit? What is flowing? hardware There are four tools available ~ at these costs hammer TV coffee PC There are four tasks available ~ with these rewards hammer TV coffee PC 4 tools & 4 tasks each task requires some tools E4 waking folks in east sleep coding

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

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

Dijkstra, for single-source shortest paths Put into your queue Q. While Q not empty: Remove Q's nearest node For each edge [n c, n k, d c2k ]: For all n k, track Let d k be n k 's distance: If d c + d c2k < d k : set d k = d c + d c2k Put into Q... S shortest dist from S

Dijkstra, for single-source shortest paths Put into your queue Q. While Q not empty: Remove Q's nearest node For each edge [n c, n k, d c2k ]: For all n k, track Let d k be n k 's distance: If d c + d c2k < d k : set d k = d c + d c2k Put into Q... S shortest dist from S

Jotto! SophsJrsSrs audio 1audio 2audio 1 Frosh audio 2 graze 3graze 1 graze 2 alloy 1 alloy 2 fresh 2 fresh 1 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... armor 2 armor 1armor 2 brave 3brave 1 brave 2 wreak 3wreak 1wreak 2 fjord 1fjord 5 fjord 1 fjord 2 taper 4taper 1 taper 2 tater 4tater 1 tater 2