Uploaded by Nguyen Xuan Ha

AI chap01 GraphColoring

advertisement
11/30/2020
ARTIFICIAL INTELLIGENCE
GRAPH COLORING
Le Thi Ngoc Tho, PhD
Faculty of Information Technology
Ho Chi Minh City University of Technology
ltn.tho@hutech.edu.vn
1
CONTENTS
• DEFINITION
• BASIC ALGORITHM
• “OPTIMIZED” ALGORITHM
• GREEDY ALGORITHM
AI - Le T.N. Tho - Graph Coloring
2
2
1
11/30/2020
PROBLEM DEFINITION
• Input: Graph 𝐺 = {𝑉, 𝐸}
• 𝑉: Set of vertices 𝑉 = {𝑣 , 𝑣 , ⋯ , 𝑣 }
• 𝐸: Set of edges connecting vertices 𝐸 = (𝑣 , 𝑣 )|𝑖 ≠ 𝑗 ∧
𝑣 ,𝑣 ∈ 𝑉
• Output: Color vertices of the graph such that:
• No adjacent vertices is colored the same.
• Minimize the number of required colors.
3
AI - Le T.N. Tho - Graph Coloring
3
PROBLEM DEFINITION
• Example:
a
c
b
e
d
h
f
Use 3 colors  Minimum number of colors?
AI - Le T.N. Tho - Graph Coloring
4
4
2
11/30/2020
APPLICATIONS
• Scheduling:
• Class schedule, examination schedule
• Sport match scheduling
• Arrange seats
• Car, taxi arrangement.
• Register distribution
AI - Le T.N. Tho - Graph Coloring
5
5
BASIC ALGORITHM
• Step 1: Assign color 1 to the first vertex
• Step 2: For the rest V-1 vertices:
• Choose one vertex;
• Assign to the chosen vertex the lowest numbered color,
such that the color has not been used for the neighbors;
• If all colors have been used for neighbors, create a new
color for the chosen vertex.
AI - Le T.N. Tho - Graph Coloring
6
6
3
11/30/2020
BASIC ALGORITHM
a
• Illustration:
a
e
d
h
Adjacent matrix
a
Graph
c
b
f
b
c
d
e
f
h
1
1
0
0
0
0
a
0
1
0
1
0
b
1
0
0
0
c
0
1
0
d
0
1
e
1
f
b
1
c
1
0
d
0
1
1
e
0
0
0
0
f
0
1
0
1
0
h
0
0
0
0
1
1
a
b
c
d
e
f
h
1
2
2
1
1
3
h
AI - Le T.N. Tho - Graph Coloring
2
7
7
“OPTIMIZED” ALGORITHM
• Step 1: [Color] Color 𝑖 (𝑖 is from 1) to the vertex
𝑣 whose degree is the highest;
• Step 2: [Downgrade & Prohibit]
1. Degree of vertex 𝑣 colored by 𝑖: 𝐷𝑒𝑔(𝑣) = 0,
2. Downgrade the degrees of all neighbors of 𝑣, say 𝑤:
𝐷𝑒𝑔(𝑤) −= 1,
3. Prohibit the color 𝑖 for all vertice 𝑤;
• Step 3: Repeat from step 1 for all the remaining vertices.
AI - Le T.N. Tho - Graph Coloring
8
8
4
11/30/2020
“OPTIMIZED” ALGORITHM
• Illustration:
Adjacent matrix
Graph
a
c
b
e
d
h
f
a
b
c
d
e
f
h
a
0
1
1
0
0
0
0
b
1
0
0
1
0
1
0
c
1
0
0
1
0
0
0
d
0
1
1
0
0
1
0
e
0
0
0
0
0
0
1
f
0
1
0
1
0
0
1
h
0
0
0
0
1
1
0
Deg
2
3
2
3
1
3
2
9
AI - Le T.N. Tho - Graph Coloring
9
“OPTIMIZED” ALGORITHM
• Illustration:
Adjacent matrix
Graph
Deg
a
c
b
e
d
h
f
AI - Le T.N. Tho - Graph Coloring
2
1
1
1
1,2
31
1
21
1,2
32
a
b
c
d
e
f
h
2
3
2
3
1
3
2
1
0
2
2
1
2
2
0
0
0
1
1
2
2
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10
10
5
11/30/2020
APPLICATIONS
• Scheduling football matches:
• There are 6 football teams A, B, C, D, E, F who are going to
play a round (1 round), knowing that the following matches
have been taken place:
• A has played with B, E.
• B has played with A, F.
• C has played with D, F.
• Due to the physical condition, each team play only one match
per week. Please schedule the match such that the number of
required weeks is least.
11
AI - Le T.N. Tho - Graph Coloring
11
APPLICATIONS
• Application: Scheduling football matches
• Determine graph:
• Vertices: Matches
A
B
C
D
A
AB AC AD
B
BC
C
E
F
AE AF
BD
BE
BF
CD
CE
CF
D
DE DF
E
EF
F
• Edges: Pairs of matches that have the same team
AI - Le T.N. Tho - Graph Coloring
12
12
6
11/30/2020
APPLICATIONS
• Edges: Pairs of matches that have the same team
AC
AD
AF
BC
BD
BE
CE
DE
DF
EF
Deg
AC
0
1
1
1
0
0
1
0
0
0
4
AD
1
0
1
0
1
0
0
1
1
0
5
AF
1
1
0
0
0
0
0
0
1
1
4
BC
1
0
0
0
1
1
1
0
0
0
4
BD
0
1
0
1
0
1
0
1
1
0
5
BE
0
0
0
1
1
0
1
1
0
1
5
CE
1
0
0
1
0
1
0
1
0
1
5
DE
0
1
0
0
1
1
1
0
1
1
6
DF
0
1
1
0
1
0
0
1
0
1
5
EF
0
0
1
0
0
1
1
1
1
0
5
13
AI - Le T.N. Tho - Graph Coloring
13
APPLICATIONS
• Application: Scheduling football matches
Deg
AC
AD
AF
BC
BD
BE
CE
DE
DF
EF
4
5
4
4
5
5
5
6
5
5
AI - Le T.N. Tho - Graph Coloring
14
14
7
11/30/2020
APPLICATIONS
• Scheduling topics in workshop
• A workshop includes 9 topics A, B, C, D, E, F, G, H, I.
Given that, the following topics are not allowed to be
presented in the same session: AC, BDE, ADG, CDF,
DFG, EGH, GHI.
• Please schedule the topics for workshop, such that the
number of sessions is minimum.
AI - Le T.N. Tho - Graph Coloring
15
15
APPLICATIONS
• Scheduling topics in workshop
• A workshop includes 9 topics A, B, C, D, E, F, G, H, I. Given
that, the following topics are not allowed to be presented in the
same session: AC, BDE, ADG, CDF, DFG, EGH, GHI.
• Please schedule the topics for workshop, such that the number
of sessions is minimum.
• Graph:
• Vertices: topics A, B, C, D, E, F, G, H, I
• Edges: connect two topics if they are not allowed to be
presented in the same session.
AI - Le T.N. Tho - Graph Coloring
16
16
8
11/30/2020
APPLICATIONS
• Scheduling topics in workshop: AC, BDE, ADG, CDF, DFG, EGH, GHI
A
B
C
D
E
F
G
H
I
Deg
A
0
0
1
1
0
0
1
0
0
3
B
0
0
0
1
1
0
0
0
0
2
C
1
0
0
1
0
1
0
0
0
3
D
1
1
1
0
1
1
1
0
0
6
E
0
1
0
1
0
0
1
1
0
4
F
0
0
1
1
0
0
1
0
0
3
G
1
0
0
1
1
1
0
1
1
6
H
0
0
0
0
1
0
1
0
1
3
I
0
0
0
0
0
0
1
1
0
2
17
AI - Le T.N. Tho - Graph Coloring
17
APPLICATIONS
• Scheduling topics in workshop
Deg
A
B
C
D
E
F
G
H
I
3
2
3
6
4
3
6
3
2
AI - Le T.N. Tho - Graph Coloring
18
18
9
11/30/2020
APPLICATIONS
• Scheduling examination:
• In semester 1 of academic year 2017-2018, we need to schedule
examination for courses A, B, C, D, E, F, G, H, I, such that the
following courses are not proceeded in the same session: ABC, AE,
BCD, BHI, EFG, EI, GHI.
• Please schedule the examination such that the number of sessions
required is minimum.
• Graph:
• Vertices: courses A, B, C, D, E, F, G, H, I
• Edges: connect two courses which are not proceeded in the same
session.
19
AI - Le T.N. Tho - Graph Coloring
19
APPLICATIONS
• Scheduling examination:
A
B
C
D
E
F
G
H
I
Deg
A
0
1
1
0
1
0
0
0
0
3
B
1
0
1
1
0
0
0
1
1
5
C
1
1
0
1
0
0
0
0
0
3
D
0
1
1
0
0
0
0
0
0
2
E
1
0
0
0
0
1
1
0
1
4
F
0
0
0
0
1
0
1
0
0
2
G
0
0
0
0
1
1
0
1
1
4
H
0
1
0
0
0
0
1
0
1
3
I
0
1
0
0
1
0
1
1
0
4
AI - Le T.N. Tho - Graph Coloring
20
20
10
11/30/2020
APPLICATIONS
• Scheduling examination:
Deg
A
B
C
D
E
F
G
H
I
3
5
3
2
4
2
4
3
4
21
AI - Le T.N. Tho - Graph Coloring
21
APPLICATIONS
• Broadcast station
• A company has 8 radio
station A, B, C, D, E, F,
G, H which have
A
B
C
D
E
distance (km) as
F
described in the matrix:
G
H
A
B
C
D
G
H
0
100
50
30
200 150
40
120
0
30
80
120
50
200
150
0
120 100
30
0
E
F
80
50
50
120 150
30
0
200 120
0
120
180
150
0
50
0
• Due to the technical requirements, radio stations with
distance ≥100km do not share the same broadcast station.
Suggest an implementation to minimize the number of the
broadcast stations.
AI - Le T.N. Tho - Graph Coloring
22
22
11
11/30/2020
GREEDY ALGORITHM
• Step 1: 𝑖 ≔ 0
• Step 2:
• 𝑖: = 𝑖 + 1
• Assign color i to all possible vertices.
• Step 3: Repeat step 2 until all vertices have been
colored.
23
AI - Le T.N. Tho - Graph Coloring
23
GREEDY ALGORITHM
• Illustration:
1
2
3
a
a
c
b
c
b
e
d
h
h
f
Start at vertex b
AI - Le T.N. Tho - Graph Coloring
e
d
f
Start at vertex f
24
24
12
11/30/2020
QUESTIONS & ANSWERS
AI - Le T.N. Tho - Graph Coloring
25
25
13
Download