|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.uci.ics.jung.utils.GraphUtils
public class GraphUtils
A series of helpful utility methods. All methods in GraphUtils can be accomplished with public members of other code; these are simply combinations that we found useful.
Constructor Summary | |
---|---|
GraphUtils()
|
Method Summary | |
---|---|
static void |
addDirectedVertices(Graph g,
int count)
Deprecated. As of version 1.2, replaced by addVertices(edu.uci.ics.jung.graph.Graph, int) . |
static Edge |
addEdge(Graph g,
Vertex v1,
Vertex v2)
Adds an appropriate edge between two vertices. |
static void |
addEdges(Graph g,
Set edges)
Adds all edges in the specified set to g . |
static void |
addEdges(Hypergraph g,
Set edges)
Adds all edges in the specified set to g . |
static void |
addUndirectedVertices(Graph g,
int count)
Deprecated. As of version 1.2, replaced by addVertices(edu.uci.ics.jung.graph.Graph, int) . |
static void |
addVertices(Graph g,
int count)
Adds count vertices into a graph. |
static void |
addVertices(Graph g,
Set vertices)
Adds all vertices in the specified set to g . |
static void |
addVertices(Hypergraph g,
Set vertices)
Adds all vertices in the specified set to g . |
static boolean |
areEquivalent(ArchetypeGraph g1,
ArchetypeGraph g2)
Returns true if g1 and g2 have equivalent
vertex and edge sets (that is, if each vertex and edge in g1
has an equivalent in g2 , and vice versa), and false
otherwise. |
static void |
copyLabels(StringLabeller source,
StringLabeller target)
Copies the labels of vertices from one StringLabeller to another. |
static void |
copyValues(ArchetypeGraph g,
NumberVertexValue source,
NumberVertexValue dest)
Copies, for each vertex v in g ,
source 's value to dest . |
static Graph |
edgeSetToGraph(Set edges,
boolean retain)
Given a set of edges, creates a new Graph that contains all of those edges, and at least all the vertices that are attached to them. |
static Set |
getEqualEdges(Set s,
ArchetypeGraph g)
Returns the set of edges in g which are equal
to the edges in g . |
static Set |
getEqualVertices(Set s,
ArchetypeGraph g)
Returns the set of vertices in g which are equal
to the vertices in g . |
static VertexGenerator |
getVertexGenerator(ArchetypeGraph g)
Returns the VertexGenerator , if any, stored in g 's
user data at the standardized location specified by the VG interface: VertexGenerator.TAG . |
static String |
printVertices(Collection s,
StringLabeller sl)
For every vertex in s, prints sl.get(s). |
static void |
removeEdges(Graph g,
Set edges)
Removes all vertices in the specified set from g . |
static void |
removeEdges(Hypergraph g,
Set edges)
Removes all vertices in the specified set from g . |
static void |
removeVertices(Graph g,
Set vertices)
Removes all vertices in the specified set from g . |
static void |
removeVertices(Hypergraph g,
Set vertices)
Removes all vertices in the specified set from g . |
static UndirectedGraph |
transform(DirectedGraph dGraph)
Deprecated. As of version 1.4, replaced by DirectionTransformer.toUndirected(Graph) |
static DirectedGraph |
transform(Graph uGraph)
Deprecated. As of version 1.4, replaced by DirectionTransformer.toDirected(Graph) |
static Set |
translateAll(Set s,
Graph g)
Deprecated. As of version 1.4, replaced by getEqualVertices(Set, ArchetypeGraph) |
static Set |
translateAllEdges(Set s,
Graph g)
Deprecated. As of version 1.4, replaced by getEqualEdges(Set, ArchetypeGraph) |
static ArchetypeGraph |
union(ArchetypeGraph g1,
ArchetypeGraph g2)
Returns a graph which consists of the union of the two input graphs. |
static DoubleArrayList |
vertexMapToDAL(Map vertex_values,
Indexer indexer)
Converts vertex_values (a Map of vertex to Number values)
to a DoubleArrayList, using indexer to determine the location
of each vertex's value in the DAL. |
static Graph |
vertexSetToGraph(Set s)
Given a set of vertices, creates a new Graph that contains all of those vertices, and all the edges that connect them. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GraphUtils()
Method Detail |
---|
public static Edge addEdge(Graph g, Vertex v1, Vertex v2)
DirectedSparseEdge
,
otherwise a new
UndirectedSparseEdge
.
This is a convenience method; one might instead just call g.addEdge( new XXSparseEdge(v1, v2)))
.
The input vertices must be of type Vertex
,
or the method will throw a ClassCastException
.
ClassCastException
- if the input aren't Vertices
IllegalArgumentException
- if the vertices don't belong to the same graphGraph.addEdge(edu.uci.ics.jung.graph.Edge)
,
AbstractSparseGraph.addEdge(edu.uci.ics.jung.graph.Edge)
public static void addVertices(Graph g, int count)
count
vertices into a graph. This is a convenience
method; one might instead just call g.addVertex( new SparseVertex()))
count
times.
The input graph must be one that can accept a series of
directed vertices
.
g
- A graph to add the vertices tocount
- how many vertices to addAbstractSparseGraph.addVertex(edu.uci.ics.jung.graph.Vertex)
public static void addDirectedVertices(Graph g, int count)
addVertices(edu.uci.ics.jung.graph.Graph, int)
.
count
directed vertices into a graph. This is a
convenience method; one might instead just call g.addVertex( new DirectedSparseVertex()))
count
times.
The input graph must be one that can accept a series of
directed vertices
.
g
- A graph to add the vertices tocount
- how many vertices to addAbstractSparseGraph.addVertex(edu.uci.ics.jung.graph.Vertex)
public static void addUndirectedVertices(Graph g, int count)
addVertices(edu.uci.ics.jung.graph.Graph, int)
.
count
undirected vertices into a graph. This is a
convenience method; one might instead just call g.addVertex( new UndirectedSparseVertex()))
count
times.
The input graph must be one that can accept a series of
undirected vertices
.
g
- A graph to add the vertices tocount
- how many vertices to addAbstractSparseGraph.addVertex(edu.uci.ics.jung.graph.Vertex)
public static Set translateAll(Set s, Graph g)
getEqualVertices(Set, ArchetypeGraph)
set
into the graph
given. For each vertex, then, it gets the equivalent vertex in g
,
and returns the collated set.
s
- The set of input vertices, not from gg
- The graph which has the corresponding vertices
ArchetypeVertex.getEqualVertex(edu.uci.ics.jung.graph.ArchetypeGraph)
public static Set getEqualVertices(Set s, ArchetypeGraph g)
g
which are equal
to the vertices in g
.
public static Set translateAllEdges(Set s, Graph g)
getEqualEdges(Set, ArchetypeGraph)
set
into the graph
given. For each edge, then, it gets the equivalent edge in g
,
and returns the collated set.
s
- The set of input edges, not from gg
- The graph which has the corresponding edges
ArchetypeEdge.getEqualEdge(edu.uci.ics.jung.graph.ArchetypeGraph)
public static Set getEqualEdges(Set s, ArchetypeGraph g)
g
which are equal
to the edges in g
.
public static Graph vertexSetToGraph(Set s)
UnassembledGraph
mechanism to create the graph.
s
- A set of Vertex s that want to be a part of a new
Graph
Graph.newInstance
,
containing vertices equivalent to (and that are copies of!) all
the vertices in the input set. Note that if the input is an
empty set, null is returned.public static Graph edgeSetToGraph(Set edges, boolean retain)
UnassembledGraph
mechanism to create the graph. The parameter decides what to do with
disconnected vertices: true says that they should be
retained, false says that they should be discarded (with a
DropSoloNodesFilter
).
edges
- A set of Edge s that want to be a part of a new
Graphretain
- Is true if all isolated vertices should be retained; is false if they
should be discarded.
Graph.newInstance
,
containing edges equivalent to (and that are copies of!) all the
edges in the input set. Note that if the input is an empty set,
null is returned.public static ArchetypeGraph union(ArchetypeGraph g1, ArchetypeGraph g2)
public static DirectedGraph transform(Graph uGraph)
DirectionTransformer.toDirected(Graph)
uGraph
- the undirected graph to transform
public static UndirectedGraph transform(DirectedGraph dGraph)
DirectionTransformer.toUndirected(Graph)
dGraph
- the directed graph to transform
public static void copyLabels(StringLabeller source, StringLabeller target) throws StringLabeller.UniqueLabelException
source
- the source StringLabellertarget
- the target StringLabeller
StringLabeller.UniqueLabelException
public static boolean areEquivalent(ArchetypeGraph g1, ArchetypeGraph g2)
g1
and g2
have equivalent
vertex and edge sets (that is, if each vertex and edge in g1
has an equivalent in g2
, and vice versa), and false
otherwise.
public static String printVertices(Collection s, StringLabeller sl)
s
- sl
- public static void copyValues(ArchetypeGraph g, NumberVertexValue source, NumberVertexValue dest)
v
in g
,
source
's value to dest
.
g
- the graph from which the vertices are takensource
- the NumberVertexValue
from which values are to be copieddest
- the NumberVertexValue
into which values are to be copiedpublic static VertexGenerator getVertexGenerator(ArchetypeGraph g)
VertexGenerator
, if any, stored in g
's
user data at the standardized location specified by the VG interface: VertexGenerator.TAG
.
public static DoubleArrayList vertexMapToDAL(Map vertex_values, Indexer indexer)
vertex_values
(a Map of vertex to Number values)
to a DoubleArrayList, using indexer
to determine the location
of each vertex's value in the DAL.
Note: assumes that indexer
is 0-based and covers
all the vertices in vertex_values
, and that
vertex_values
contains Number
instances.
vertex_values
- a map of vertices to Number
instancesindexer
- a 0-based index of the vertices
public static void addVertices(Graph g, Set vertices)
g
. Syntactic
sugar for a loop that calls g.addVertex
on all elements
of the set.
If any element of vertices
may not be legally added
to this graph, throws an exception: ClassCastException
if
the type is inappropriate, and IllegalArgumentException
otherwise. If an exception is thrown, any vertices that may
already have been added are not guaranteed to be retained.
public static void addVertices(Hypergraph g, Set vertices)
g
. Syntactic
sugar for a loop that calls g.addVertex
on all elements
of the set.
If any element of vertices
may not be legally added
to this graph, throws an exception: ClassCastException
if
the type is inappropriate, and IllegalArgumentException
otherwise. If an exception is thrown, any vertices that may
already have been added are not guaranteed to be retained.
public static void addEdges(Graph g, Set edges)
g
. Syntactic
sugar for a loop that calls g.addEdge
on all elements
of the set.
If any element of edges
may not be legally added
to this graph, throws an exception: ClassCastException
if
the type is inappropriate, and IllegalArgumentException
otherwise. If an exception is thrown, any edges that may
already have been added are not guaranteed to be retained.
public static void addEdges(Hypergraph g, Set edges)
g
. Syntactic
sugar for a loop that calls g.addEdge
on all elements
of the set.
If any element of edges
may not be legally added
to this graph, throws an exception: ClassCastException
if
the type is inappropriate, and IllegalArgumentException
otherwise. If an exception is thrown, any edges that may
already have been added are not guaranteed to be retained.
public static void removeVertices(Graph g, Set vertices)
g
. Syntactic
sugar for a loop that calls g.removeVertex
on all elements
of the set.
If any element of vertices
is not part of this graph,
then throws IllegalArgumentException
. If this
exception is thrown, any vertices that may have been removed already
are not guaranteed to be restored to the graph.
public static void removeVertices(Hypergraph g, Set vertices)
g
. Syntactic
sugar for a loop that calls g.removeVertex
on all elements
of the set.
If any element of vertices
is not part of this graph,
then throws IllegalArgumentException
. If this
exception is thrown, any vertices that may have been removed already
are not guaranteed to be restored to the graph.
public static void removeEdges(Graph g, Set edges)
g
. Syntactic
sugar for a loop that calls g.removeVertex
on all elements
of the set.
If any element of edges
is not part of this graph,
then throws IllegalArgumentException
. If this
exception is thrown, any edges that may have been removed already
are not guaranteed to be restored to the graph.
public static void removeEdges(Hypergraph g, Set edges)
g
. Syntactic
sugar for a loop that calls g.removeVertex
on all elements
of the set.
If any element of edges
is not part of this graph,
then throws IllegalArgumentException
. If this
exception is thrown, any edges that may have been removed already
are not guaranteed to be restored to the graph.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |