Interface Graph<V,E>

Type Parameters:
V - the vertex type
E - the edge type
All Superinterfaces:
Explorable<V,E>
All Known Implementing Classes:
HashGraph

public interface Graph<V,E> extends Explorable<V,E>
A mathematical graph. Graph extends Explorable with more capabilities.
Author:
Lee A. Christie
  • Method Details

    • vertices

      default Set<V> 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

      boolean containsVertex(V vertex)
      Checks whether the graph contains the specified vertex.
      Parameters:
      vertex - the vertex, not null
      Returns:
      true if contained, false otherwise
    • containsEdge

      boolean containsEdge(V from, V to)
      Checks whether the graph contains an edge from one specified source to another.
      Parameters:
      from - the vertex for which this is an out-edge, not null
      to - the vertex for which this is an in-edge, not null
      Returns:
      if the edge exists, false otherwise
    • reverse

      default Graph<V,E> 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

      default List<Graph<V,E>> 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

      default Graph<V,E> 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

      default Graph<V,E> 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

      default Graph<V,E> toSymmetricStructure(Function<Graph.Edge<V,E>, E> edgeMap)
      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

      default List<Graph.Edge<V,E>> 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

      default Graph<V,E> applyToEdges(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. 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

      default void forEachEdge(Consumer<Graph.Edge<V,E>> consumer)
      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

      default Graph<V,E> deleteEdges(Predicate<Graph.Edge<V,E>> delete)
      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 implementing applyToEdges(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

      default Graph<V,E> 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. 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 implementing applyToEdges(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

      default Graph<V,E> preserveVertices(Predicate<V> preserve)
      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

      default Graph<V,E> deleteVertices(Predicate<V> delete)
      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 implementing preserveVertices(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