// put all clusterGraph vertices and edges into the new Graph
for(Object v : cluster) {
graph.addVertex(v);
for(Object edge : clusterGraph.getIncidentEdges(v)) {
Pair endpoints = clusterGraph.getEndpoints(edge);
graph.addEdge(edge, endpoints.getFirst(), endpoints.getSecond(), clusterGraph.getEdgeType(edge));
}
}
// add all the vertices from the current graph except for
// the cluster we are expanding
for(Object v : inGraph.getVertices()) {
if(v.equals(clusterGraph) == false) {
graph.addVertex(v);
}
}
// now that all vertices have been added, add the edges,
// ensuring that no edge contains a vertex that has not
// already been added
for(Object v : inGraph.getVertices()) {
if(v.equals(clusterGraph) == false) {
for(Object edge : inGraph.getIncidentEdges(v)) {
Pair endpoints = inGraph.getEndpoints(edge);
Object v1 = endpoints.getFirst();
Object v2 = endpoints.getSecond();
if(cluster.containsAll(endpoints) == false) {
if(clusterGraph.equals(v1)) {
// i need a new v1
Object originalV1 = originalGraph.getEndpoints(edge).getFirst();
Object newV1 = findVertex(graph, originalV1);