ACM today The Fall competition is getting organized… it's going to be lonely…

Slides:



Advertisements
Similar presentations
§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
Advertisements

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.
Reducibility Class of problems A can be reduced to the class of problems B Take any instance of problem A Show how you can construct an instance of problem.
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.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
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.
Maximum Flow Computation Programming Puzzles and Competitions CIS 4900 / 5920 Spring 2009.
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
Multi-Source Shortest Paths T. Patrick Bailey CSC 5408 Graph Theory 4/28/2008.
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)
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1, a 2, …, a n } and a size.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 04 / 29 / 2009 Instructor: Michael Eckmann.
Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a1, a2, …, an} and a size s(a)
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
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.
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.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
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.
ACM today Some nice unix commands… practice problems? code.google.com/codejam/ This week: beyond Floyd-Warshall.
ACM today This week's problems… New and improved :-) ACM table slacking! not slacking… missing entries? let me know…
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Honors Track: Competitive Programming & Problem Solving Fun with Graphs II Kevin Verbeek.
& 6.855J & ESD.78J Algorithm Visualization The Ford-Fulkerson Augmenting Path Algorithm for the Maximum Flow Problem.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
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.
NETWORK FLOWS Shruti Aggrawal Preeti Palkar. Requirements 1.Implement the Ford-Fulkerson algorithm for computing network flow in bipartite graphs. 2.For.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
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.
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
Finding a Path With Largest Smallest Edge
Linear Programming (LP) (Chap.29)
CS4234 Optimiz(s)ation Algorithms
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Jotto! Frosh Sophs Jrs Srs audio 2 audio 1 audio 2 audio 1 graze 2
CS120 Graphs.
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Graphs Chapter 13.
CSE 373 Data Structures and Algorithms
Jotto! Sophs Jrs Srs Profs pluot 1 pluot 2 pluot 1 pluot 2 squid 2
Chapter 11 Graphs.
Flow Networks and Bipartite Matching
Honors Track: Competitive Programming & Problem Solving Avoiding negative edges Steven Ge.
Algorithms (2IL15) – Lecture 7
CSE 373: Data Structures and Algorithms
EE5900 Advanced Embedded System For Smart Infrastructure
CSE 373: Data Structures and Algorithms
Graphs: Shortest path and mst
Presentation transcript:

ACM today The Fall competition is getting organized… it's going to be lonely…

Mock mock contest #2 More teams solved problems; more problems were solved All problems solved by some team shippingforwardpanic all-pairs shortest paths could be used for this one… following calls through a graph of forwarding instructions Still one computer per team… API-reference is OK on another machine

Infinities seen…

int BIG = ; Michael E.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R. int constant = 1000; Zvi E.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R. int constant = 1000; Zvi E. public static int Inf = 200; George T.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R. int constant = 1000; Zvi E. public static int Inf = 200; George T. adjacency[a][b] = 0; Andrew H.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R. int constant = 1000; Zvi E. public static int Inf = 200; George T. adjacency[a][b] = 100; Andrew H. int infinity = 31; Kwang K.

Infinities seen… int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R. int constant = 1000; Zvi E. public static int Inf = 200; George T. adjacency[a][b] = 100; Andrew H. int infinity = 31; Kwang K. #define INFINITE 0x0fffffff Andrew F.

Infinities seen… for (int woo = 0; woo < tries; woo++) { int hashnode(char *buf) { int hv = 0; while(*buf) { hv <<= 6; hv |= *buf++ & 31; } return hv; } int BIG = ; Michael E. grid[j][k] = ; Scott P. paths[i][j] = 9001; Martin P. direct = 2400; Russ R. int constant = 1000; Zvi E. public static int Inf = 200; George T. adjacency[a][b] = 100; Andrew H. int infinity = 31; Kwang K. #define INFINITE 0x0fffffff Andrew F.

Schedule 10/2/ /9/ /16/ /23/ /30/ /6/ /13/2007 Today -- search and related problems Lab / mock mock contest No class: conference & fall break… Real mock contest - "real" rules apply Meeting for ACM teams Final CS 189 meeting: contest wrap-up 9pm to 1am Tuesday, 10/30 one more algorithm

Max Flow A B E D C 13 F source capacity sink The problem how much traffic can get from the source to the sink ? Ford-Fulkerson algorithm

Max Flow The problem how much traffic can get from the source to the sink ? A B E D C 13 A B C D E FROM ABCDE F F F TO “Capacity Graph” source sink capacity C

Find a path in C via BFS The problem how much traffic can get from the source to the sink ? A B E D C 13 FROM F TO source sink capacity C A B C D E ABCDE F F need to add this into here…

Create F Create a FLOW GRAPH with the minimum weight from that path A B E D C 13 A B C D E FROM ABCDE F F F TO “Flow Graph” source sink capacity F 12 flow in one direction is negative flow in the other direction

R = C - F Create a RESIDUAL GRAPH with the rest of the capacity after that flow A B E D C 13 A B C D E FROM ABCDE F F F TO “Residual Graph” source sink capacity R 12 reverse edges allow the "undoing" of previous flow!

Keep going! Continue running this on the residual capacity until BFS fails… A B E D C 12/13 F 11/16 0/101/4 0/9 12/12 11/14 7/7 19/20 4/4 source sink There is no longer a path from A to F !

The max flow algorithm A B E D C 13 F “Residual Graph” source sink capacity flow Don't need to keep R around explicity: Keep only the current flow (F) and the original capacity (C). A B C D E F residual Floyd-Fulkerson 1. Set F to all 0 2. Compute R = C - F 3. BFS in R from source to sink. 3a. If no path, you’re done. 3b. If  a path, add the available capacity to F; goto (2).

Get into the flow! def edmonds_karp(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 flow = float(1e309) # Infinity ! # traverse path to find smallest capacity for (u,v) in path: flow = min(flow, C[u][v] - F[u][v]) # traverse path to update flow for u,v in path: F[u][v] += flow F[v][u] -= flow return sum([F[source][i] for i in xrange(n)]) def BFS(C, F, source, sink): queue = [source] paths = {source: []} while queue: u = queue.pop(0) for v in range(len(C)): if C[u][v] - F[u][v] > 0 and v not in paths: # Python == English ! paths[v] = paths[u] + [(u,v)] if v == sink: return paths[v] queue.append(v) return None Pseudo-code (Python) A little bit of name contention… edmonds_karp is really Ford-Fulkerson, but with other people getting the credit…

Max flow examples… Dinner problem Circuses problem A E C F D B G Circus inspectors need to visit every circus -- starting from anywhere. What is the smallest # of inspectors needed to visit each node without overlap? There are M teams with M[i] team members T tables with T[i] seating capacity No two members from one team should share a table. Can you still seat everyone? tables with capacities team sizes

How does maxflow help… ? The problem Fewest number of people to reach all nodes without coinciding... A E C F D B G one instance ABCDEFG S T ABCDEFG answer is N-maxflow (all edges 1 unit) graph of constraints

Get into the flow! def edmonds_karp(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 flow = float(1e309) # Infinity ! # traverse path to find smallest capacity for (u,v) in path: flow = min(flow, C[u][v] - F[u][v]) # traverse path to update flow for u,v in path: F[u][v] += flow F[v][u] -= flow return sum([F[source][i] for i in xrange(n)]) def BFS(C, F, source, sink): queue = [source] paths = {source: []} while queue: u = queue.pop(0) for v in range(len(C)): 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) return None Pseudo-code (Python) A little bit of name contention… edmonds_karp is really Floyd-Fulkerson, but with other people getting the credit… many problems require no more than BFS or DFS

Problem Set #5: Search algorithms, etc. orchard gumbo getout sq circuses

Subdividing Squares orchard gumbo getout sq circuses 9 smaller squares that cover a larger 7x7 square Input Output side length in the larger square # of problems smallest number of smaller squares covering the original

Counting trees Input vertices of a polygon on a single line of input Output orchard.X 15 1 right-justified number of lattice points in each polygon 0,0 7,7

Java Geometry

Ascii Geometry START 3 -10,-2,1 300,14.5, ,-80,0 400,28.75,26 n #^^# oU ## o ooooooooooo o oooooo o oooo o DDDD oo DDDD D D TT TT END number of bullets to be fired Input velocity of the target bullet velocities: N, E, up target shape getout.X the bullets are fired 10m due south of the center of the target

Ascii Geometry START 3 -10,-2,1 300,14.5, ,-80,0 400,28.75,26 n #^^# oU ## o ooooooooooo o oooooo o oooo o DDDD oo DDDD D D TT TT END number of bullets to be fired Input velocity of the target bullet velocities: N, E, up target shape Output getout.X * #^^# oU ## o ooooooooooo o oooooo o oooo o DDDD oo DDDD D D TT TT asterisk indicating hits the bullets are fired 10m due south of the center of the target Matt Streshinsky… each ASCII character is 10cm x 10cm

Jotto… SophomoresJuniorsSeniorsMe fjord 3fjord 0fjord 1fjord 2 tempt 1 marks 1 tempt 1 marks 3 tempt 2 marks 0 tempt 0 marks 1 diner 1 diner 0diner 2 chore 2chore 0chore 1

See you next week!

ACM today The Fall competition is getting organized…

Schedule 10/2/ /9/ /16/ /23/ /30/ /6/ /13/2007 Today -- search and misc problems Lab / mock mock contest No class: conference & fall break… Real mock contest - "real" rules apply Meeting for ACM teams Final CS 189 meeting: contest wrap-up 9pm to 1am Tuesday, 10/30

Max Flow The problem how much traffic can get from the source to the sink ? A B E D C 13 A B C D E FROM ABCDE F F F TO “Capacity Graph” source sink capacity C

Create F Create a FLOW GRAPH with the minimum weight from that path A B E D C 13 A B C D E FROM ABCDE F F F TO “Flow Graph” source sink capacity F 12 flow in one direction is negative flow in the other direction

R = C - F Create a RESIDUAL GRAPH with the rest of the capacity after that flow A B E D C 13 A B C D E FROM ABCDE F F F TO “Residual Graph” source sink capacity R 12 reverse edges allow the "undoing" of previous flow!

Keep going! Continue running this on the residual capacity until BFS fails… A B E D C 12/13 F 11/16 0/101/4 0/9 12/12 11/14 7/7 19/20 4/4 source sink There is no longer a path from A to F !

The max flow algorithm A B E D C 13 F “Residual Graph” source sink capacity flow Don't need to keep R around explicity: Keep only the current flow (F) and the original capacity (C). A B C D E F residual Floyd-Fulkerson 1. Set F to all 0 2. Compute R = C - F 3. BFS in R from source to sink. 4a. If no path, you’re done. 4b. If  a path, add the available capacity to F; goto (2).

Get into the flow! def edmonds_karp(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 flow = float(1e309) # Infinity ! # traverse path to find smallest capacity for (u,v) in path: flow = min(flow, C[u][v] - F[u][v]) # traverse path to update flow for u,v in path: F[u][v] += flow F[v][u] -= flow return sum([F[source][i] for i in xrange(n)]) def BFS(C, F, source, sink): queue = [source] paths = {source: []} while queue: u = queue.pop(0) for v in range(len(C)): 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) return None Pseudo-code (Python) A little bit of name contention… edmonds_karp is really Floyd-Fulkerson, but with other people getting the credit…

Max flow examples… Dinner problem Circuses problem A E C F D B G Circus inspectors need to visit every circus -- starting from anywhere. What is the smallest # of inspectors needed to visit each node without overlap? There are M teams with M[i] team members T tables with T[i] seating capacity No two members from one team should share a table. Can you still seat everyone? tables with capacities team sizes

Subdividing Squares orchard gumbo getout sq circuses 9 smaller squares that cover a larger 7x7 square Input Output side length in the larger square # of problems smallest number of smaller squares covering the original

Java Geometry

Jotto… SophomoresJuniorsSeniorsMe fjord 3fjord 0fjord 1fjord 2 tempt 1 marks 1 tempt 1 marks 3 tempt 2 marks 0 tempt 0 marks 1

Ascii Geometry number of dimensions Input starting point and destination point edges in the graph next number of dimensions Output Maze #1 can be traveled Maze #2 cannot be traveled getout.X