| 362 | |
| 363 | |
| 364 | int |
| 365 | ParallelNumberer::mergeSubGraph(Graph &theGraph, Graph &theSubGraph, ID &vertexTags, ID &vertexRefs, ID &theSubdomainMap) |
| 366 | { |
| 367 | // for each vertex in the SubGraph we see if a vertex exists in the Graph which has the same |
| 368 | // reference tag (Reference tag in the AnalysisModel graph is the node tag) .. if so this will be |
| 369 | // the new vertex tag for SubGraph vertex in new graph, otherwise we assign it some new vertex tag, |
| 370 | // create a vertex for this new vertex tag & add it to the graph |
| 371 | |
| 372 | Vertex *subVertexPtr; |
| 373 | VertexIter &theSubGraphIter1 = theSubGraph.getVertices(); |
| 374 | int count =0; |
| 375 | int numVertex = theGraph.getNumVertex(); |
| 376 | int numVertexSub = theSubGraph.getNumVertex(); |
| 377 | |
| 378 | while ((subVertexPtr = theSubGraphIter1()) != 0) { |
| 379 | int vertexTagSub = subVertexPtr->getTag(); |
| 380 | int vertexTagRef = subVertexPtr->getRef(); |
| 381 | int loc = vertexRefs.getLocation(vertexTagRef); |
| 382 | |
| 383 | int vertexTagMerged; |
| 384 | if (loc < 0) { |
| 385 | // if not already in, we will be creating a new vertex |
| 386 | vertexTagMerged = theGraph.getFreeTag(); |
| 387 | vertexTags[numVertex] = vertexTagMerged; |
| 388 | vertexRefs[numVertex] = vertexTagRef; |
| 389 | Vertex *newVertex = new Vertex(vertexTagMerged, vertexTagRef, subVertexPtr->getWeight(), subVertexPtr->getColor()); |
| 390 | |
| 391 | theGraph.addVertex(newVertex); |
| 392 | numVertex++; |
| 393 | } else |
| 394 | vertexTagMerged = vertexTags[loc]; |
| 395 | |
| 396 | // use the subgraphs ID to hold the mapping of vertex numbers between merged and original |
| 397 | theSubdomainMap[count] = vertexTagSub; |
| 398 | theSubdomainMap[count+numVertexSub] = vertexTagMerged; |
| 399 | count++; |
| 400 | } |
| 401 | |
| 402 | // for each vertex in subgraph, we add it's adjacenecy into the merged graph |
| 403 | VertexIter &theSubGraphIter2 = theSubGraph.getVertices(); |
| 404 | while ((subVertexPtr = theSubGraphIter2()) != 0) { |
| 405 | int vertexTagSub = subVertexPtr->getTag(); |
| 406 | int loc = theSubdomainMap.getLocation(vertexTagSub); |
| 407 | int vertexTagMerged = theSubdomainMap[loc+numVertexSub]; |
| 408 | |
| 409 | const ID &adjacency = subVertexPtr->getAdjacency(); |
| 410 | |
| 411 | for (int i=0; i<adjacency.Size(); i++) { |
| 412 | int vertexTagSubAdjacent = adjacency(i); |
| 413 | int loc = theSubdomainMap.getLocation(vertexTagSubAdjacent); |
| 414 | int vertexTagMergedAdjacent = theSubdomainMap[loc+numVertexSub]; |
| 415 | theGraph.addEdge(vertexTagMerged, vertexTagMergedAdjacent); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | |
| 420 | return 0; |
| 421 | } |
no test coverage detected