Beispiel #1
0
 /**
  * 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 already undirected, just returns
  * it.
  *
  * @param g the graph for which an undirected view is to be returned
  * @param <V> the graph vertex type
  * @param <E> the graph edge type
  *
  * @return an undirected view of the specified graph, if it is directed, or or the specified
  *         graph itself if it is already undirected.
  *
  * @throws IllegalArgumentException if the graph is neither directed nor undirected
  * @see AsUndirectedGraph
  */
 public static Graph <V, E> undirectedGraph <V, E>(Graph <V, E> g)
 {
     if (g.getType().isDirected())
     {
         throw new NotImplementedException();
         //return new AsUndirectedGraph<>(g);
     }
     else if (g.getType().isUndirected())
     {
         return(g);
     }
     else
     {
         throw new ArgumentException("graph must be either directed or undirected");
     }
 }
Beispiel #2
0
        /**
         * Adds all the vertices and all the edges of the specified source digraph to the specified
         * destination digraph, reversing all of the edges. If you want to do this as a linked view of
         * the source graph (rather than by copying to a destination graph), use
         * {@link EdgeReversedGraph} instead.
         *
         * <p>
         * The behavior of this operation is undefined if any of the specified graphs is modified while
         * operation is in progress.
         *
         * @param destination the graph to which vertices and edges are added
         * @param source the graph used as source for vertices and edges to add
         * @param <V> the graph vertex type
         * @param <E> the graph edge type
         *
         * @see EdgeReversedGraph
         */
        public static void addGraphReversed <V, E>(Graph <V, E> destination, Graph <V, E> source)
        {
            if (!source.getType().isDirected() || !destination.getType().isDirected())
            {
                throw new ArgumentException("graph must be directed");
            }

            addAllVertices(destination, source.vertexSet());

            foreach (E edge in source.edgeSet())
            {
                destination.addEdge(source.getEdgeTarget(edge), source.getEdgeSource(edge));
            }
        }