Package org.graph4j.coloring
Class GreedyColoringBase
java.lang.Object
org.graph4j.SimpleGraphAlgorithm
org.graph4j.coloring.GreedyColoringBase
- All Implemented Interfaces:
ColoringAlgorithm
- Direct Known Subclasses:
DSaturGreedyColoring,GreedyColoring
Greedy coloring is a simple heuristic algorithm that assigns colors to the
vertices of a graph in a greedy manner, that is, by selecting the smallest
possible color that has not yet been used by any of the neighboring vertices.
The greedy algorithm does not necessarily produce the optimal vertex
coloring, but it can be a useful heuristic in certain cases.
- Author:
- Cristian Frăsinaru
-
Field Summary
FieldsFields inherited from class org.graph4j.SimpleGraphAlgorithm
graph -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionIn case of exact algorithms, this method should return the optimum coloring, if one can be computed within the alloted time.findColoring(int numColors) protected abstract booleanprotected voidinit()protected voidmarkUsedColor(int u, double weight) protected abstract intprotected voidupdate(int v) Methods inherited from class org.graph4j.SimpleGraphAlgorithm
getGraphMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graph4j.coloring.ColoringAlgorithm
getGraph, getHeuristicColoring, getLowerBound, getMaximalClique, isOptimalityEnsured, isSolvingComponents, isStoppingOnFailure, isValid
-
Field Details
-
colors
protected int[] colors -
used
-
numColors
protected int numColors
-
-
Constructor Details
-
GreedyColoringBase
- Parameters:
graph- the input graph.
-
-
Method Details
-
findColoring
Description copied from interface:ColoringAlgorithmIn case of exact algorithms, this method should return the optimum coloring, if one can be computed within the alloted time. Otherwise, in case of heuristics or if the time limit is exceeded, it should return the best valid coloring that could be computed.- Specified by:
findColoringin interfaceColoringAlgorithm- Returns:
- a valid coloring of the graph.
-
findColoring
- Specified by:
findColoringin interfaceColoringAlgorithm- Parameters:
numColors- maximum number of colors to be used.- Returns:
- a coloring of the graph with the specified number of colors, or
nullif no coloring can be found by this algorithm.
-
markUsedColor
protected void markUsedColor(int u, double weight) -
init
protected void init() -
update
protected void update(int v) -
hasUncoloredVertices
protected abstract boolean hasUncoloredVertices() -
nextUncoloredVertex
protected abstract int nextUncoloredVertex()
-