void EdmondMatching::solveEdmondMatching() {
    // they've already called addEdge() for all edges

    // interface with C library
    assert(graphSize < MAX);
    initGraph(graphSize);               //Since C++ arrays are 0..n-1 and input 1..n , subtractions 
    for (unsigned i=0; i<Edges.size(); i++){    //are made for better memory usage.
        //scanf(" %d %d",&a,&b);
        unsigned a = Edges.at(i).first;
        unsigned b = Edges.at(i).second;
        //printf("edge: %d %d\n",a,b);
        if (a!=b) {
            g[a-1][b-1]=g[b-1][a-1]=unmatched;
        }
    }

    findMaximumMatching(graphSize);

    for (unsigned i=0; i<graphSize; i++){
        for (unsigned j=i+1; j<graphSize; j++) {
            if (g[i][j]==matched) {
                Matches.push_back(EdgeType(i+1,j+1));
                //printf("match: %d %d\n",i+1,j+1);
            }
        }
    }

}
int EdmondMatching::main(){
    int n;
    n=readGraph();
    findMaximumMatching(n);
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++) if (g[i][j]==matched)
            printf("%d %d\n",i+1,j+1);
    }
    return 0;
}
Beispiel #3
0
 void verifyMatching(BipartiteGraph g, unsigned expectedSize)
 {
     Matching matching = findMaximumMatching(g);
     typedef boost::unordered_set<unsigned> VertexSet;
     VertexSet first;
     VertexSet second;
     for (auto elem : matching)
     {
         ASSERT_TRUE(first.insert(elem.first).second);
         ASSERT_TRUE(second.insert(elem.second).second);
         ASSERT_TRUE(g.edgeExists(elem));
     }
     ASSERT_EQ(expectedSize, matching.size());
 }
Beispiel #4
0
TYPED_TEST_P(BipartiteGraphTest, defaultConstructor)
{
    ASSERT_EQ(this->g.numOfVertices(), 0);
    ASSERT_EQ(this->g.numOfEdges(), 0);
    ASSERT_EQ(Matching(), findMaximumMatching(this->g));
}