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 typeE
- 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 (seeGraph.isDirected()
,Graph.isAllowParallelEdges()
,Graph.isAllowSelfEdges()
). Wether the adapter is weighted or not is determined in the constructor by passing the edge weight key, seeGraph.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:
Graph
,Graph
,JGraphTWrapper
-
-
Field Summary
-
Fields inherited from interface org.jgrapht.Graph
DEFAULT_EDGE_WEIGHT
-
-
Constructor Summary
Constructors Constructor Description JGraphTAdapter(Graph<V,E> graph)
Constructs a new unweighted adapter from the given JGAlgo graph.JGraphTAdapter(Graph<V,E> graph, String edgeWeightKey)
Constructs a new adapter from the given JGAlgo graph, optionally weighted.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
addEdge(V sourceVertex, V targetVertex)
boolean
addEdge(V sourceVertex, V targetVertex, E e)
V
addVertex()
boolean
addVertex(V v)
boolean
containsEdge(E e)
boolean
containsEdge(V sourceVertex, V targetVertex)
boolean
containsVertex(V v)
int
degreeOf(V vertex)
Set<E>
edgeSet()
Set<E>
edgesOf(V vertex)
Set<E>
getAllEdges(V sourceVertex, V targetVertex)
E
getEdge(V sourceVertex, V targetVertex)
V
getEdgeSource(E e)
Supplier<E>
getEdgeSupplier()
V
getEdgeTarget(E e)
double
getEdgeWeight(E e)
GraphType
getType()
Supplier<V>
getVertexSupplier()
Set<E>
incomingEdgesOf(V vertex)
int
inDegreeOf(V vertex)
int
outDegreeOf(V vertex)
Set<E>
outgoingEdgesOf(V vertex)
Set<E>
removeAllEdges(V sourceVertex, V targetVertex)
boolean
removeEdge(E e)
E
removeEdge(V sourceVertex, V targetVertex)
boolean
removeVertex(V v)
void
setEdgeSupplier(Supplier<E> edgeSupplier)
Set the edge supplier of the adapter.void
setEdgeWeight(E e, double weight)
void
setVertexSupplier(Supplier<V> vertexSupplier)
Set the vertex supplier of the adapter.Set<V>
vertexSet()
-
Methods inherited from class org.jgrapht.graph.AbstractGraph
assertVertexExist, equals, hashCode, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jgrapht.Graph
iterables, setEdgeWeight
-
-
-
-
Constructor Detail
-
JGraphTAdapter
public JGraphTAdapter(Graph<V,E> graph)
Constructs a new unweighted adapter from the given JGAlgo graph.- Parameters:
graph
- the JGAlgo graph
-
JGraphTAdapter
public JGraphTAdapter(Graph<V,E> graph, String edgeWeightKey)
Constructs a new adapter from the given JGAlgo graph, optionally weighted.- Parameters:
graph
- the JGAlgo graphedgeWeightKey
- the edge weight key of the double weights of the JGAlgo graph (seeGraph.edgesWeights(String)
), ornull
for unweighted- Throws:
IllegalArgumentException
- if the edge weight key is notnull
and it is not found in the JGAlgo graph
-
-
Method Detail
-
setVertexSupplier
public void setVertexSupplier(Supplier<V> vertexSupplier)
Set the vertex supplier of the adapter.- Parameters:
vertexSupplier
- the vertex supplier, ornull
to not support adding vertices viaaddVertex()
-
setEdgeSupplier
public void setEdgeSupplier(Supplier<E> edgeSupplier)
Set the edge supplier of the adapter.- Parameters:
edgeSupplier
- the edge supplier, ornull
to not support adding edges viaaddEdge(Object, Object)
-
addVertex
public V addVertex()
-
addVertex
public boolean addVertex(V v)
-
containsEdge
public boolean containsEdge(V sourceVertex, V targetVertex)
- Specified by:
containsEdge
in interfaceGraph<V,E>
- Overrides:
containsEdge
in classAbstractGraph<V,E>
-
containsEdge
public boolean containsEdge(E e)
-
containsVertex
public boolean containsVertex(V v)
-
degreeOf
public int degreeOf(V vertex)
-
inDegreeOf
public int inDegreeOf(V vertex)
-
outDegreeOf
public int outDegreeOf(V vertex)
-
removeAllEdges
public Set<E> removeAllEdges(V sourceVertex, V targetVertex)
- Specified by:
removeAllEdges
in interfaceGraph<V,E>
- Overrides:
removeAllEdges
in classAbstractGraph<V,E>
-
removeEdge
public boolean removeEdge(E e)
-
removeVertex
public boolean removeVertex(V v)
-
getType
public GraphType getType()
-
getEdgeWeight
public double getEdgeWeight(E e)
-
setEdgeWeight
public void setEdgeWeight(E e, double weight)
-
-