public Graph<CV,CE> collapseVertexPartitions(VertexPartition<V,E> partitioning){
  Graph<V,E> original=partitioning.getGraph();
  Graph<CV,CE> collapsed=graph_factory.get();
  for (  Set<V> set : partitioning.getVertexPartitions()) {
    CV cv=vertex_factory.get();
    collapsed.addVertex(vertex_factory.get());
    set_collapsedv.put(set,cv);
  }
  for (  E e : original.getEdges()) {
    Collection<V> incident=original.getIncidentVertices(e);
    Collection<CV> collapsed_vertices=new HashSet<CV>();
    Map<V,Set<V>> vertex_partitions=partitioning.getVertexToPartitionMap();
    for (    V v : incident)     collapsed_vertices.add(set_collapsedv.get(vertex_partitions.get(v)));
    if (collapsed_vertices.size() > 1) {
      CE ce=edge_factory.get();
      collapsed.addEdge(ce,collapsed_vertices);
    }
  }
  return collapsed;
}

public Graph < CV , CE > collapseVertexPartitions ( VertexPartition < V , E > partitioning ) { Graph < V , E > original = partitioning . getGraph ( ) ; Graph < CV , CE > collapsed = graph_factory . get ( ) ; for ( Set < V > set : partitioning . getVertexPartitions ( ) ) { CV cv = vertex_factory . get ( ) ; collapsed . addVertex ( vertex_factory . get ( ) ) ; set_collapsedv . put ( set , cv ) ; } for ( E e : original . getEdges ( ) ) { Collection < V > incident = original . getIncidentVertices ( e ) ; Collection < CV > collapsed_vertices = new HashSet < CV > ( ) ; Map < V , Set < V > > vertex_partitions = partitioning . getVertexToPartitionMap ( ) ; for ( V v : incident ) collapsed_vertices . add ( set_collapsedv . get ( vertex_partitions . get ( v ) ) ) ; if ( collapsed_vertices . size ( ) > 1 ) { CE ce = edge_factory . get ( ) ; collapsed . addEdge ( ce , collapsed_vertices ) ; } } return collapsed ; }
creates a new graph whose vertices correspond to the partitions of the supplied graph .
