Ejemplo n.º 1
0
int XC::ParallelNumberer::mergeSubGraph(Graph &theGraph, Graph &theSubGraph, ID &vertexTags, ID &vertexRefs, ID &theSubdomainMap)
{  
  // for each vertex in the SubGraph we see if a vertex exists in the XC::Graph which has the same
  // reference tag (Reference tag in the XC::AnalysisModel graph is the node tag) .. if so this will be 
  // the new_ vertex tag for SubGraph vertex in new_ graph, otherwise we assign it some new_ vertex tag,
  // create a vertex for this new_ vertex tag & add it to the graph

  Vertex *subVertexPtr;
  VertexIter &theSubGraphIter1= theSubGraph.getVertices();
  int count =0;
  int numVertex= theGraph.getNumVertex();
  int numVertexSub= theSubGraph.getNumVertex();

  while ((subVertexPtr= theSubGraphIter1()) != 0) {
    int vertexTagSub= subVertexPtr->getTag();
    int vertexTagRef= subVertexPtr->getRef();
    int loc= vertexRefs.getLocation(vertexTagRef);

    int vertexTagMerged;
    if(loc < 0)
      {
        // if not already in, we will be creating a new_ vertex
        vertexTagMerged= theGraph.getFreeTag();
        vertexTags[numVertex]= vertexTagMerged;
        vertexRefs[numVertex]= vertexTagRef;
        Vertex newVertex(vertexTagMerged, vertexTagRef, subVertexPtr->getWeight(), subVertexPtr->getColor());

        theGraph.addVertex(newVertex);
        numVertex++;
      }
    else
      vertexTagMerged= vertexTags[loc];

    // use the subgraphs XC::ID to hold the mapping of vertex numbers between merged and original
    theSubdomainMap[count]= vertexTagSub;
    theSubdomainMap[count+numVertexSub]= vertexTagMerged;
    count++;
  }

    // for each vertex in subgraph, we add it's adjacenecy into the merged graph
    VertexIter &theSubGraphIter2= theSubGraph.getVertices();
    while ((subVertexPtr= theSubGraphIter2()) != 0)
      {
        const int vertexTagSub= subVertexPtr->getTag();
        const int loc= theSubdomainMap.getLocation(vertexTagSub);
        const int vertexTagMerged= theSubdomainMap[loc+numVertexSub];

        const std::set<int> &adjacency= subVertexPtr->getAdjacency();

        for(std::set<int>::const_iterator i=adjacency.begin(); i!=adjacency.end(); i++)
          {
            const int vertexTagSubAdjacent= *i;
            const int loc= theSubdomainMap.getLocation(vertexTagSubAdjacent);
            const int vertexTagMergedAdjacent= theSubdomainMap[loc+numVertexSub];      
            theGraph.addEdge(vertexTagMerged, vertexTagMergedAdjacent);
          }
      }


  return 0;
}