org._3pq.jgrapht
Class GraphHelper
java.lang.Object
org._3pq.jgrapht.GraphHelper
public final class GraphHelper
extends java.lang.Object
A collection of utilities to assist the working with graphs.
static Edge | addEdge(Graph g, Object sourceVertex, Object targetVertex, double weight) - Creates a new edge and adds it to the specified graph similarly to the
Graph.addEdge(Object,Object) method.
|
static Edge | addEdgeWithVertices(Graph g, Object sourceVertex, Object 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 Edge | addEdgeWithVertices(Graph g, Object sourceVertex, Object 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 boolean | addEdgeWithVertices(Graph g, Edge e) - Adds the specified edge to the specified graph including its vertices.
|
static boolean | addGraph(Graph destination, Graph source) - Adds all the vertices and all the edges of the specified source graph to
the specified destination graph.
|
static void | addGraphReversed(DirectedGraph destination, DirectedGraph 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 List | neighborListOf(Graph g, Object vertex) - Returns a list of vertices that are the neighbors of a specified vertex.
|
static List | predecessorListOf(DirectedGraph g, Object vertex) - Returns a list of vertices that are the predecessors of a specified
vertex.
|
static List | successorListOf(DirectedGraph g, Object vertex) - Returns a list of vertices that are the successors of a specified
vertex.
|
static UndirectedGraph | undirectedGraph(Graph g) - Returns an undirected view of the specified graph.
|
addEdge
public static Edge addEdge(Graph g,
Object sourceVertex,
Object targetVertex,
double weight)
g
- the graph for which the edge to be added.sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.weight
- weight of the edge.
- The newly created edge if added to the graph, otherwise
null
.
addEdgeWithVertices
public static Edge addEdgeWithVertices(Graph g,
Object sourceVertex,
Object 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.
g
- the graph for which the specified edge to be added.sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.
- The newly created edge if added to the graph, otherwise
null
.
addEdgeWithVertices
public static Edge addEdgeWithVertices(Graph g,
Object sourceVertex,
Object 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.
g
- the graph for which the specified edge to be added.sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.weight
- weight of the edge.
- The newly created edge if added to the graph, otherwise
null
.
addEdgeWithVertices
public static boolean addEdgeWithVertices(Graph g,
Edge e)
Adds the specified edge to the specified graph including its vertices.
If any of the vertices of the specified edge are not already in the
graph they are also added (before the edge is added).
g
- the graph for which the specified edge to be added.e
- the edge to be added to the graph (including its vertices).
true
if and only if the specified edge was not
already contained in the graph.
addGraph
public static boolean addGraph(Graph destination,
Graph source)
Adds all the vertices and all the edges of the specified source graph to
the specified destination graph. First all vertices of the source graph
are added to the destination graph. Then every edge of the source graph
is added to the destination graph. This method returns
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.
destination
- the graph to which vertices and edges are added.source
- the graph used as source for vertices and edges to add.
true
if and only if the destination graph has been
changed as a result of this operation.
addGraphReversed
public static void addGraphReversed(DirectedGraph destination,
DirectedGraph source)
Adds all the vertices and all the edges of the specified source digraph
to the specified destination digraph, reversing all of the edges.
The behavior of this operation is undefined if any of the specified
graphs is modified while operation is in progress.
destination
- the graph to which vertices and edges are added.source
- the graph used as source for vertices and edges to add.
neighborListOf
public static List neighborListOf(Graph g,
Object vertex)
Returns a list of vertices that are the neighbors of a specified vertex.
If the graph is a multigraph vertices may appear more than once in the
returned list.
g
- the graph to look for neighbors in.vertex
- the vertex to get the neighbors of.
- a list of the vertices that are the neighbors of the specified
vertex.
predecessorListOf
public static List predecessorListOf(DirectedGraph g,
Object vertex)
Returns a list of vertices that are the predecessors of a specified
vertex. If the graph is a multigraph, vertices may appear more than
once in the returned list.
g
- the graph to look for predecessors in.vertex
- the vertex to get the predecessors of.
- a list of the vertices that are the predecessors of the
specified vertex.
successorListOf
public static List successorListOf(DirectedGraph g,
Object vertex)
Returns a list of vertices that are the successors of a specified
vertex. If the graph is a multigraph vertices may appear more than once
in the returned list.
g
- the graph to look for successors in.vertex
- the vertex to get the successors of.
- a list of the vertices that are the successors of the specified
vertex.
undirectedGraph
public static UndirectedGraph undirectedGraph(Graph g)
Returns an undirected view of the specified graph. If the specified
graph is directed, returns an undirected view of it. If the specified
graph is undirected, just returns it.
g
- the graph for which an undirected view to be returned.
- an undirected view of the specified graph, if it is directed, or
or the specified graph itself if it is undirected.