public class DirectionTransformer
extends java.lang.Object
Transforms graphs of one directionality into the other.
The copy
parameter of the transformation methods, if
true
, specifies
that the vertices of the input graph will be copied (using the
ArchetypeVertex.copy()
method) into the new graph;
if false
,
new vertices will be created (using the most restrictive vertex type
appropriate to the transformed graph type). In
either case, the user data repositories of the original vertices will be
imported into the corresponding vertices of the transformed graph.
The advantage
of using the copy
mode is that the vertex equality
relationship reflected by getEqualVertex()
will be
established between the vertices of the two graphs; however, the
vertices of the original graph must be able to accommodate edges of
the types appropriate to both the original and the transformed graph.
(As of version 1.4, this means that the vertices of the input
graph must be instances of either SparseVertex
or
SimpleSparseVertex
.)
The advantage of not using the copy
mode is that
the vertices of the original graph do not need to be able to accommodate
both directed and undirected edges, which relieves the user from having
to worry about this matter.
Directed edges cannot be copied to undirected edges or vice versa, so the edges of the transformed graph are always new edges; as above, the user data repositories of the original edges are imported into the edges of the transformed graph.
Known issues:
toUndirected()
: if the edges
(a,b)
and (b,a)
both exist in the original
graph, the user data from one will be imported into the new undirected
edge; the user data from the other will not be imported. It is not
specified which edge's user data will be imported.
The resultant graphs will not have parallel edges, regardless of
whether the original graphs had parallel edges.
Constructor and Description |
---|
DirectionTransformer() |
Modifier and Type | Method and Description |
---|---|
protected static java.util.Map |
convertVertices(Graph old,
Graph transformed,
boolean copy)
Puts a version of each vertex from
old into
transformed . |
static DirectedGraph |
toDirected(Graph graph)
Transforms
graph (which may be of any directionality)
into a directed graph without
parallel edges. |
static DirectedGraph |
toDirected(Graph graph,
boolean copy)
Transforms
graph (which may be of any directionality)
into a directed graph. |
static UndirectedGraph |
toUndirected(Graph graph)
Transforms
graph (which may be of any directionality)
into an undirected graph without
parallel edges. |
static UndirectedGraph |
toUndirected(Graph graph,
boolean copy)
Transforms
graph (which may be of any directionality)
into an undirected graph. |
public static UndirectedGraph toUndirected(Graph graph)
graph
(which may be of any directionality)
into an undirected graph without
parallel edges. (This is likely to be very useful for visualization
tasks). Creates exactly one undirected edge (a, b) iff a isNeighborOf b.
Equivalent to toUndirected(dGraph, true)
.graph
- the graph to be transformedUndirectedGraph
toUndirected(Graph, boolean)
public static UndirectedGraph toUndirected(Graph graph, boolean copy)
graph
(which may be of any directionality)
into an undirected graph. (This is likely to be very useful for
visualization tasks). Creates exactly one undirected edge (a, b) iff a
isNeighborOf b. If copy
is true
, specifies
that the vertices of the input graph will be copied (using the
ArchetypeVertex.copy()
method) into the new graph; if
false
, new vertices will be created (using the most
restrictive vertex type appropriate to the transformed graph type).graph
- the graph to be transformedcopy
- specifies whether the vertices are to be copied or duplicatedUndirectedGraph
protected static java.util.Map convertVertices(Graph old, Graph transformed, boolean copy)
old
into
transformed
. See the class-level documentation for
the behavior of the copy
parameter.public static DirectedGraph toDirected(Graph graph)
graph
(which may be of any directionality)
into a directed graph without
parallel edges. Creates exactly one directed edge (a, b) iff a
isPredecessorOf b (so an UndirectedEdge will actually produce two edges).
Equivalent to toDirected(graph, true)
.graph
- the graph to be transformedDirectedGraph
toDirected(Graph, boolean)
public static DirectedGraph toDirected(Graph graph, boolean copy)
graph
(which may be of any directionality)
into a directed graph. Creates exactly one directed edge (a, b) iff a
isPredecessorOf b (so an UndirectedEdge will actually produce two edges).
If copy
is true
, specifies
that the vertices of the input graph will be copied (using the
ArchetypeVertex.copy()
method) into the new graph; if
false
, new vertices will be created (using the most
restrictive vertex type appropriate to the transformed graph type).graph
- the graph to be transformedcopy
- specifies whether the vertices are to be copied or duplicatedDirectedGraph