Package org.graph4j.coloring
Class Coloring
java.lang.Object
org.graph4j.coloring.Coloring
A coloring of the vertices of a graph. Coloring algorithms will usually
produce as solution an object of this type.
- Author:
- Cristian Frăsinaru
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty coloring - no vertex has a color assigned to it.Creates a vertex coloring using the colors in the given array: the color of the vertex with indexiin the graph iscolors[i].Creates a vertex coloring using the specified color classes: all the vertices in the i-th set of thecolorClasseslist are assigned colori. -
Method Summary
Modifier and TypeMethodDescriptionvoidIf the coloring is not equitable, it throws an exception.voidIf the coloring is not proper, it throws an exception.booleanintgetColor(int v) Returns the color assigned to a vertex v, or-1if no color has been set.Creates and returns the color classes.int[]Returns an array containing the colors of the vertices.getColorsUsedBy(int[] vertices) getColorsUsedBy(VertexSet vertexSet) getGraph()inthashCode()booleanisColorSet(int v) Returnstrueif a color has been set for a vertex v.booleanisColorUsed(int color) Returnstrueif the given color has been used for some vertex.booleanReturnstrueif all the vertices have been colored.booleanisEmpty()Returnstrueif no vertex has been colored.booleanbooleanisProper()A proper coloring is an assignment of colors to the vertices of a graph so that no two adjacent vertices have the same color.intintReturns the number of vertices which have been assigned a color.intnumColoredVertices(int color) intReturn the number of used colors.final voidsetColor(int v, int color) Assigns a color to the specified vertex.toString()
-
Field Details
-
graph
-
vertexColor
protected final int[] vertexColor -
numColoredVertices
protected int numColoredVertices -
usedColors
-
colorMap
-
-
Constructor Details
-
Coloring
Creates an empty coloring - no vertex has a color assigned to it.- Parameters:
graph- the input graph.
-
Coloring
- Parameters:
graph- the input graph.other- a vertex coloring.
-
Coloring
Creates a vertex coloring using the colors in the given array: the color of the vertex with indexiin the graph iscolors[i].- Parameters:
graph- the input graph.colors- an array of color numbers.
-
Coloring
Creates a vertex coloring using the specified color classes: all the vertices in the i-th set of thecolorClasseslist are assigned colori.- Parameters:
graph- the input graph.colorClasses- the already computed color classes.
-
-
Method Details
-
getGraph
- Returns:
- the graph on which this coloring is defined.
-
isColorSet
public boolean isColorSet(int v) Returnstrueif a color has been set for a vertex v.- Parameters:
v- a vertex number.- Returns:
trueif a color has been set for the vertex v.
-
isColorUsed
public boolean isColorUsed(int color) Returnstrueif the given color has been used for some vertex.- Parameters:
color- a color number.- Returns:
trueif the color has been used for some vertex.
-
setColor
public final void setColor(int v, int color) Assigns a color to the specified vertex.- Parameters:
v- a vertex number.color- the color to be set, or-1to uncolor the specified vertex.
-
getColors
public int[] getColors()Returns an array containing the colors of the vertices.- Returns:
- an array containing the colors of the vertices.
-
getColor
public int getColor(int v) Returns the color assigned to a vertex v, or-1if no color has been set.- Parameters:
v- a vertex number;- Returns:
- the color assigned to v, or
-1if no color has been set.
-
getColorClasses
Creates and returns the color classes. It is executed in a lazy fashion: if the color classes are already created, it only returns them. If the coloring changes, the color classes are computed again.- Returns:
- the color classes.
-
numUsedColors
public int numUsedColors()Return the number of used colors.- Returns:
- the number of used colors.
-
numColoredVertices
public int numColoredVertices()Returns the number of vertices which have been assigned a color.- Returns:
- the number of colored vertices.
-
numColoredVertices
public int numColoredVertices(int color) - Parameters:
color- a color.- Returns:
- the number of vertices colored with color.
-
isEmpty
public boolean isEmpty()Returnstrueif no vertex has been colored.- Returns:
trueif no vertex has been colored.
-
isComplete
public boolean isComplete()Returnstrueif all the vertices have been colored.- Returns:
trueif all the vertices have been colored.
-
isProper
public boolean isProper()A proper coloring is an assignment of colors to the vertices of a graph so that no two adjacent vertices have the same color.- Returns:
trueif the coloring is proper.
-
isEquitable
public boolean isEquitable()- Returns:
trueif the coloring is equitable.
-
checkProper
public void checkProper()If the coloring is not proper, it throws an exception. -
checkEquitable
public void checkEquitable()If the coloring is not equitable, it throws an exception. -
getColoredVertices
- Returns:
- the set of the colored vertices.
-
getUncoloredVertices
- Returns:
- the set of the vertices that do not have a color.
-
getColorsUsedBy
- Parameters:
vertexSet- a set of vertices.- Returns:
- the distinct colors used by the given vertices.
-
getColorsUsedBy
- Parameters:
vertices- an array of vertices.- Returns:
- the distinct colors used by the given vertices.
-
maxColorNumber
public int maxColorNumber()- Returns:
- the maximum color number that was used.
-
toString
-
hashCode
public int hashCode() -
equals
-