Graph Coloring and Applications

Slides:



Advertisements
Similar presentations
Bart Jansen 1.  Problem definition  Instance: Connected graph G, positive integer k  Question: Is there a spanning tree for G with at least k leaves?
Advertisements

Register Usage Keep as many values in registers as possible Register assignment Register allocation Popular techniques – Local vs. global – Graph coloring.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Register Allocation after Classical SSA Elimination is NP-complete Fernando M Q Pereira Jens Palsberg - UCLA - The University of California, Los Angeles.
Lauritzen-Spiegelhalter Algorithm
The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Playing Fair at Sudoku Joshua Cooper USC Department of Mathematics.
CS774. Markov Random Field : Theory and Application Lecture 17 Kyomin Jung KAIST Nov
Agenda: Problem statement Graph Construction Relation to graph problem Special Property Problem solution References.
Train DEPOT PROBLEM USING PERMUTATION GRAPHS
Applied Combinatorics, 4th Ed. Alan Tucker
Last time: terminology reminder w Simple graph Vertex = node Edge Degree Weight Neighbours Complete Dual Bipartite Planar Cycle Tree Path Circuit Components.
Introduction to Approximation Algorithms Lecture 12: Mar 1.
1 CS 201 Compiler Construction Lecture 12 Global Register Allocation.
Vertex Cover, Dominating set, Clique, Independent set
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
Graph Colouring Lecture 20: Nov 25.
Register Allocation (via graph coloring)
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Register Allocation (via graph coloring). Lecture Outline Memory Hierarchy Management Register Allocation –Register interference graph –Graph coloring.
Coloring Algorithms and Networks. Coloring2 Graph coloring Vertex coloring: –Function f: V  C, such that for all {v,w}  E: f(v)  f(w) Chromatic number.
Graph Theory Ch.5. Coloring of Graphs 1 Chapter 5 Coloring of Graphs.
Graph Coloring.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
1 Treewidth, partial k-tree and chordal graphs Delpensum INF 334 Institutt fo informatikk Pinar Heggernes Speaker:
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
ANALYSIS AND IMPLEMENTATION OF GRAPH COLORING ALGORITHMS FOR REGISTER ALLOCATION By, Sumeeth K. C Vasanth K.
1 Graph Coloring: An Overview Graph Coloring Basics Planar/4-color Graphs Applications New Register Allocation Technique.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Chapter 10.8 Graph Coloring
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
NP-Complete problems.
Graph Colouring Lecture 20: Nov 25. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
NPC.
Great Theoretical Ideas in Computer Science for Some.
Chapter 10.8 Graph Coloring These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 7 th ed., by Kenneth.
COMPSCI 102 Introduction to Discrete Mathematics.
Register Allocation Ajay Mathew Pereira and Palsberg. Register allocation via coloring of chordal graphs. APLOS'05Register allocation via coloring of chordal.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Xuding Zhu National Sun Yat-sen University Circular chromatic index.
Presented By Ravindra Babu, Pentyala.  Real World Problem  What is Coloring  Planar Graphs  Vertex Coloring  Edge Coloring  NP Hard Problem  Problem.
Single Static Assignment Intermediate Representation (or SSA IR) Many examples and pictures taken from Wikipedia.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The NP class. NP-completeness
Global Register Allocation Based on
Graph Coloring.
Graph Coloring Lots of application – be it mapping routes, coloring graphs, building redundant systems, mapping genes, looking at traffic patterns (see.
Richard Anderson Lecture 26 NP-Completeness
Great Theoretical Ideas In Computer Science
Algorithms and Networks
Graph Coloring CS 594 Stephen Grady.
Great Theoretical Ideas in Computer Science
ICS 353: Design and Analysis of Algorithms
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
Parameterised Complexity
Graph Theory Graph Colorings.
Chapter 10.8 Graph Coloring
Chapter 10.8 Graph Coloring
Chapter 10.8 Graph Coloring
Graph Coloring.
Chapter 10.8 Graph Coloring
Lecture 17: Register Allocation via Graph Colouring
Register Allocation via Coloring of Chordal Graphs
Discrete Mathematics for Computer Science
CSE 589 Applied Algorithms Spring 1999
CS 201 Compiler Construction
Presentation transcript:

Graph Coloring and Applications Presented by Adam Cramer

Overview Graph Coloring Basics Planar/4-color Graphs Applications Chordal Graphs New Register Allocation Technique

Basics Assignment of "colors" to certain objects in a graph subject to certain constraints Vertex coloring (the default) Edge coloring Face coloring (planar) an edge coloring assigns a color to each edge so that no two incident edges share the same color, and a face coloring of a planar graph assigns a color to each face or region so that no two faces that share a boundary share the same color Unless otherwise specified, vertex coloring is assumed

Not Graph Labeling Graph coloring Graph labeling Just markers to keep track of adjacency or incidence Graph labeling Calculable problems that satisfy a numerical condition Graph coloring is not to be confused with graph labeling, which is an assignment of labels, usually also in the form of numbers, to vertices or edges. In graph coloring problems, colors (e.g. 1, 2, 3...) are nothing more than markers for keeping track of adjacency or incidence. In graph labeling problems, labels (e.g. 1, 2, 3...) are calculable values that need to satisfy a certain numerical condition in the definition of the labeling.

Vertex coloring In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices share the same color Edge and Face coloring can be transformed into Vertex version an edge coloring of a graph is just the vertex coloring of its line graph, and a face coloring of a planar graph is just the vertex coloring of its (planar) dual.

Vertex Color example Anything less results in adjacent vertices with the same color Known as “proper” 3-color example

Vertex Color Example 1 2 3 4 5

Vertex Color Example 1 2 3 4 5

Chromatic Number χ - least number of colors needed to color a graph Chromatic number of a complete graph: χ(Kn) = n Complete graph has an edge between every two vertices

Properties of χ(G) χ(G) = 1 if and only if G is totally disconnected χ(G) ≥ 3 if and only if G has an odd cycle (equivalently, if G is not bipartite) χ(G) ≥ ω(G) (clique number) χ(G) ≤ Δ(G)+1 (maximum degree) χ(G) ≤ Δ(G) for connected G, unless G is a complete graph or an odd cycle (Brooks' theorem). χ(G) ≤ 4, for any planar graph The “four-color theorem” Degree = the number of edges incident to v, with loops being counted twice.

Four-color Theorem Dates back to 1852 to Francis Guthrie Any given plane separated into regions may be colored using no more than 4 colors Used for political boundaries, states, etc Shares common segment (not a point) Many failed proofs states that given any plane separated into regions, such as a political map of the states of a country, the regions may be colored using no more than four colors in such a way that no two adjacent regions receive the same color First major theorem to be proven using a computer, and the proof is not accepted by all mathematicians because it would be unfeasible for a human to verify by hand

Four-color Theorem

Four-color Theorem

Algorithmic complexity Finding minimum coloring: NP-hard Decision problem: “is there a coloring which uses at most k colors?” Makes it NP-complete It remains NP-complete even on planar graphs of degree at most 4, as shown by Garey and Johnson in 1974[1], although on planar graphs it's trivial for k > 3 (due to the four color theorem). There are however some efficient approximation algorithms The case k = 2 is equivalent to determining whether or not the graph is bipartite. This can be accomplished in polynomial time. For k >= 3 the problem is NP-Complete. By the gap theorem, this implies that the problem can not be approximated by a polynomial algorithm within a factor of 4/3 unless P=NP.

Coloring a Graph - Applications Sudoku Scheduling Mobile radio frequency assignment Pattern matching Register Allocation

Register Allocation with Graphs Coloring Register pressure How determine what should be stored in registers Determine what to “spill” to memory Typical RA utilize graph coloring for underlying allocation problem Build graph to manage conflicts between live ranges Colors used to show when cannot share same register Better way to do RA with graphs

Chordal Graphs Each cycle of four or more nodes has a chord Subset of perfect graphs Also known as triangulated graphs graph is chordal if each of its cycles of four or more nodes has a chord, which is an edge joining two nodes that are not adjacent in the cycle.

Chordal Graph Example Removing a green edge will make it non-chordal A cycle (black) with two chords (green). As for this part, the graph is chordal. However, removing one green edge would result in a non-chordal graph. Indeed, the other green edge with three black edges would form a cycle of length four with no chords.

RA with Chordal Graphs Normal register allocation was an NP-complete problem Graph coloring If program is in SSA form, it can be accomplished in polynomial time with chordal graphs! Thereby decreasing need for registers

Quick Static Single Assignment Review SSA Characteristics Basic blocks Unique naming for variable assignments Φ-functions used at convergence of control flows Improves optimization constant propagation dead code elimination global value numbering partial redundancy elimination strength reduction register allocation

RA with Chordal Graphs SSA representation needs fewer registers Key insight: a program in SSA form has a chordal interference graph Very Recent Programs in SSA form need the same or smaller number of registers than that of the original program The key insight is that a program in SSA form has a chordal interference graph..

RA with Chordal Graphs cont Result is based on the fact that in strict-SSA form, every variable has a single contiguous live range Variables with overlapping live ranges form cliques in the interference graph

RA with Chordal Graphs cont Greedy algorithm can color a chordal graph in linear time New SSA-elimination algorithm done without extra registers Result: Simple, optimal, polynomial-time algorithm for the core register allocation problem A greedy algorithm can optimally color a chordal graph in linear time in the number of edges. Completing the picture, Hack et al. have presented a new SSA-elimination algorithm that does not demand extra registers. The combined result is a simple, optimal, polynomial-time algorithm for a core register allocation problem. The new SSA-elimination algorithm of Hack et al. is essential because classical SSA elimination leads to an Npcomplete core register allocation problem, as shown by Palsberg and Pereira. Register allocation with spilling for SSA form remains NP-complete

Chordal Color Assignment Algorithm: Chordal Color Assignment Input: Chordal Graph G = (V, E), PEO σ Output: Color Assignment f : V → {1… χG} For Integer : i ← 1 to |V| in PEO order Let c be the smallest color not assigned to a vertex in Ni(vi) f(vi) ← c EndFor The basic idea of an elimination order is that graph Gi+1 can be constructed from Gi by adding vi+1 to Vi and adding all edges belonging to Ni(vi+1) to Ei A Perfect Elimination Order (PEO) is an elimination order that satisfies the property that Ni(vi) is a clique in Gi. A PEO for a chordal graph can be computed in O(|V| + |E|) time using Maximum Cardinality Search (MCS)

Conclusion Graph Coloring Chordal Graphs New Register Allocation Technique Polynomial time

References http://en.wikipedia.org Engineering a Compiler, Keith D. Cooper and Linda Torczon, 2004 http://www.math.gatech.edu/~thomas/FC/fourcolor.html An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs, Philip Brisk, et. Al., CASES 07 Register Allocation via Coloring of Chordal Graphs, Jens Palsberg, CATS2007

Questions? Thank you