Download presentation
Presentation is loading. Please wait.
1
Special Graphs: Modeling and Algorithms
2
Flow graph modeling Often, recognizing a task as network flow is biggest challenge. Example: Some number of users brings a set of applications (label ‘A’ to ‘Z’) to be run. There are 10 computers that can run applications (1 per day). Applications can only run on certain computers Create nodes for each application, each computer Create single source and single sink Create edge from source to each application node Set weight as the number of that application submitted by users Create edge from application node to computer nodes that can run it Weight can be 1, since only 1 program can run per computer Create edge from computer nodes to the sink Weight is 1, since each can run one program.
3
Another example (UVA problem 11380) – Titanic sinking
Grid of values: water (impassible) – ice with a person on it (will disappear once they leave), ice a person can move to (but will sink once they leave), iceberg (can hold people but not permanently), large wood (can hold people for safety, but only limited number) Create graph connecting adjacent nodes, high edge capacity Set node capacity for ice to 1 Create a source to all nodes with starting people (high edge weight) Create a sink from all wood nodes with weight equal to max. wood capacity.
4
Bipartite graph and Bipartite matching
Divide into two groups, A and B All edges are from something in group A to something in group B Bipartite matching Want to uniquely match one item from group A with one item in group B Called Maximum Cardinality Bipartite Matching (MCBM) Notice: Bipartite matching must have bipartite graph where |A| = |B| Given a bipartite graph, can do analysis to find a MCBM
5
Maximum Cardinality Bipartite Matching
Assign a source with an edge to every vertex in set 1 Assign a sink with an edge from every vertex in set 2 Run Max Flow If it can find flow of amount equal to |A| (and therefore |B|), we have a match If sets are unequal size, will find the best possible match (all of one should match to something from other, if possible)
6
Max Independent Set and Min Vertex Cover
Independent Set: no two vertices in set have edge between them Vertex Cover: every vertex is adjacent to some vertex in the set Number of vertices in min vertex cover is number in MCBM Number of vertices in max independent set is total number minus number in MCBM Note that finding these is a little different (but can use the MCBM matching for this)
7
MCBM with Augmenting Paths
Start at a free vertex (on “left”) Find a free edge to a vertex on “right”. Assume it is already matched. Follow the matched edge back to the “left” Repeat until reaching a free vertex on the right Then, reverse the order of all edges visited (from “free” <-> “matched” Easy to implement (relatively) and fast enough on most cases.
8
Edge-disjoint paths Paths in graphs – how many paths do not share an edge Convert each edge to a unit-weight edge If the graph is undirected, form two edges for each (one per direction) Max flow in the graph is the number of edge-disjoint paths
9
Circulation Each node has either supply or demand, edges have capacity
Create a new source with edges to the nodes with supply Edge weights are the amount of supply (negated) Create a new sink with edges from the nodes with demand Edge weights are the amount of demand Then, just run max flow! Several problems can be modeled as circulation problems
10
Other Graph Types DAG (Directed Acyclic Graph): Tree Eulerian Graph
Graph with an Eulerian path or tour: visits each edge exactly once Several algorithms can be simplified if the graph is of one of these types See book for examples
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.