Autonomous University of Nuevo Leon Faculty of Mechanical and Electrical Engineering
Autonomous University of Nuevo Leon Faculty of Mechanical and Electrical Engineering
Name ID Carrer
The problem is, given m colors, find a way of coloring the vertices of a graph.
The constraints in a graph, no two adjacent vertices, adjacent edges, or adjacent regions are
colored with the same colors.
The objective is to minimize the number of colors while coloring a graph. The smallest
number of colors required to color a graph G is called its chromatic number of that graph.
Graph coloring problem is a NP Complete problem.
Chromatic Number: The smallest number of colors needed to color a graph G is called its
chromatic number. For example, the following can be colored minimum 2 colors.
The vertices are ordered according to their degrees, the resulting greedy coloring uses at
most One more than the graph’s maximum degree.
In this particular algorithm the evaluation function is primarily based on the level and
order of the vertices of the graph.
For the list of candidates, 3 vertices are chosen at random in the form of a row on the
adjacency matrix, and then they are randomly rearranged.
In this way, different results can be obtained since a different pattern is followed from
that of the original adjacency matrix.
This of course can lead to better or worse results. Resulting in a disadvantage for the
algorithm, but by iterating the program again feasible solutions can be reached.
Steps
Input G= (V, E) number of vertex and adjacency matrix [i][j] of the graph
Begin
Main
LOCAL SEARCH
Before assigning a color, check for safety by considering alreadyassigned colors to the
adjacent vertices i.e check if the adjacent vertices have the same color or not.
If there is any color assignment that does not violate the conditions, mark the color
assignment as part of the solution. Ifno assignment of color is possible then backtrack and
return false.
This algorithm seeks to improve the solution obtained by the main heuristic.
Within this process, "m" number of colors is taken into account to color a graph.
This number "m" is our previous solution given by the heuristic.
One color is removed from this k-1 color solution.
Next, the backtracking algorithm tries to find a solution which will be the best solution unless in other
iteration, another one with a higher level of optimization is found.
In case the number of colors of "m" is very low(Example k =1), the algorithm will not be executed.
Therefore, the best solution for the instance to be treated will be the one given by the main heuristic
Pseudo code
Input G= (V, E) number of vertex of the graph (n) and the Adjacency
matrix[i][j]
Output: A path for the graph using the available colors (m)
n=number of vertex
m=colors {0, 1, 2, 3….} //how many colors can we use for coloring the graph
Steps:
1. The program ask for the chromatic number solution given for the previous algorithm
2. one color is removed in order to perform the local search(K-1)
3. we continue with the backtracking algorithm
4. Assign a color to a vertex (1 to m).
5. For every assigned color, check if the configuration is safe, (by
checkingwhether any of its adjacent vertices are colored with the same
color).
6. Confirm whether it is valid to color the current vertex with the
currentcolor.
7. If yes then color it and otherwise try a different color.
8. Check if all vertices are colored or not.
9. If not then move to the next adjacent uncolored vertex.
10. If no other color is available or color assignment is not possible then
backtrack (i.e. un-color last colored vertex). and return false
Begin
Main
Begin
for all vertices v of the graph, do
if there is an edge between v and i, and col = colorList[i],
then
return false
done
return true
End Function
Begin
if all vertices are checked, then
return true
for all colors col from available colors, do
if isValid(vertex, color, col), then
add col to the colorList for vertex
if graphColoring(colors, colorList, vertex+1) = true, then
return true
remove color for vertex
done
return false
End Function
Print solution( color[]) //Here print the path with the assigned
colors to the graph if exists a possible solution
End
3. Experimental results
Instances
Description
The instances used in this problem are a combination of data obtained by the web and
random graphs generated for programs, webpages and for the team during the last
presentations of the heuristic.
Some graph where take by examples of videos in the web where it explain the
heuristic and the problems itself of graph coloring.
A webpage was used for creating multiple graphs in order to test the heuristics
proposed in this activity.
https://graphonline.ru/es/
https://www.youtube.com/watch?v=-icmP32FphE&t=823s
https://www.gatevidyalay.com/graph-coloring-chromatic-number/
Instance 1
Randomized constructive solution
Chromatic number =4 //Feasible solution =YES
Local search solution
Chromatic number =3//Feasible solution =YES / Best solution
Instance 2
Randomized constructive solution
Chromatic number =4 //Feasible solution =YES
Local search solution
Chromatic number =3//Feasible solution =YES / Best solution
Instance 3
Randomized constructive solution
Chromatic number =4 //Feasible solution =YES
Local search solution
Chromatic number =3//Feasible solution =YES / Best solution
Instance 4
Instance 10
Randomized
constructive
solution
Chromatic
number =infeasible
Local search solution
Chromatic number =infeasible
Instance11
Randomized constructive solution
Chromatic number =4 // feasible
Local search solution
Chromatic number =3 Feasible solution =YES / Best solution
Instance 12
Instance 14
Randomized constructive solution
Chromatic number =3 // feasible solution =YES
Local search solution
Chromatic number =unfeasible
Discussion
After obtaining results with different instances, the algorithm was able to find a feasible solution in
12 of the 15 proposed situations.
The random algorithm, having the property of changing the path previously proposed by the
adjacency matrix, was able to obtain chromatic numbers with +1,+2 colors in most instances.
In others he was able to obtain the best solution directly.
For the local search part, in all cases the algorithm was only able to reduce the objective function to a
single color, mostly due to the size of the instances addressed.
Conclusion
Once all the instances have been treated, I can conclude that the size of these plays a very important
role during the execution and obtaining of results.
In the first algorithm, having a very small number of vertices and changing the direction in which the
graph was colored, several times bad results were obtained.
However, when testing with moderately large instances, the change of direction in the coloration of
the graph was sometimes favorable for the final result and, combined with the local search, the most
feasible solution could be found.
A weak point of my program was not being able to iterate the local search several times more than
once, because it found the best value in the first one.
In conclusion, I can say that my heuristic works better with medium-sized graphs, since in these the
change of path can find more favorable solutions than the one obtained in the original.
And for the local search part, it was the lack of situations to be able to perform better