a fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden...

13
J Comb Optim DOI 10.1007/s10878-015-9862-1 A fast greedy sequential heuristic for the vertex colouring problem based on bitwise operations Larisa Komosko 1 · Mikhail Batsyn 1 · Pablo San Segundo 2 · Panos M. Pardalos 1,3 © Springer Science+Business Media New York 2015 Abstract In this paper a fast greedy sequential heuristic for the vertex colouring problem is presented. The suggested algorithm builds the same colouring of the graph as the well-known greedy sequential heuristic in which on every step the current vertex is coloured in the minimum possible colour. Our main contributions include introduction of a special matrix of forbidden colours and application of efficient bitwise operations on bit representations of the adjacency and forbidden colours matrices. Computational experiments show that in comparison with the classical greedy heuristic the average speedup of the developed approach is 2.6 times on DIMACS instances. Keywords Graph colouring · Heuristic · Bitwise operations · Greedy algorithm · Sequential colouring B Panos M. Pardalos pardalos@ufl.edu Larisa Komosko [email protected] Mikhail Batsyn [email protected] Pablo San Segundo [email protected] 1 Laboratory of Algorithms and Technologies for Networks Analysis, National Research University Higher School of Economics, 136 Rodionova, Nizhny Novgorod, Russia 603093 2 Centre for Automation and Robotics (UPM-CSIC), C/ Jose Gutierrez Abascal, 2, 28006 Madrid, Spain 3 Center for Applied Optimization, University of Florida, 401 Weil Hall, P.O. Box 116595, Gainesville, FL 32611-6595, USA 123

Upload: others

Post on 26-Feb-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb OptimDOI 10.1007/s10878-015-9862-1

A fast greedy sequential heuristic for the vertexcolouring problem based on bitwise operations

Larisa Komosko1 · Mikhail Batsyn1 ·Pablo San Segundo2 · Panos M. Pardalos1,3

© Springer Science+Business Media New York 2015

Abstract In this paper a fast greedy sequential heuristic for the vertex colouringproblem is presented. The suggested algorithm builds the same colouring of the graphas the well-known greedy sequential heuristic in which on every step the currentvertex is coloured in the minimum possible colour. Our main contributions includeintroduction of a special matrix of forbidden colours and application of efficient bitwiseoperations on bit representations of the adjacency and forbidden colours matrices.Computational experiments show that in comparison with the classical greedy heuristicthe average speedup of the developed approach is 2.6 times on DIMACS instances.

Keywords Graph colouring · Heuristic · Bitwise operations · Greedy algorithm ·Sequential colouring

B Panos M. [email protected]

Larisa [email protected]

Mikhail [email protected]

Pablo San [email protected]

1 Laboratory of Algorithms and Technologies for Networks Analysis, National ResearchUniversity Higher School of Economics, 136 Rodionova, Nizhny Novgorod, Russia 603093

2 Centre for Automation and Robotics (UPM-CSIC), C/ Jose Gutierrez Abascal, 2, 28006 Madrid,Spain

3 Center for Applied Optimization, University of Florida, 401 Weil Hall, P.O. Box 116595,Gainesville, FL 32611-6595, USA

123

Page 2: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

1 Introduction

The vertex colouring problem (VCP) is a well-known combinatorial optimizationproblem. It is one of the Karp’s 21 original NP-complete problems (Karp 1972). Forthis class of problems it is impossible to find an exact solution in reasonable time asthe solution space increases in exponential dependency on the input data size.

The VCP consists in finding the minimum number of colours needed to colour allvertices of a graph in such a way that any two adjacent vertices have different colours.The VCP finds applications in various areas. Good surveys can be found in Pardaloset al. (1999) and Erciyes (2013).

A number of timetabling problems can be reduced to it. In this case graph verticesrepresent courses which should be included to the timetable and colours represent timeintervals during which several courses are held in parallel. An edge is added betweentwo vertices if the corresponding courses cannot be held simultaneously (Welsh andPowell 1967; MirHassani and Habibi 2013).

The problem of processor registers allocation for variables in program code duringthe compilation process could also be reduced to the VCP. In this case graph verticesare variables and their colours are processor registers. An edge connects two verticesif the lifetimes of the two variables intersect in the program (Briggs et al. 1992; Smithet al. 2004; Odaira et al. 2010).

The problem of assigning frequencies to stations in cellular networks could bemodelled by means of graph colouring. Stations are modelled as graph vertices andfrequencies—as colours of these vertices. An edge is added if two stations are locatedclose to each other and their signals can interfere (Halldorsson 1997; Meirong andYuzhen 2014).

Some data clustering problems can be described via the VCP. In this case datarecords are graph vertices and clusters are colour classes. An edge between two verticesis added if the corresponding data records differ significantly and should not be in onecluster (Kochenberger et al. 2005; Wang et al. 2004).

The VCP problem is also used for computing upper bounds in branch-and-boundalgorithms for the maximum clique problem and the maximum independent set prob-lem equivalent to it (San Segundo et al. 2011; Batsyn et al. 2014). In this case the VCPproblem is solved billions of times and thus the computational time of solving oneVCP instance should be as small as possible. Of course only classical fast heuristicscan be used for this purpose.

There have been proposed a large number of exact (Malaguti et al. 2011; Méndez-Díaz and Zabala 2006; San Segundo 2012) and heuristic (Welsh and Powell 1967;Matula et al. 1972; Johnson 1974; Brelaz 1979; Radin 2000; Porumbela et al. 2010)approaches for the VCP. Among fast classical heuristics the following are widelyused: Greedy, DSATUR, greedy independent sets and others (see Kosowski andManuszewski 2004). Such heuristics represent a sequence of simple operations, con-ditional branches and loops without applying mathematical operations. An efficientalgorithm applying bitwise operations for branching and colouring is introduced bySan Segundo et al. (2011) for the maximum clique problem.

In this paper the vertex colouring algorithm based on bitwise operations over bitmatrices is presented. We introduce a special matrix of forbidden colours which allows

123

Page 3: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

us to simplify the algorithm and accelerate its implementation. .The applied bitwiseoperations process 64 graph vertices simultaneously (in case of 64-bit CPU architec-ture). Bit representation of input and output data in our approach reduces its volumein memory and thus increases the CPU cache efficiency accelerating the programimplementation.

2 Mathematical model

An undirected graph G is given by an ordered pair G = (V, E), where V is a set ofvertices, |V | = n, and E ⊂ V × V —a set of edges, |E | = m. Two vertices u, v ∈ Vare called adjacent if they are connected by an edge: {u, v} ∈ E . An edge and a vertexon this edge are called incident. The degree deg(v) of a vertex v is measured as thenumber of edges incident to the vertex v: deg(v) = ∣

∣{e ∈ E : v ∈ e}∣∣.A vertex colouring of graph G = (V, E) is a function c : V → N, which assigns a

natural number (colour) to each vertex of the graph so that any two adjacent verticesare assigned different colours, that is {u, v} ∈ E ⇒ c(u) �= c(v). The function c iscalled the colouring function. A graph G for which there exists a vertex colouringof k colours is called k-colourable, while such a colouring is called a k-colouring.The smallest number k for which there exists a k-colouring of graph G is called thechromatic number of graph G and is denoted by χ(G).

The following straight forward mathematical model for the vertex colouring prob-lem is well-known and can be found in many papers (see for example Malaguti et al.2011). In this model k is a number of colours which is enough to colour graph G. Thiscan be a simple upper bound on the number of colours: k = max

v∈Vdeg(v) + 1.

Decision variables:

xih ∈ {0, 1}, xih = 1, if vertex i is assigned a colour h

yh ∈ {0, 1}, yh = 1, if colour h is used in the solution

Objective function:k

h=1

yh → min (1)

Constraints:

k∑

h=1

xih = 1, i ∈ V (2)

xih + x jh ≤ yh, {i, j} ∈ E, h = 1, . . . , k (3)

Objective function (1) minimizes the number of colours used. Constraints (2) requirethat exactly one colour is assigned to every vertex. Finally, constraints (3) preventadjacent vertices from having the same colour.

123

Page 4: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

3 Algorithm description

The developed algorithm works on the basis of bitwise operations on the adjacencymatrix and a special matrix of forbidden colours. Adjacency matrix A is a square n ×nmatrix, in which ai j = 1 if vertices i and j are connected with an edge and ai j = 0otherwise. The matrix of forbidden colours C is also a square n × n matrix, in whichci j = 1 if colour i is forbidden for vertex j , because one of its neighbours already hasthis colour. Initially matrix C is zero.

The following operations are made with matrices A and C . We begin from the firstvertex of the graph—the first column of matrix C : j = 1. We search for the minimalcolour feasible for this vertex. So we determine the minimal value of i , for whichci j = 0 (colour i is not forbidden for vertex j) and assign this colour to vertex j .

Then it is necessary to forbid colour i for the neighbours of vertex j . Therefore, abitwise operation—“O R′′—disjunction of Boolean vectors A j and Ci is computed:Ci = Ci ∨ A j . Since ones in row A j occur on the places of vertex j neighbours thenthese ones appear in row Ci forbidding colour i for these neighbours. Then the nextvertex j = j + 1 (next column of matrix C) is considered and the same operationsare performed. We search for the minimal colour feasible for vertex j and forbid thiscolour for its neighbours.

The algorithm stops when all the vertices of the graph G are coloured. The obtainedcolouring is described by matrix C . For every vertex j its colour is determined as theminimal colour i which is not forbidden for vertex j (Ci j = 0).

Let us consider graph G shown in Fig. 1.The adjacency and forbidden colours matrices Aand C of graph G are the following:

A =

1 2 3 4 5 6 71 0 1 1 0 0 0 12 1 0 1 1 0 0 03 1 1 0 1 0 1 14 0 1 1 0 1 0 15 0 0 0 1 0 1 06 0 0 1 0 1 0 07 1 0 1 1 0 0 0

C =

1 2 3 4 5 6 71 0 0 0 0 0 0 02 0 0 0 0 0 0 03 0 0 0 0 0 0 04 0 0 0 0 0 0 05 0 0 0 0 0 0 06 0 0 0 0 0 0 07 0 0 0 0 0 0 0

Fig. 1 Graph for the algorithmdemonstration 2

1

7

35

6

4

123

Page 5: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

Manipulations with the matrix of forbidden colours C begin from the first column:j = 1. In this column we search for the minimal feasible colour, the first zero in thiscolumn (top down). The first zero is in row i = 1, and consequently, vertex 1 willbe assigned colour 1. We forbid this colour for the neighbours of vertex 1. For thispurpose we “add” row 1 of the adjacency matrix A to row 1 of the matrix of forbiddencolours C .

∨000000001100010110001

The new row i = 1 of the matrix of forbidden colours C becomes: C1 = 0110001.So colour 1 is forbidden for vertices 2, 3 and 7 (neighbours of vertex 1).

Next all the same operations are performed for all vertices j = 2, 3, 4, 5, 6, 7 ofgraph G. Vertex 2 is assigned colour 2, we forbid this colour for its neighbours, androw 2 of matrix C becomes: C2 =1011000. Vertex 3 is assigned colour 3, we forbidthis colour for its neighbours and row 3 of matrix C becomes: C3 =1101011. The forthvertex is assigned the first colour and in the first row of matrix C this colour becomesalso forbidden for the fifth vertex: C1 =0110101. Vertex 5 is coloured in colour 2and it becomes also forbidden for the sixth vertex: C2 =1011010. The sixth vertexis assigned the first colour, but “addition” of sixth row of the adjacency matrix Atothe first row of matrix C does not produce any changes as the first colour has alreadybeen forbidden for all neighbours of vertex 6: C1 =0110101. Vertex 7 is assigned thesecond colour. Since it was the last vertex there is no reason to perform the disjunctionoperation. Finally we have the following matrix C :

C =

1 2 3 4 5 6 71 0 1 1 0 1 0 12 1 0 1 1 0 1 03 1 1 0 1 0 1 14 0 0 0 0 0 0 05 0 0 0 0 0 0 06 0 0 0 0 0 0 07 0 0 0 0 0 0 0

So three colours are needed to colour graph G. The colour for every vertex j isdetermined by the first zero in column j of matrix C . Vertices 1, 2, 3, 4, 5, 6, 7 areassigned the following colours correspondingly: 1, 2, 3, 1, 2, 1, 2.

4 Pseudo-code of algorithms

For the bit representation of matrices A and C every row is divided into parts of thesize determined by the computer architecture (for example, the size of 64 bits). Thisallows us to apply bitwise operations processing several vertices at once (64 verticesfor 64-bit computer architecture). The index of a bit part in a row is determined byvariable p in the pseudo-code below. The disjunction of rows of the adjacency and

123

Page 6: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bitparts of these rows. In order to get the value of bit b from a 64-bit part a bitwiseconjunction operation “&” is used with a special mask. This mask is a number inwhich all bits are zeroes except the bit at position b which is equal to 1. Such a maskcan be obtained by the left shift operation “<<” of 1 by b bits to the left. Conjunctionwith this mask is equal to zero if bit b in the 64-bit part is equal to zero. Otherwise theresult is the mask itself, or in other words a nonzero number.

In the pseudo-code below vertices, colours and bit parts are numbered starting from0. The following variables are used in the pseudo-code:

BITS—32 or 64 depending on the computer architectureAip—BITS-bit part p of row i of the adjacency matrix ACip—BITS-bit part p of row i of the forbidden colours matrix Cparts = n/B I T S�—the number of bit parts in rows of matrices A and C

123

Page 7: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

The proposed algorithm is compared with the standard Greedy-Colour algorithmwhose pseudo-code is also given below. Vertices and colours in this pseudo-code arenumbered starting from 1. In the standard algorithm the colouring is stored in a set ofcolour classes C1, C2, . . . , Ck , where Ci contains vertices coloured in colour i .

It is easy to see that the smallest number of operations our Bit-Greedy-Colouralgorithm does is n(1 + parts) = n + n2/B I T S because the outer loop alwaysperforms n iterations, the first inner loop performs only 1 iteration in case of an emptygraph, and the second inner loop always performs parts = n/B I T S iterations. So thebest-case complexity of this algorithm is n2/B I T S. The worst case for this algorithmis a complete graph. In this case the first inner loop performs in total 1+2+· · ·+n =n(n+1)/2 iterations and so the worst-case complexity is

(

n(n + 1)/2 + n2/B I T S) ∼

(1/2 + 1/B I T S) n2. In the same way it is not difficult to see that the worst-case

123

Page 8: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

complexity of the Greedy-Colour algorithm is n(n − 1)/2 ∼ n2/2. The worst casehere is an empty graph for which all vertices are coloured in the first colour and soHas-Neighbours() function performs in total 0 + 1 + · · · + n − 1 iterations in n callsfrom the outer loop. So for B I T S = 64 the worst-case behaviour of both algorithmsis almost the same.

5 Experimental results

The experiments are carried out on Intel Xeon X5690 3.47 GHz computer with 64-bitarchitecture (BITS = 64). The algorithms are tested on random and DIMACS instances(http://dimacs.rutgers.edu/Challenges). As colouring of one graph takes only severalmilliseconds, we repeat the calculation 10000 times for random graphs and 1 milliontimes for DIMACS graphs. Note that both algorithms return the same colouring sowe test only the performance. For random graphs the results are averaged over 50instances. These results are shown in Table 1.

Table 2 shows the speedup on random graphs which our Bit-Greedy-Colour algo-rithm has in comparison with the classical Greedy-Colour algorithm. The suggestedapproach has a good speedup on all instances due to the smaller number of steps foralmost all densities except very high (0.90–0.99) and due to the lower memory con-sumption which results in better usage of CPU cache. The best speedup is obtained formedium densities from 0.3 to 0.5 and for a big number of vertices. For small densitiesthe number of colours is small, the Greedy-Colour algorithm uses a small number ofCi arrays for storing colour classes, and this provides good usage of CPU cache. Thatis why the computational time for this algorithm increases when density is increasing.For our Bit-Greedy-Colour algorithm the computational time increases in this casedue to the increasing number of steps from the best case with n2/B I T S complexityto the worst case with (1/2 + 1/B I T S) n2 complexity. For densities from 0.3 to 0.5this increase in complexity is relatively small and for the Greedy-Colour algorithmthe computational time increases faster than for the Bit-Greedy-Colour. Bit-Greedy-Colour uses much less memory due to bit representation of the data and so it providesgood usage of CPU cache for any density. The greater is the number of vertices thegreater is the difference in memory usage between the two algorithms. That is why for500 vertices the average speedup is 3.3, for 1000 vertices—3.7, for 5000 vertices—4.1.

The results for DIMACS graphs are shown in Table 3. The average speedup is 2.6for these instances. Only for two graphs our approach gives slightly worse results:johnson32-2-4 and johnson8-2-4. Though it gives smaller number of steps the com-putational time is slightly greater.

6 Concluding remarks

In this paper a fast greedy heuristic algorithm for the vertex colouring problem is sug-gested. The main idea of the algorithm is the application of efficient bitwise operationsfor bit matrices: the adjacency matrix and the forbidden colours matrix.

The main advantages of the developed algorithm are:

123

Page 9: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

Tabl

e1

Tim

ean

dst

eps

for

rand

omgr

aphs

aver

aged

over

50in

stan

ces

|V|

500

1000

5000

Den

sity

Tim

e(s

ec)

Step

sT

ime

(sec

)St

eps

Tim

e(s

ec)

Step

s

Gre

edy

Bit-

Gre

edy

Gre

edy

Bit-

Gre

edy

Gre

edy

Bit-

Gre

edy

Gre

edy

Bit-

Gre

edy

Gre

edy

Bit-

Gre

edy

Gre

edy

Bit-

Gre

edy

0.01

0.60

0.19

59,3

6951

001.

980.

5819

9,36

018

,63

338

.79

11.3

23,

414,

090

429,

783

0.10

0.72

0.24

34,9

2279

922.

510.

7512

1,28

728

,77

151

.92

13.9

82,

263,

136

622,

037

0.20

0.97

0.28

31,5

1010

,78

43.

530.

9011

0,40

838

,73

675

.01

16.7

72,

124,

349

820,

505

0.30

1.27

0.32

30,5

0613

,63

94.

741.

0510

7,82

048

,95

010

1.40

19.8

12,

102,

009

1,02

6,26

8

0.40

1.56

0.37

30,4

4616

,68

85.

941.

2110

7,89

159

,76

612

7.09

23.2

52,

139,

912

1,25

1,71

2

0.50

1.75

0.41

31,0

3620

,01

86.

771.

3811

1,02

672

,17

714

6.00

28.2

42,

220,

025

1,50

5,66

2

0.60

1.80

0.47

32,2

8223

,86

17.

191.

6011

6,53

786

,57

616

0.25

35.7

52,

346,

156

1,80

3,30

9

0.70

1.75

0.53

34,3

0028

,48

37.

171.

8312

4,49

710

3,77

617

5.77

46.0

42,

529,

999

2,16

6,43

8

0.80

1.70

0.63

37,8

8734

,80

47.

052.

1613

7,66

912

6,75

019

7.98

58.5

12,

829,

549

2,65

9,33

0

0.90

1.68

0.77

44,7

4644

,78

37.

232.

8616

3,52

716

3,80

623

2.61

77.4

53,

384,

183

3,44

1,39

8

0.99

1.98

1.11

64,9

5668

,80

19.

505.

0924

7,54

126

1,68

840

0.38

138.

585,

565,

384

5,90

5,28

4

123

Page 10: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

Table 2 The speedup forrandom graphs averaged over 50instances

|V| 500 1000 5000

Density Speedup

0.01 3.2 3.4 3.4

0.10 3.0 3.3 3.7

0.20 3.5 3.9 4.5

0.30 4.0 4.5 5.1

0.40 4.2 4.9 5.5

0.50 4.3 4.9 5.2

0.60 3.8 4.5 4.5

0.70 3.3 3.9 3.8

0.80 2.7 3.3 3.4

0.90 2.2 2.5 3.0

0.99 1.8 1.9 2.9

Table 3 Time, steps and speedup for DIMACS graphs

G (V,E) |V| |E| Time (sec) Steps Speedup

Greedy Bit-Greedy

Greedy Bit-Greedy

brock200_1 200 14,834 34 12 6903 6168 2.8

brock200_2 200 9876 32 10 5865 3921 3.2

brock200_3 200 12,048 42 8 6192 4746 5.3

brock200_4 200 13,089 32 12 6301 5200 2.7

brock400_1 400 59,723 124 42 24,158 21,275 3.0

brock400_2 400 59,786 108 38 23,975 21,119 2.8

brock400_3 400 59,681 118 40 23,654 20,905 3.0

brock400_4 400 59,765 102 38 23,309 20,609 2.7

brock800_1 800 207,505 434 110 79,000 62,405 3.9

brock800_2 800 208,166 438 110 79,262 62,663 4.0

brock800_3 800 207,333 420 112 78,462 62,034 3.8

brock800_4 800 207,643 496 112 80,340 63,306 4.4

c-fat200-1 200 1534 16 10 10,260 2020 1.6

c-fat200-2 200 3235 16 6 10,264 3124 2.7

c-fat200-5 200 8473 24 12 12,346 7568 2.0

c-fat500-1 500 4459 68 16 63,487 7390 4.3

c-fat500-10 500 46627 124 66 66,159 35,502 1.9

c-fat500-2 500 9139 78 26 62,461 10,510 3.0

c-fat500-5 500 23191 106 46 63,431 19,878 2.3

C1000.9 1000 450,079 710 268 162,446 163,314 2.6

C125.9 125 6963 12 8 3411 3457 1.5

C250.9 250 27,984 40 20 12011 12,016 2.0

123

Page 11: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

Table 3 continued

G(V,E) |V| |E| Time, sec Steps Speedup

Greedy Bit-Greedy

Greedy Bit-Greedy

C500.9 500 112,332 174 78 45,324 45,366 2.2

dsjc1000.1.col.txt 1000 49,629 240 72 120,229 28,892 3.3

dsjc1000.5.col.txt 1000 249,826 790 140 112,208 73,246 5.6

dsjc500.1.col.txt 500 12,458 70 24 35,851 8110 2.9

dsjc500.5.col.txt 500 62,624 204 46 30,405 19,878 4.4

frb30-15-1 450 83,198 44 22 11,224 10,575 2.0

frb30-15-2 450 83,151 56 26 11,278 10,575 2.2

frb30-15-3 450 83,216 42 22 11,166 10,575 1.9

frb30-15-4 450 83,194 46 22 11,286 10,575 2.1

frb30-15-5 450 83,231 45 22 11,190 10,575 2.1

gen200_p0.9_44 200 17,910 32 12 7402 7608 2.7

gen200_p0.9_55 200 17,910 28 12 7734 7951 2.3

gen400_p0.9_55 400 71,820 100 52 24,878 25,497 1.9

gen400_p0.9_65 400 71,820 88 48 26,861 27,294 1.8

gen400_p0.9_75 400 71,820 108 60 28,265 28,710 1.8

hamming6-2 64 1824 4,8 2,7 1104 1120 1.8

hamming6-4 64 704 2,8 1,2 872 352 2.3

hamming8-2 256 31,616 44 28 16,832 17,536 1.6

hamming8-4 256 20,864 34 12 8384 5248 2.8

johnson16-2-4 120 5460 4,3 3,4 1316 997 1.3

johnson32-2-4 496 107,880 25 27 10,820 9829 0.9

johnson8-2-4 28 210 0,4 0,5 148 121 0.8

johnson8-4-4 70 1855 3,6 2,5 856 824 1.4

keller4 171 9435 19 8 3708 2948 2.5

keller5 776 225,990 224 108 60,898 57,023 2.1

MANN_a27 378 70,551 68 50 27,459 29,430 1.4

MANN_a9 45 918 1,8 1,6 486 513 1.2

p_hat1000-1 1000 122,253 358 86 86,134 41,400 4.2

p_hat1000-2 1000 244,799 514 146 80,809 66,477 3.5

p_hat1000-3 1000 371,746 606 188 121,348 112,955 3.2

p_hat300-1 300 10,933 48 14 10,680 4543 3.4

p_hat300-2 300 21,928 48 14 9612 7318 3.4

p_hat300-3 300 33,390 60 26 13,752 12,335 2.3

p_hat500-1 500 31,569 100 26 25,657 11,741 3.8

p_hat500-2 500 62,946 132 40 23,379 18,823 3.3

p_hat500-3 500 93,800 146 56 33,506 31,081 2.6

p_hat700-1 700 60,999 218 56 45,988 21,278 3.9

p_hat700-2 700 121,728 192 66 40,906 34,226 2.9

123

Page 12: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

Table 3 continued

G(V,E) |V| |E| Time (sec) Steps Speedup

Greedy Bit-Greedy Greedy Bit-Greedy

p_hat700-3 700 183,010 320 112 62,644 58,212 2.9

san1000 1000 250,500 168 76 46,408 30,652 2.2

san200_0.7_1 200 13,930 28 12 5794 5098 2.3

san200_0.7_2 200 13,930 18 10 4110 3649 1.8

san200_0.9_1 200 17,910 30 16 9058 9310 1.9

san200_0.9_2 200 17,910 30 16 8767 8902 1.9

san200_0.9_3 200 17,910 26 20 7398 7585 1.3

san400_0.5_1 400 39,900 44 22 11,253 7098 2.0

san400_0.7_1 400 55,860 96 34 18,125 16,064 2.8

san400_0.7_2 400 55,860 74 28 15,759 13,930 2.6

san400_0.7_3 400 55,860 62 26 13,212 12,027 2.4

san400_0.9_1 400 71,820 110 54 33,544 33,538 2.0

sanr200_0.7 200 13,868 38 10 6407 5463 3.8

sanr200_0.9 200 17,863 24 16 7962 8139 1.5

sanr400_0.5 400 39,984 126 28 20,820 13,641 4.5

sanr400_0.7 400 55,869 112 36 22,965 19,185 3.1

1. Bit representation of the adjacency and forbidden colours matrices which signifi-cantly reduces the required memory space.

2. Bitwise disjunction operation on the rows of the adjacency and forbidden coloursmatrices, which significantly reduces the computational time.

The computational time comparison of the developed algorithm with the standardGreedy-Colour algorithm shows that our approach is 2.6 times faster in average onDIMACS graphs. The suggested algorithm can be applied to various discrete opti-mization problems arising in timetabling, data clustering, processor register allocationduring compilation, traffic light phasing, frequency assignment and other problems.The vertex colouring problem is also used for computing upper bounds in exact algo-rithms for the maximum clique problem and its analogues: maximum independentset and minimum vertex cover problems. In this case, colouring of various subgraphsof the initial graph should be calculated many times as the search tree contains anexponential number of nodes.

Acknowledgments The work is conducted at National Research University Higher School of Economicsand supported by RSF Grant 14-41-00039.

References

Batsyn M, Goldengorin B, Maslov E, Pardalos PM (2014) Improvements to MCS algorithm for the maximumclique problem. J Comb Optim 27:397–416

Brelaz D (1979) New methods to color the vertices of a graph. Commun ACM 22:251–256

123

Page 13: A fast greedy sequential heuristic for the vertex colouring … · 2015. 7. 13. · forbidden colours matrices is computed by means of a bitwise operation “|” on 64-bit parts

J Comb Optim

Briggs P, Cooper K, Torczon L (1992) Coloring register pairs. ACM Lett Program Lang Syst 1(1):3–13Erciyes K (2013) Vertex coloring. In: distributed graph algorithms for computer networks, pp 107–134Halldorsson MM (1997) Parallel and on-line graph coloring. J Algorithms 23:265–280Johnson DS (1974) Worst case behavior of graph coloring algorithms. In: Proceedings of the Fifth Southeast-

ern Conference on Combinatorics, Graph Theory and Computing. Utilitas Mathematica Publishing,pp 513–528

Karp Richard M (1972) Reducibility among combinatorial problems. In: Miller RE, Thatcher JW (eds)Complexity of computer computations. Plenum, New York, pp 85–103

Kochenberger G, Glover F, Alidaee B, Wang H (2005) Clustering of microarray data via clique partitioning.J Comb Optim 10(1):77–92

Kosowski A, Manuszewski K (2004) Classical coloring of graphs. In: Kubale M (ed) Graph colorings. AMSContemporary Mathematics, pp 1–20

Malaguti E, Monaci M, Toth P (2011) An exact approach for the vertex coloring problem. Discret Optim8(2):174–190

Matula DM, Marble BG, Isaacson JD (1972) Graph coloring algorithms. In: Graph theory and computing.Academic Press, New York, pp 109–122

Meirong X, Yuzhen W (2014) T-coloring of graphs with application to frequency assignment in cellularmobile networks. In: Proceedings of the 33rd Chinese Control Conference (CCC), 2014

Méndez-Díaz I, Zabala P (2006) A Branch-and-cut algorithm for graph coloring. Discret Appl Math154(5):826–847

MirHassani SA, Habibi F (2013) Solution approaches to the course timetabling problem. Artif Intell Rev39:133–149

Odaira R, Nakaike T, Inagaki T, Komatsu H, Nakatani T (2010) Coloring-based coalescing for graph coloringregister allocation. In: CGO ’10: Proceedings of the 8th annual IEEE/ACM international symposiumon Code generation and optimization

Pardalos PM, Mavridou T, Xue J (1999) The graph coloring problem: a bibliographic survey. In: Du DZ,Pardalos PM (ed) Handbook of combinatorial optimization, pp 1077–1141

Porumbela DC, Hao JK, Kuntz P (2010) A search space “cartography” for guiding graph coloring heuristics.Comput Oper Res 37:769–778

Radin A (2000) Graph coloring heuristics from investigation of smallest hard to color graphs. MS Thesis,Rochester Institute of Technology

San Segundo P (2012) A new DSATUR-based algorithm for exact vertex coloring. Comput Oper Res039(7):1724–1733

San Segundo P, Rodriguez-Losada D, Jimenez A (2011) An exact bit-parallel algorithm for the maximumclique problem. Comput Oper Res 038(2):571–581

Smith MD, Ramsey N, Holloway G (2004) A generalized algorithm for graph-coloring register allocation.In: PLDI ’04: Proceedings of the ACM SIGPLAN 2004 Conference on Programming language designand implementation

Wang H, Alidaee B, Kochenberger GA (2004) Evaluating a clique partitioning problem model for clusteringhigh-dimensional data mining. In: Proceedings of the 10th Americas Conference on InformationSystems (AMCIS 2004), New York, NY, 6–8 August 2004

Welsh DJA, Powell MB (1967) An upper bound for the chromatic number of a graph and its application totimetabling problems. Comput J 10(1):85–86

123