00001 00024 #ifndef HEM_H_ 00025 #define HEM_H_ 00026 00027 class HEMMatcher{ 00028 private: 00029 int maxVertexWeight; 00030 GGraph* graph; 00031 GGraph* coarseGraph; 00032 MetisGraph* metisGraph; 00033 public: 00034 HEMMatcher(MetisGraph* metisGraph, GGraph* coarseGraph, int maxVertexWeight) { 00035 this->coarseGraph=coarseGraph; 00036 this->metisGraph = metisGraph; 00037 this->graph=metisGraph->getGraph(); 00038 this->maxVertexWeight=maxVertexWeight; 00039 } 00040 /* 00041 void match(GNode node) { 00042 MetisNode& nodeData = node.getData(Galois::CHECK_CONFLICT); 00043 if (metisGraph->isMatched(nodeData.getNodeId())) { 00044 return; 00045 } 00046 GNode matchNode = node; 00047 int maxwgt = -1; 00048 for (GGraph::neighbor_iterator jj = graph->neighbor_begin(node, Galois::CHECK_CONFLICT), eejj = graph->neighbor_end(node, Galois::CHECK_CONFLICT); jj != eejj; ++jj) { 00049 GNode neighbor = *jj; 00050 MetisNode& neighMNode = neighbor.getData(Galois::NONE); 00051 int edgeData = graph->getEdgeData(node, jj, Galois::NONE); 00052 if (!metisGraph->isMatched(neighMNode.getNodeId()) && maxwgt < edgeData 00053 && nodeData.getWeight() + neighMNode.getWeight() <= maxVertexWeight) { 00054 maxwgt = edgeData; 00055 matchNode = neighbor; 00056 } 00057 } 00058 00059 MetisNode& matchNodeData = matchNode.getData(Galois::NONE); 00060 // nodeData.setMatch(matchNode); 00061 // maxNodeData.setMatch(node); 00062 metisGraph->setMatch(nodeData.getNodeId(), matchNode); 00063 00064 int weight = nodeData.getWeight(); 00065 if (node != matchNode) { 00066 metisGraph->setMatch(matchNodeData.getNodeId(), node); 00067 weight += matchNodeData.getWeight(); 00068 } 00069 00070 <<<<<<< .mine 00071 // GNode newNode = coarseGraph->createNode(MetisNode(weight)); 00072 // coarseGraph->addNode(newNode, Galois::Graph::NONE); 00073 // metisGraph->setCoarseGraphMap(nodeData.getNodeId(), newNode); 00074 // if(matchNode!=node){ 00075 // metisGraph->setCoarseGraphMap(matchNodeData.getNodeId(), newNode); 00076 // } 00077 ======= 00078 GNode newNode = coarseGraph->createNode(MetisNode(weight)); 00079 coarseGraph->addNode(newNode, Galois::NONE); 00080 metisGraph->setCoarseGraphMap(nodeData.getNodeId(), newNode); 00081 if(matchNode!=node){ 00082 metisGraph->setCoarseGraphMap(matchNodeData.getNodeId(), newNode); 00083 } 00084 >>>>>>> .r7421 00085 } 00086 00087 */ 00088 void match(GNode node) { 00089 MetisNode& nodeData = node.getData(Galois::NONE); 00090 if (metisGraph->isMatched(nodeData.getNodeId())) { 00091 return; 00092 } 00093 GNode matchNode; 00094 while(true){ 00095 matchNode = node; 00096 int maxwgt = -1; 00097 for (GGraph::neighbor_iterator jj = graph->neighbor_begin(node, Galois::NONE), eejj = graph->neighbor_end(node, Galois::NONE); jj != eejj; ++jj) { 00098 GNode neighbor = *jj; 00099 MetisNode& neighMNode = neighbor.getData(Galois::NONE); 00100 int edgeData = graph->getEdgeData(node, jj, Galois::NONE); 00101 if (!metisGraph->isMatched(neighMNode.getNodeId()) && maxwgt < edgeData 00102 && nodeData.getWeight() + neighMNode.getWeight() <= maxVertexWeight) { 00103 maxwgt = edgeData; 00104 matchNode = neighbor; 00105 } 00106 } 00107 00108 MetisNode& matchNodeData = matchNode.getData(Galois::CHECK_CONFLICT); 00109 if(node == matchNode || !metisGraph->isMatched(matchNodeData.getNodeId())){ 00110 // cout<<(node==matchNode)<<endl; 00111 break; 00112 } 00113 } 00114 node.getData(Galois::CHECK_CONFLICT); 00115 if(metisGraph->isMatched(nodeData.getNodeId())){ 00116 return; 00117 } 00118 00119 metisGraph->setMatch(nodeData.getNodeId(), matchNode); 00120 MetisNode& matchNodeData = matchNode.getData(Galois::NONE); 00121 int weight = nodeData.getWeight(); 00122 if (node != matchNode) { 00123 metisGraph->setMatch(matchNodeData.getNodeId(), node); 00124 weight += matchNodeData.getWeight(); 00125 } 00126 // GNode newNode = coarseGraph->createNode(MetisNode(weight)); 00127 // coarseGraph->addNode(newNode, Galois::Graph::NONE); 00128 // metisGraph->setCoarseGraphMap(nodeData.getNodeId(), newNode); 00129 // if(matchNode!=node){ 00130 // metisGraph->setCoarseGraphMap(matchNodeData.getNodeId(), newNode); 00131 // } 00132 } 00133 00134 }; 00135 00136 #endif /* HEM_H_ */