/** * 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 * <code>true</code> if the destination graph has been modified as a result of this operation, * otherwise it returns <code>false</code>. * * <p> * The behavior of this operation is undefined if any of the specified graphs is modified while * operation is in progress. * </p> * * @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 * * @return <code>true</code> if and only if the destination graph has been changed as a result * of this operation. */ public static bool addGraph <V, E>(Graph <V, E> destination, Graph <V, E> source) { bool modified = addAllVertices(destination, source.vertexSet()); modified |= addAllEdges(destination, source, source.edgeSet()); return(modified); }
/** * 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)); } }