Class JGraphTAdapter<V,E>

java.lang.Object
org.jgrapht.graph.AbstractGraph<V,E>
com.jgalgo.adapt.jgrapht.JGraphTAdapter<V,E>
Type Parameters:
V - the vertices type
E - the edges type
All Implemented Interfaces:
Graph<V,E>

public class JGraphTAdapter<V,E> extends AbstractGraph<V,E>
An adapter from JGAlgo graph to JGraphT graph.

The adapter is constructed with a JGAlgo graph and implements the JGraphT graph interface, and can be used with any JGraphT algorithm. The adapter is a live view, so any change in the JGraphT graph is reflected in the JGAlgo graph and vice versa, but the underlying JGAlgo graph should not be modified directly.

The GraphType of the adapter determined by the capabilities of the underlying JGAlgo graph (see Graph.isDirected(), Graph.isAllowParallelEdges(), Graph.isAllowSelfEdges()). Wether the adapter is weighted or not is determined in the constructor by passing the edge weight key, see Graph.edgesWeights(String). Although JGAlgo graphs support multiple types of weights, both for vertices and edges, JGraphT graphs support only one double weight type, for edges.

For adapting the other way around, from JGraphT to JGAlgo, see JGraphTWrapper.

Author:
Barak Ugav
See Also:
  • Constructor Details Link icon

    • JGraphTAdapter Link icon

      public JGraphTAdapter(Graph<V,E> graph)
      Constructs a new unweighted adapter from the given JGAlgo graph.
      Parameters:
      graph - the JGAlgo graph
    • JGraphTAdapter Link icon

      public JGraphTAdapter(Graph<V,E> graph, String edgeWeightKey)
      Constructs a new adapter from the given JGAlgo graph, optionally weighted.
      Parameters:
      graph - the JGAlgo graph
      edgeWeightKey - the edge weight key of the double weights of the JGAlgo graph (see Graph.edgesWeights(String)), or null for unweighted
      Throws:
      IllegalArgumentException - if the edge weight key is not null and it is not found in the JGAlgo graph
  • Method Details Link icon

    • setVertexSupplier Link icon

      public void setVertexSupplier(Supplier<V> vertexSupplier)
      Set the vertex supplier of the adapter.
      Parameters:
      vertexSupplier - the vertex supplier, or null to not support adding vertices via addVertex()
    • setEdgeSupplier Link icon

      public void setEdgeSupplier(Supplier<E> edgeSupplier)
      Set the edge supplier of the adapter.
      Parameters:
      edgeSupplier - the edge supplier, or null to not support adding edges via addEdge(Object, Object)
    • getAllEdges Link icon

      public Set<E> getAllEdges(V sourceVertex, V targetVertex)
    • getEdge Link icon

      public E getEdge(V sourceVertex, V targetVertex)
    • getVertexSupplier Link icon

      public Supplier<V> getVertexSupplier()
    • getEdgeSupplier Link icon

      public Supplier<E> getEdgeSupplier()
    • addEdge Link icon

      public E addEdge(V sourceVertex, V targetVertex)
    • addEdge Link icon

      public boolean addEdge(V sourceVertex, V targetVertex, E e)
    • addVertex Link icon

      public V addVertex()
    • addVertex Link icon

      public boolean addVertex(V v)
    • containsEdge Link icon

      public boolean containsEdge(V sourceVertex, V targetVertex)
      Specified by:
      containsEdge in interface Graph<V,E>
      Overrides:
      containsEdge in class AbstractGraph<V,E>
    • containsEdge Link icon

      public boolean containsEdge(E e)
    • containsVertex Link icon

      public boolean containsVertex(V v)
    • edgeSet Link icon

      public Set<E> edgeSet()
    • degreeOf Link icon

      public int degreeOf(V vertex)
    • edgesOf Link icon

      public Set<E> edgesOf(V vertex)
    • inDegreeOf Link icon

      public int inDegreeOf(V vertex)
    • incomingEdgesOf Link icon

      public Set<E> incomingEdgesOf(V vertex)
    • outDegreeOf Link icon

      public int outDegreeOf(V vertex)
    • outgoingEdgesOf Link icon

      public Set<E> outgoingEdgesOf(V vertex)
    • removeAllEdges Link icon

      public Set<E> removeAllEdges(V sourceVertex, V targetVertex)
      Specified by:
      removeAllEdges in interface Graph<V,E>
      Overrides:
      removeAllEdges in class AbstractGraph<V,E>
    • removeEdge Link icon

      public E removeEdge(V sourceVertex, V targetVertex)
    • removeEdge Link icon

      public boolean removeEdge(E e)
    • removeVertex Link icon

      public boolean removeVertex(V v)
    • vertexSet Link icon

      public Set<V> vertexSet()
    • getEdgeSource Link icon

      public V getEdgeSource(E e)
    • getEdgeTarget Link icon

      public V getEdgeTarget(E e)
    • getType Link icon

      public GraphType getType()
    • getEdgeWeight Link icon

      public double getEdgeWeight(E e)
    • setEdgeWeight Link icon

      public void setEdgeWeight(E e, double weight)