- Type Parameters:
V- the graph vertex type.E- the graph edge type.
MaximumCardinalityIterator or LexBreadthFirstIterator to compute a perfect
elimination order. The desired method is specified during construction time.
Chordal graphs are a subset of the perfect graphs. They may be recognized in polynomial time, and several problems that are hard on other classes of graphs such as minimum vertex coloring or determining maximum cardinality cliques and independent set can be performed in polynomial time when the input is chordal.
All methods in this class run in $\mathcal{O}(|V| + |E|)$ time. Determining whether a graph is
chordal, as well as computing a perfect elimination order takes $\mathcal{O}(|V| + |E|)$ time,
independent of the algorithm (MaximumCardinalityIterator or
LexBreadthFirstIterator) used to compute the perfect elimination order.
All the methods in this class are invoked in a lazy fashion, meaning that computations are only started once the method gets invoked.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies internal iterator type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanContains true if the graph is chordal, otherwise false.The inspected graph.A hole contained in the inspectedgraph.private final ChordalityInspector.IterationOrderStores the type of iterator used by thisChordalityInspector.Order produced byorderIterator.private final GraphIterator<V, E> Iterator used for producing perfect elimination order. -
Constructor Summary
ConstructorsConstructorDescriptionChordalityInspector(Graph<V, E> graph) Creates a chordality inspector forgraph, which usesMaximumCardinalityIteratoras a default iterator.ChordalityInspector(Graph<V, E> graph, ChordalityInspector.IterationOrder iterationOrder) Creates a chordality inspector forgraph, which uses an iterator defined by the second parameter as an internal iterator. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidComputes some cycle in the graph on the vertices from the domain of the mapvisited.private voidComputes a hole from the vertices ofsubgraphof the inspectedgraphwith verticesa,bandcon this cycle (there must be no edge betweenaandc.getHole()A graph which is not chordal, must contain a hole (chordless cycle on 4 or more vertices).Returns the type of iterator used in thisChordalityInspectorReturns a perfect elimination order if one exists.getPredecessors(Map<V, Integer> vertexInOrder, V vertex) Returns the predecessors ofvertexin the order defined bymap.getVertexInOrder(List<V> vertexOrder) Returns a map containing vertices from thevertexOrdermapped to their indices invertexOrder.booleanChecks whether the inspected graph is chordal.booleanisPerfectEliminationOrder(List<V> vertexOrder) Checks whether the vertices in thevertexOrderform a perfect elimination order with respect to the inspected graph.private booleanisPerfectEliminationOrder(List<V> vertexOrder, boolean computeHole) Checks whether the vertices in thevertexOrderform a perfect elimination order with respect to the inspected graph.Computes vertex order viaorderIterator.minimizeCycle(List<V> cycle) Minimizes the cycle represented by the listcycle.
-
Field Details
-
iterationOrder
Stores the type of iterator used by thisChordalityInspector. -
orderIterator
Iterator used for producing perfect elimination order. -
graph
The inspected graph. -
chordal
private boolean chordalContains true if the graph is chordal, otherwise false. -
order
Order produced byorderIterator. -
hole
A hole contained in the inspectedgraph.
-
-
Constructor Details
-
ChordalityInspector
Creates a chordality inspector forgraph, which usesMaximumCardinalityIteratoras a default iterator.- Parameters:
graph- the graph for which a chordality inspector to be created.
-
ChordalityInspector
Creates a chordality inspector forgraph, which uses an iterator defined by the second parameter as an internal iterator.- Parameters:
graph- the graph for which a chordality inspector is to be created.iterationOrder- the constant, which defines iterator to be used by thisChordalityInspector.
-
-
Method Details
-
isChordal
public boolean isChordal()Checks whether the inspected graph is chordal.- Returns:
- true if this graph is chordal, otherwise false.
-
getPerfectEliminationOrder
Returns a perfect elimination order if one exists. The existence of a perfect elimination order certifies that the graph is chordal. This method returns null if the graph is not chordal.- Returns:
- a perfect elimination order of a graph or null if graph is not chordal.
-
getHole
A graph which is not chordal, must contain a hole (chordless cycle on 4 or more vertices). The existence of a hole certifies that the graph is not chordal. This method returns a chordless cycle if the graph is not chordal, or null if the graph is chordal.- Returns:
- a hole if the
graphis not chordal, or null if the graph is chordal.
-
isPerfectEliminationOrder
Checks whether the vertices in thevertexOrderform a perfect elimination order with respect to the inspected graph. Returns false otherwise.- Parameters:
vertexOrder- the sequence of vertices of thegraph.- Returns:
- true if the
graphis chordal and the vertices invertexOrderare in perfect elimination order, otherwise false.
-
lazyComputeOrder
Computes vertex order viaorderIterator.- Returns:
- computed order.
-
isPerfectEliminationOrder
Checks whether the vertices in thevertexOrderform a perfect elimination order with respect to the inspected graph. Returns false otherwise. Computes a hole if thecomputeHoleis true.- Parameters:
vertexOrder- the sequence of vertices ofgraph.computeHole- tells whether to compute the hole if the graph isn't chordal.- Returns:
- true if the
graphis chordal and the vertices invertexOrderare in perfect elimination order.
-
getVertexInOrder
Returns a map containing vertices from thevertexOrdermapped to their indices invertexOrder.- Parameters:
vertexOrder- a list with vertices.- Returns:
- a mapping of vertices from
vertexOrderto their indices invertexOrder.
-
findHole
Computes a hole from the vertices ofsubgraphof the inspectedgraphwith verticesa,bandcon this cycle (there must be no edge betweenaandc.- Parameters:
a- vertex that belongs to the cycleb- vertex that belongs to the cyclec- vertex that belongs to the cycle
-
dfsVisit
Computes some cycle in the graph on the vertices from the domain of the mapvisited. More precisely, finds some path frommiddletofinish. The vertexmiddleisn't the endpoint of any chord in this cycle.- Parameters:
cycle- already computed part of the cyclevisited- the map that defines which vertex has been visited by this methodfinish- the last vertex in the cycle.middle- the vertex, which must be adjacent onlcurrent- currently examined vertex.
-
minimizeCycle
Minimizes the cycle represented by the listcycle. More precisely it retains first 2 vertices and finds a chordless cycle starting from the third vertex.- Parameters:
cycle- vertices of the graph that represent the cycle.- Returns:
- a chordless cycle
-
getPredecessors
Returns the predecessors ofvertexin the order defined bymap. More precisely, returns those ofvertex, whose mapped index inmapis less then the index ofvertex.- Parameters:
vertexInOrder- defines the mapping of vertices ingraphto their indices in order.vertex- the vertex whose predecessors in order are to be returned.- Returns:
- the predecessors of
vertexin order defines bymap.
-
getIterationOrder
Returns the type of iterator used in thisChordalityInspector- Returns:
- the type of iterator used in this
ChordalityInspector
-