graph coloring - utkweb.eecs.utk.edu/.../coloring_pres.pdfsudoku can be represented as a graph...

60
Graph Coloring Stephen Grady, David Eberius, and John Duggan

Upload: others

Post on 09-Sep-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Graph ColoringStephen Grady, David Eberius, and John Duggan

Page 2: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Three Types of Coloring● Vertex coloring● Edge coloring● Total coloring

Page 3: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Vertex Coloring● Proper vertex coloring - Labeling of all vertices

in a graph such that no two vertices sharing an edge share the same color

Page 4: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Edge Coloring● Proper coloring of edges - labeling of edges

such that no two edges that share the same vertex share the same color.

Page 5: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Total Coloring● Proper total coloring - Coloring of a graph such

that no adjacent vertices or adjacent edges share the same color.

Page 6: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Chromatic Number● Chromatic Number - minimum number of

colors needed to properly color a graph

Page 7: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Brooks’ Theorem● A connected, simple graph’s chromatic

number is no larger than the maximum vertex degree[1]

● Exception: complete and odd cycle graphs[1]

Page 8: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Chromatic Polynomial● Used to count the possible number of ways of

properly vertex coloring a graph.● Example:

P3 can be colored in 12 ways using 3 colors

Page 9: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Chromatic Equivalence Two graphs are chromatically equivalent if they share the same the same chromatic polynomial

Page 10: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

History● First presented as a map coloring problem● The problem: Given a planar graph, what is the

minimum number of colors that one can use to color all vertices?

Page 11: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

History: 4 vs 5 Coloring● In 1852, Francis Guthrie postulated the four

color conjecture when coloring the counties of England.[2]

● Interestingly, this theorem is not used by map makers.[3]

Page 12: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

History: 4 vs 5 ColoringAlfred Kempe followed this up in 1879 by publishing a paper claiming to prove the four color theorem.[2]

11 years later Percy John Heawood showed Kempe was mistaken in his proof but that four colors suffice still held true.[2]

Page 13: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

History: Kempe’s Flaw● Where did Kempe’s 4 color theorem go

wrong?

Page 14: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

History: 4 vs 5 ColoringThe four color theorem was finally proven in 1976 by Kenneth Appel and Wolfgang Haken[4,5]. (It should be said that this was proof was aided by a computer, so there was some controversy surrounding this proof.)

Page 15: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Complexity● Decision: NP-complete● Optimization: NP-hard

Page 16: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Algorithms ● Greedy Algorithms● Brute force algorithm● Parallel Processing algorithms

Page 17: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Greedy Coloring● Given a vertex order, assign each vertex the

first available color● Fast, but potentially poor

Page 18: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Vertex Ordering● Any graph has a vertex ordering for greedy

coloring that yields an optimal coloring● Finding this ordering for arbitrary graphs is

NP-hard

Page 19: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Welsh-Powell Algorithm● Provides an upper-bound on the number of

colors used by greedy coloring[6]

● Order vertices by descending degree

Page 20: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Welsh-Powell Example

Page 21: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Welsh-Powell Example

Page 22: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Chordal Graphs● All cycles of 4 or more vertices have a chord● Chord - an edge not in the cycle which

connects 2 of the vertices

Page 23: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Perfect Elimination Ordering

● A graph is chordal iff it has a perfect elimination ordering[7]

● Each vertex and its neighbors which follow it in the order form a clique[7]

● This ordering can be found using lexicographic BFS[7]

Page 24: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Lexicographic BFS1. Begin with all vertices in a single set2. Remove a vertex v from the first set3. Place this vertex at the end of the order4. Divide each set into two subsets: neighbors of v and

non-neighbors of v.5. Repeat 2-4 until all vertices are in the order

Note: if we reverse this ordering, we get a perfect elimination ordering (if one exists)

Page 25: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Brute ForceThe brute force search is highly inefficient as it runs through each possibility of kn where k is the number of colors and n the number of vertices.

Page 26: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Brute Force● The key factor for the inefficiency of the

brute force algorithm is the sheer number of colorings to check.

● Is there a way to reduce the number of colorings?

Page 27: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Brute Force● Number of Colorings Used:

○ C = 1 -> 1 coloring○ 1 < C < V -> ???○ C = V -> 1 coloring

● This is still a huge number of colorings, so it’s still extremely slow!

Page 28: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Brute Force Algorithm● Generate all possible combinations of

‘guarantee’ spots for all C where 1 < C < V○ For each of these combinations, generate all

possible permutations of C colors from 0 to C-1■ For each of the above permutations, generate all

possible combinations of colors in the remaining V-C spots by counting in base C with V-C digits.

Page 29: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Brute Force Algorithm● Test each coloring combination for validity.● If a valid coloring is found, stop generating

possibilities, because the current C is the chromatic number.○ If this is true, what order did I test my colorings in?

Page 30: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Parallel Processing● Performing work on multiple processors at

the same time.● You must divide tasks up such that there

aren’t any dependences between tasks that are running at the same time.○ DMV Analogy○ What are dependences?

Page 31: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Matrix Matrix Multiply● Multiply two matrices

together.● This algorithm is one

of the quintessential parallel programming algorithms.

Page 32: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Matrix Matrix Multiply● The Algorithm:

○ For each row of the left side matrix, multiply the ith element with the ith element of the corresponding column in the right matrix.

○ The sum of these multiplications is put at the [r][c] spot of the result matrix.

for(int r = 0; r < dim; r++) { for(int c = 0; c < dim; c++) { sum = 0; for(int i = 0; i < dim; i++) { sum += matrix[r][i] * matrix[i][c]; } result[r][c] = sum; } }

Page 33: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Parallel Processing Algorithms

● Times are in seconds.

● Sizes are of M by M matrices.

● 4 Hyperthreaded cores were used.

Page 34: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Parallel Brute Force● Used nearly the same algorithm as the serial

version, with the following differences:○ Generate N choices for the ‘guarantee’ spots, where

N is the number of parallel threads.○ Assign each thread to generate the subsequent

possible colorings for these spots and test whether they are valid colorings.

○ Merge all threads and check for completion.

Page 35: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Implementations● Greedy coloring

○ Random vertex ordering○ Welsh-Powell ordering○ Ordering by lexicographic BFS

● Brute force● Parallelized brute force

Page 36: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Results (greedy)

Page 37: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Results (greedy)Random Welsh-Powell Lex. BFS

random_5_5.txt 3 3 3

random_10_20.txt 4 4 4

random_20_35.txt 4 4 5

random_40_100.txt 5 4 5

random_100_500.txt 6 6 7

random_200_600.txt 6 5 6

random_500_1500.txt 6 6 6

Page 38: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Results (brute force)● Small graphs run quickly,

but the run times grow exponentially.○ Note: Timings are in

seconds.○ The longest runs for each

category took 137.68 and 68.87 minutes respectively.

Page 39: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Results (parallel)● Timings are in

seconds.● All graphs were

cliques.● Speedup less than 1

means parallel is slower.

Page 40: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Applications● Sudoku● Register Allocation● Scheduling Problem

Page 41: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

SudokuA game in which the goal is to create a 9x9 chart where no number shares a column, row or 3x3 square.

Page 42: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Sudoku

Page 43: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Sudoku● Sudoku can be represented as a graph coloring

problem● Transform the board into a graph with 81

vertices where two vertices that shares a column, row or 3x3 square are connected by an edge. Now color using 9 colors.

Page 44: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Sudoku

Page 45: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Register Allocation● At compile time, the compiler allocates registers

to certain variables in a program. Multiple variables can exist in the same register but they cannot be called at the same time, so allocating them becomes a coloring problem.

Page 46: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Register Allocation

Page 47: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Scheduling ProblemGraph coloring can be used to find the minimum number of time slots needed to create a schedule with no time conflicts

Page 48: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Example● Finals will be here soon so we’ll use that as our

example.● For each Student list out what classes are being

taken● Student1 {biology, diff. eq, bio stats, graph algo }● Student2 {English lit, journalism, biology, pchem1}● Student3 {bio stats, modern physics, modern physics

lab}

Page 49: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Example continued● Each vertex represents a class and an edge

between vertices represents a student taking both.

So our example becomes….

Page 50: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Example continued

Page 51: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Example Continued● Now we simply color to determine how many

time slots are required to make sure there are now time conflicts.

The above graph becomes...

Page 52: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Final ScheduleFor the example there should be 4 time slots.

Page 53: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Open Problems● Is there a polynomial time algorithm for

checking if a k-coloring for a graph exists?

Page 54: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Open Problems● Erdős-Faber-Lovász Conjecture - the union of n

pairwise edge-disjoint complete graphs with n vertices is n-colorable

Page 55: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Open Problems● Reed’s upper bound[8]:

(G) ≤ (1 + (G) + (G)) / 2

Page 56: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

References1. Brooks, R.L. On Colouring the Nodes of a Network. Mathematical Proceedings of the

Cambridge Philosophical Society, April 1941.2. Thomas, Robin. The Four Color Theorem. School of Mathematics, Georgia Institute of

Technology. http://people.math.gatech.edu/~thomas/FC/fourcolor.html.3. Wilson, Robin. Four Colors Suffice. London: Penguin Books, 2002.4. Appel, Kenneth and Wolfgang Haken. Every Planar Map is Four Colorable Part I. Discharging.

Illinois Journal of Mathematics, 1977.5. Appel, Kenneth et al. Every Planar Map is Four Colorable Part II. Reducibility. Illinois Journal

of Mathematics, 1977.6. Welsh, D.J.A. and M.B. Powell. An Upper Bound for the Chromatic Number of a Graph and Its

Application to Timetabling Problems. The Computer Journal, 1967.7. Rose, Donald J. et al. Algorithmic Aspects of Vertex Elimination on Graphs. SIAM Journal on

Computing, 1976.8. http://www.math.illinois.edu/~dwest/openp/

Page 57: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Email answers to [email protected].

1. Use the lexicographical BFS algorithm to produce an ordering for the following graph (details on next page):

Homework

0

2

13

5

4 6

Page 58: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

HomeworkFor question 1, begin with vertex 6. When breaking ties, select the lowest-numbered vertex. See http://en.wikipedia.org/wiki/Lexicographic_breadth-first_search for more details on the algorithm itself.

Page 59: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Homework2. What is the chromatic number of this graph?

A

B

C

D

E

F

G

H

I

Page 60: Graph Coloring - UTKweb.eecs.utk.edu/.../coloring_pres.pdfSudoku can be represented as a graph coloring problem Transform the board into a graph with 81 vertices where two vertices

Homework3. Given 9 classes and 3 students with schedules:

Student 1 {1,2,6,9}Student 2 {2,3,4,7}Student 3 {1,5,8,9}

How many time slots are needed to guarantee no schedule conflicts?