edu.uci.ics.jung.algorithms.transformation
Class DirectionTransformer

java.lang.Object
  extended by edu.uci.ics.jung.algorithms.transformation.DirectionTransformer

public class DirectionTransformer
extends 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:

Author:
Danyel Fisher, Joshua O'Madadhain

Constructor Summary
DirectionTransformer()
           
 
Method Summary
protected static 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectionTransformer

public DirectionTransformer()
Method Detail

toUndirected

public static UndirectedGraph toUndirected(Graph graph)
Transforms 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).

Parameters:
graph - the graph to be transformed
Returns:
the transformed UndirectedGraph
See Also:
toUndirected(Graph, boolean)

toUndirected

public static UndirectedGraph toUndirected(Graph graph,
                                           boolean copy)
Transforms 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).

Parameters:
graph - the graph to be transformed
copy - specifies whether the vertices are to be copied or duplicated
Returns:
the transformed UndirectedGraph

convertVertices

protected static Map convertVertices(Graph old,
                                     Graph transformed,
                                     boolean copy)
Puts a version of each vertex from old into transformed. See the class-level documentation for the behavior of the copy parameter.


toDirected

public static DirectedGraph toDirected(Graph graph)
Transforms 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).

Parameters:
graph - the graph to be transformed
Returns:
the transformed DirectedGraph
See Also:
toDirected(Graph, boolean)

toDirected

public static DirectedGraph toDirected(Graph graph,
                                       boolean copy)
Transforms 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).

Parameters:
graph - the graph to be transformed
copy - specifies whether the vertices are to be copied or duplicated
Returns:
the transformed DirectedGraph