public abstract class Graphs extends Object
Constructor and Description 

Graphs() 
Modifier and Type  Method and Description 

static <V,E> boolean 
addAllEdges(Graph<? super V,? super E> destination,
Graph<V,E> source,
Collection<? extends E> edges)
Adds a subset of the edges of the specified source graph to the specified destination graph.

static <V,E> boolean 
addAllVertices(Graph<? super V,? super E> destination,
Collection<? extends V> vertices)
Adds all of the specified vertices to the destination graph.

static <V,E> E 
addEdge(Graph<V,E> g,
V sourceVertex,
V targetVertex,
double weight)
Creates a new edge and adds it to the specified graph similarly to the
Graph.addEdge(Object, Object) method. 
static <V,E> boolean 
addEdgeWithVertices(Graph<V,E> targetGraph,
Graph<V,E> sourceGraph,
E edge)
Adds the specified edge to the graph, including its vertices if not already included.

static <V,E> E 
addEdgeWithVertices(Graph<V,E> g,
V sourceVertex,
V targetVertex)
Adds the specified source and target vertices to the graph, if not already included, and
creates a new edge and adds it to the specified graph similarly to the
Graph.addEdge(Object, Object) method. 
static <V,E> E 
addEdgeWithVertices(Graph<V,E> g,
V sourceVertex,
V targetVertex,
double weight)
Adds the specified source and target vertices to the graph, if not already included, and
creates a new weighted edge and adds it to the specified graph similarly to the
Graph.addEdge(Object, Object) method. 
static <V,E> boolean 
addGraph(Graph<? super V,? super E> destination,
Graph<V,E> source)
Adds all the vertices and all the edges of the specified source graph to the specified
destination graph.

static <V,E> void 
addGraphReversed(Graph<? super V,? super E> destination,
Graph<V,E> source)
Adds all the vertices and all the edges of the specified source digraph to the specified
destination digraph, reversing all of the edges.

static <V,E> void 
addIncomingEdges(Graph<V,E> graph,
V target,
Iterable<V> sources)
Add edges from multiple source vertices to one target vertex.

static <V,E> void 
addOutgoingEdges(Graph<V,E> graph,
V source,
Iterable<V> targets)
Add edges from one source vertex to multiple target vertices.

static <V,E> V 
getOppositeVertex(Graph<V,E> g,
E e,
V v)
Gets the vertex opposite another vertex across an edge.

static <V,E> VertexToIntegerMapping<V> 
getVertexToIntegerMapping(Graph<V,E> graph)
Compute a new mapping from the vertices of a graph to the integer range $[0, n)$ where $n$ is
the number of vertices in the graph.

static <V,E> List<V> 
neighborListOf(Graph<V,E> g,
V vertex)
Returns a list of vertices that are the neighbors of a specified vertex.

static <V,E> Set<V> 
neighborSetOf(Graph<V,E> g,
V vertex)
Returns a set of vertices that are neighbors of a specified vertex.

static <V,E> List<V> 
predecessorListOf(Graph<V,E> g,
V vertex)
Returns a list of vertices that are the direct predecessors of a specified vertex.

static <V,E> boolean 
removeVertexAndPreserveConnectivity(Graph<V,E> graph,
Iterable<V> vertices)
Removes all the given vertices from the given graph.

static <V,E> boolean 
removeVertexAndPreserveConnectivity(Graph<V,E> graph,
V vertex)
Removes the given vertex from the given graph.

static <V,E> boolean 
removeVerticesAndPreserveConnectivity(Graph<V,E> graph,
Predicate<V> predicate)
Filters vertices from the given graph and subsequently removes them.

static <V,E> List<V> 
successorListOf(Graph<V,E> g,
V vertex)
Returns a list of vertices that are the direct successors of a specified vertex.

static <V,E> boolean 
testIncidence(Graph<V,E> g,
E e,
V v)
Tests whether an edge is incident to a vertex.

static <V,E> Graph<V,E> 
undirectedGraph(Graph<V,E> g)
Returns an undirected view of the specified graph.

static <V,E> boolean 
vertexHasPredecessors(Graph<V,E> graph,
V vertex)
Check if a vertex has any direct predecessors.

static <V,E> boolean 
vertexHasSuccessors(Graph<V,E> graph,
V vertex)
Check if a vertex has any direct successors.

public static <V,E> E addEdge(Graph<V,E> g, V sourceVertex, V targetVertex, double weight)
Graph.addEdge(Object, Object)
method.V
 the graph vertex typeE
 the graph edge typeg
 the graph for which the edge to be addedsourceVertex
 source vertex of the edgetargetVertex
 target vertex of the edgeweight
 weight of the edge
null
.UnsupportedOperationException
 if the graph has no edge supplierGraph.addEdge(Object, Object)
public static <V,E> E addEdgeWithVertices(Graph<V,E> g, V sourceVertex, V targetVertex)
Graph.addEdge(Object, Object)
method.V
 the graph vertex typeE
 the graph edge typeg
 the graph for which the specified edge to be addedsourceVertex
 source vertex of the edgetargetVertex
 target vertex of the edge
null
.public static <V,E> boolean addEdgeWithVertices(Graph<V,E> targetGraph, Graph<V,E> sourceGraph, E edge)
V
 the graph vertex typeE
 the graph edge typetargetGraph
 the graph for which the specified edge to be addedsourceGraph
 the graph in which the specified edge is already presentedge
 edge to addpublic static <V,E> E addEdgeWithVertices(Graph<V,E> g, V sourceVertex, V targetVertex, double weight)
Graph.addEdge(Object, Object)
method.V
 the graph vertex typeE
 the graph edge typeg
 the graph for which the specified edge to be addedsourceVertex
 source vertex of the edgetargetVertex
 target vertex of the edgeweight
 weight of the edge
null
.public static <V,E> boolean addGraph(Graph<? super V,? super E> destination, Graph<V,E> source)
true
if the destination graph has been modified as a result of this operation,
otherwise it returns false
.
The behavior of this operation is undefined if any of the specified graphs is modified while operation is in progress.
V
 the graph vertex typeE
 the graph edge typedestination
 the graph to which vertices and edges are addedsource
 the graph used as source for vertices and edges to addtrue
if and only if the destination graph has been changed as a result
of this operation.public static <V,E> void addGraphReversed(Graph<? super V,? super E> destination, Graph<V,E> source)
EdgeReversedGraph
instead.
The behavior of this operation is undefined if any of the specified graphs is modified while operation is in progress.
V
 the graph vertex typeE
 the graph edge typedestination
 the graph to which vertices and edges are addedsource
 the graph used as source for vertices and edges to addEdgeReversedGraph
public static <V,E> boolean addAllEdges(Graph<? super V,? super E> destination, Graph<V,E> source, Collection<? extends E> edges)
addEdgeWithVertices(org.jgrapht.Graph<V, E>, V, V)
is used for the transfer, so source
vertexes will be added automatically to the target graph.V
 the graph vertex typeE
 the graph edge typedestination
 the graph to which edges are to be addedsource
 the graph used as a source for edges to addedges
 the edges to be addedpublic static <V,E> boolean addAllVertices(Graph<? super V,? super E> destination, Collection<? extends V> vertices)
Graph.addVertex(Object)
method.V
 the graph vertex typeE
 the graph edge typedestination
 the graph to which edges are to be addedvertices
 the vertices to be added to the graphNullPointerException
 if the specified vertices contains one or more null vertices, or
if the specified vertex collection is
null.Graph.addVertex(Object)
public static <V,E> List<V> neighborListOf(Graph<V,E> g, V vertex)
The method uses Graph.edgesOf(Object)
to traverse the graph.
V
 the graph vertex typeE
 the graph edge typeg
 the graph to look for neighbors invertex
 the vertex to get the neighbors ofpublic static <V,E> Set<V> neighborSetOf(Graph<V,E> g, V vertex)
V
 the graph vertex typeE
 the graph edge typeg
 the graph to look for neighbors invertex
 the vertex to get the neighbors ofpublic static <V,E> List<V> predecessorListOf(Graph<V,E> g, V vertex)
The method uses Graph.incomingEdgesOf(Object)
to traverse the graph.
V
 the graph vertex typeE
 the graph edge typeg
 the graph to look for predecessors invertex
 the vertex to get the predecessors ofpublic static <V,E> List<V> successorListOf(Graph<V,E> g, V vertex)
The method uses Graph.outgoingEdgesOf(Object)
to traverse the graph.
V
 the graph vertex typeE
 the graph edge typeg
 the graph to look for successors invertex
 the vertex to get the successors ofpublic static <V,E> Graph<V,E> undirectedGraph(Graph<V,E> g)
V
 the graph vertex typeE
 the graph edge typeg
 the graph for which an undirected view is to be returnedIllegalArgumentException
 if the graph is neither directed nor undirectedAsUndirectedGraph
public static <V,E> boolean testIncidence(Graph<V,E> g, E e, V v)
V
 the graph vertex typeE
 the graph edge typeg
 graph containing e and ve
 edge in gv
 vertex in gpublic static <V,E> V getOppositeVertex(Graph<V,E> g, E e, V v)
V
 the graph vertex typeE
 the graph edge typeg
 graph containing e and ve
 edge in gv
 vertex in gpublic static <V,E> boolean removeVertexAndPreserveConnectivity(Graph<V,E> graph, V vertex)
V
 the graph vertex typeE
 the graph edge typegraph
 graph to be mutatedvertex
 vertex to be removed from this graph, if presentpublic static <V,E> boolean removeVerticesAndPreserveConnectivity(Graph<V,E> graph, Predicate<V> predicate)
V
 the graph vertex typeE
 the graph edge typegraph
 graph to be mutatedpredicate
 a noninterfering stateless predicate to apply to each vertex to determine
if it should be removed from the graphpublic static <V,E> boolean removeVertexAndPreserveConnectivity(Graph<V,E> graph, Iterable<V> vertices)
V
 the graph vertex typeE
 the graph edge typegraph
 to be mutatedvertices
 vertices to be removed from this graph, if presentpublic static <V,E> void addOutgoingEdges(Graph<V,E> graph, V source, Iterable<V> targets)
Graph
implementation.V
 the graph vertex typeE
 the graph edge typegraph
 graph to be mutatedsource
 source vertex of the new edgestargets
 target vertices for the new edgespublic static <V,E> void addIncomingEdges(Graph<V,E> graph, V target, Iterable<V> sources)
Graph
implementation.V
 the graph vertex typeE
 the graph edge typegraph
 graph to be mutatedtarget
 target vertex for the new edgessources
 source vertices for the new edgespublic static <V,E> boolean vertexHasSuccessors(Graph<V,E> graph, V vertex)
V
 the graph vertex typeE
 the graph edge typegraph
 the graph to look for successorsvertex
 the vertex to look for successorspublic static <V,E> boolean vertexHasPredecessors(Graph<V,E> graph, V vertex)
V
 the graph vertex typeE
 the graph edge typegraph
 the graph to look for predecessorsvertex
 the vertex to look for predecessorspublic static <V,E> VertexToIntegerMapping<V> getVertexToIntegerMapping(Graph<V,E> graph)
V
 the graph vertex typeE
 the graph edge typegraph
 the input graphvertexMap
and the indexList
NullPointerException
 if graph
is null
VertexToIntegerMapping
Copyright © 2019. All rights reserved.