Interface Graph<V,E>
- Type Parameters:
V- the vertex typeE- the edge type
- All Superinterfaces:
Explorable<V,E>
- All Known Implementing Classes:
HashGraph
A mathematical graph. Graph extends Explorable with more capabilities.
- Author:
- Lee A. Christie
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordGraph.Edge<V,E> Record type representing an edge with its end points. -
Method Summary
Modifier and TypeMethodDescriptionapplyToEdges(Function<Graph.Edge<V, E>, E> edgeMap) Returns a graph which is equal to this graph but with the specified transformation applied to all edges.Returns a graph which is equal to this graph but symmetric by removing one-way edges.booleancontainsEdge(V from, V to) Checks whether the graph contains an edge from one specified source to another.booleancontainsVertex(V vertex) Checks whether the graph contains the specified vertex.deleteEdges(Predicate<Graph.Edge<V, E>> delete) Returns a graph which is equal to this graph but without the edges matching the specified predicate.deleteVertices(Predicate<V> delete) Returns a graph which is equal to this graph but without the vertices matching the specified predicate.default voidforEachEdge(Consumer<Graph.Edge<V, E>> consumer) Iterates over edges, calling the given callback function for each edge in the graph.default booleanReturns true if the graph is symmetric in structure.Returns a graph which is equal to this graph but symmetric by turning one-way edges into two-way edges of equal value.preserveEdges(Predicate<Graph.Edge<V, E>> preserve) Returns a graph which is equal to this graph but with only the edges matching the specified predicate.preserveVertices(Predicate<V> preserve) Returns a graph which is equal to this graph but with only the vertices matching the specified predicate.reverse()Returns a view of the graph with all edges reversed.default List<Graph.Edge<V, E>> Returns a list of edges which do no make corresponding reverse edges.Finds the connected components of the graph, assuming that the graph is symmetric in structure.toSymmetricStructure(Function<Graph.Edge<V, E>, E> edgeMap) Returns a graph which is equal to this graph but symmetric.vertices()The set of vertices in the graph.Methods inherited from interface Explorable
edge, neighbours
-
Method Details
-
vertices
The set of vertices in the graph.- Returns:
- the set of vertices
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
containsVertex
Checks whether the graph contains the specified vertex.- Parameters:
vertex- the vertex, not null- Returns:
- true if contained, false otherwise
-
containsEdge
-
reverse
Returns a view of the graph with all edges reversed.- Returns:
- a view of the graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
symmetricConnectedComponents
Finds the connected components of the graph, assuming that the graph is symmetric in structure. This requires that at least that for every edge (A, B) there exists an edge (B, A), even if the value of the edge is different.- Returns:
- a list of fully-connected sub graphs ordered from largest to smallest
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
breakToSymmetricStructure
Returns a graph which is equal to this graph but symmetric by removing one-way edges.- Returns:
- a symmetric graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
mirrorToSymmetricStructure
Returns a graph which is equal to this graph but symmetric by turning one-way edges into two-way edges of equal value.- Returns:
- a symmetric graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
toSymmetricStructure
Returns a graph which is equal to this graph but symmetric. The provided callback function is called for each one-way edge, and must return null to indicate that the edge should be removed, or a non-null value to indicate that the reverse edge should be added with the returned value.- Parameters:
edgeMap- mapping for how to handle each one-way edge, not null- Returns:
- a symmetric graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
isSymmetricStructure
default boolean isSymmetricStructure()Returns true if the graph is symmetric in structure. This requires that at least that for every edge (A, B) there exists an edge (B, A), even if the value of the edge is different.- Returns:
- true if structurally symmetric, false otherwise
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
structuralAsymmetries
Returns a list of edges which do no make corresponding reverse edges. i.e. each edge (A, B) such that edge (B, A) does not exist in the graph.- Returns:
- a list of asymmetries
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
applyToEdges
Returns a graph which is equal to this graph but with the specified transformation applied to all edges. The provided callback function is called for each edge, and must return null to indicate that the edge should be removed, or a non-null value to indicate that the edge should become equal to the given edge value. Identity mapping will preserve the same edge.- Parameters:
edgeMap- mapping a transformation of edges, not null- Returns:
- a graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
forEachEdge
Iterates over edges, calling the given callback function for each edge in the graph.- Parameters:
consumer- a consumer of edges, not null- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
deleteEdges
Returns a graph which is equal to this graph but without the edges matching the specified predicate. The provided callback function is called for each edge, and must return true to indicate that the edge should be removed, false to indicate that the edge should be preserved. Implementing classes can support this operation by default by implementingapplyToEdges(Function).- Parameters:
delete- predicate indicating which edges to delete, not null- Returns:
- a graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
preserveEdges
Returns a graph which is equal to this graph but with only the edges matching the specified predicate. The provided callback function is called for each edge, and must return false to indicate that the edge should be removed, true to indicate that the edge should be preserved. Implementing classes can support this operation by default by implementingapplyToEdges(Function).- Parameters:
preserve- predicate indicating which edges to preserve, not null- Returns:
- a graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
preserveVertices
Returns a graph which is equal to this graph but with only the vertices matching the specified predicate. The provided callback function is called for each vertex, and must return false to indicate that the edge should be removed, true to indicate that the edge should be preserved. If a vertex is deleted, connected in or out edges for that vertex are also deleted.- Parameters:
preserve- predicate indicating which vertices to preserve, not null- Returns:
- a graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-
deleteVertices
Returns a graph which is equal to this graph but without the vertices matching the specified predicate. The provided callback function is called for each vertex, and must return true to indicate that the edge should be removed, false to indicate that the edge should be preserved. If a vertex is deleted, connected in or out edges for that vertex are also deleted. Implementing classes can support this operation by default by implementingpreserveVertices(Predicate).- Parameters:
delete- predicate indicating which vertices to delete, not null- Returns:
- a graph
- Throws:
UnsupportedOperationException- if the graph implementation does not support this operation
-