Package org.graph4j.coloring
Class ExactColoringBase
java.lang.Object
org.graph4j.SimpleGraphAlgorithm
org.graph4j.coloring.ExactColoringBase
- All Implemented Interfaces:
ColoringAlgorithm
- Direct Known Subclasses:
BacktrackColoringBase
Base class for exact vertex coloring algorithms.
- Author:
- Cristian Frăsinaru
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Coloringprotected booleanprotected intprotected longprotected booleanprotected longFields inherited from class org.graph4j.SimpleGraphAlgorithm
graph -
Constructor Summary
ConstructorsConstructorDescriptionExactColoringBase(Graph graph) ExactColoringBase(Graph graph, long timeLimit) ExactColoringBase(Graph graph, Coloring initialColoring) ExactColoringBase(Graph graph, Coloring coloring, long timeLimit) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanfindAllColorings(int numColors, int solutionsLimit) Finding all colorings is suitable for small graphs only.In 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 ColoringAlgorithmgetInstance(Graph graph, long timeLimit) intbooleanbooleanvoidsetOutputEnabled(boolean outputEnabled) protected abstract voidsolve(int numColors) protected voidsolveDisconnected(int numColors) 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, isOptimalityEnsured, isSolvingComponents, isStoppingOnFailure, isValid
-
Field Details
-
timeLimit
protected long timeLimit -
startTime
protected long startTime -
timeExpired
protected boolean timeExpired -
initialColoring
-
components
-
solutions
-
solutionsLimit
protected int solutionsLimit -
outputEnabled
protected boolean outputEnabled
-
-
Constructor Details
-
ExactColoringBase
-
ExactColoringBase
- Parameters:
graph- the input graph.initialColoring- an initial coloring of the vertices.
-
ExactColoringBase
- Parameters:
graph- the input graph.timeLimit- in milliseconds.
-
ExactColoringBase
- Parameters:
graph- the input graph.coloring- an initial coloring of the vertices.timeLimit- in milliseconds.
-
-
Method Details
-
getInstance
-
getMaximalClique
- Specified by:
getMaximalCliquein interfaceColoringAlgorithm- Returns:
- a maximal clique of the graph to be colored.
-
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.
-
findAllColorings
Finding all colorings is suitable for small graphs only.- Parameters:
numColors- the maximum number of colors to be used.solutionsLimit- a limit on the number of colorings to be found (use 0 in order to find all the colorings).- Returns:
- all the vertex colorings 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.
-
solveDisconnected
protected void solveDisconnected(int numColors) -
solve
protected abstract void solve(int numColors) -
isTimeExpired
public boolean isTimeExpired()- Returns:
trueif time expired before determining the optimum.
-
checkTime
protected boolean checkTime() -
getSolutionsLimit
public int getSolutionsLimit()- Returns:
- the solutions limit.
-
isOutputEnabled
public boolean isOutputEnabled()- Returns:
trueif the output of the algorithm is enabled.
-
setOutputEnabled
public void setOutputEnabled(boolean outputEnabled) - Parameters:
outputEnabled- iftrue, the output is enabled.
-