int test_graph_from_leda_tutorial() { /* Test graph from the LEDA tutorial: * http://www.leda-tutorial.org/en/unofficial/ch05s03s05.html */ igraph_t graph; igraph_vector_bool_t types; igraph_vector_long_t matching; igraph_integer_t matching_size; igraph_bool_t is_matching; int i; igraph_small(&graph, 0, 0, 0, 8, 0, 12, 0, 14, 1, 9, 1, 10, 1, 13, 2, 8, 2, 9, 3, 10, 3, 11, 3, 13, 4, 9, 4, 14, 5, 14, 6, 9, 6, 14, 7, 8, 7, 12, 7, 14 , -1); igraph_vector_bool_init(&types, 15); for (i = 0; i < 15; i++) VECTOR(types)[i] = (i >= 8); igraph_vector_long_init(&matching, 0); igraph_i_maximum_bipartite_matching_unweighted(&graph, &types, &matching_size, &matching); if (matching_size != 6) { printf("matching_size is %ld, expected: 6\n", (long)matching_size); return 1; } igraph_is_maximal_matching(&graph, &types, &matching, &is_matching); if (!is_matching) { printf("not a matching: "); igraph_vector_long_print(&matching); return 3; } else igraph_vector_long_print(&matching); igraph_vector_long_destroy(&matching); igraph_vector_bool_destroy(&types); igraph_destroy(&graph); return 0; }
QList<int> MWBM::run(QList<int> input_weights, int numberOfLeft, int numberOfRight, bool &isMatched) { igraph_t graph; igraph_vector_bool_t types; igraph_vector_long_t matching; igraph_vector_t weights; igraph_integer_t matching_size; igraph_real_t matching_weight; igraph_bool_t is_matching; igraph_vector_t v; int i; QList<int> out; igraph_real_t weight_array[input_weights.size()]; for(int j=0;j<input_weights.size();j++) { weight_array[j] = input_weights.at(j); }; QList<int> edges_list; for(int j=0;j<numberOfLeft;j++) { for(int k=numberOfLeft;k<numberOfRight+numberOfLeft;k++) { edges_list.append(j); edges_list.append(k); } } igraph_real_t edges[edges_list.size()]; for(int j=0;j<edges_list.size();j++) { edges[j] = edges_list.at(j); } igraph_vector_view(&v, edges, sizeof(edges)/sizeof(double)); igraph_create(&graph, &v, 0, IGRAPH_DIRECTED); igraph_vector_bool_init(&types, numberOfLeft+numberOfRight); for (i = 0; i < numberOfLeft+numberOfRight; i++) VECTOR(types)[i] = (i >= numberOfLeft); igraph_vector_long_init(&matching, 0); igraph_vector_init_copy(&weights, weight_array, sizeof(weight_array) / sizeof(weight_array[0])); igraph_maximum_bipartite_matching(&graph, &types, &matching_size, &matching_weight, &matching, &weights,DBL_EPSILON); igraph_is_maximal_matching(&graph, &types, &matching, &is_matching); if (!is_matching) { isMatched = false; } else { isMatched=true; } for(int j=0;j<numberOfLeft*2;j++) out.append(VECTOR(matching)[j]); igraph_vector_destroy(&weights); igraph_vector_long_destroy(&matching); igraph_vector_bool_destroy(&types); igraph_destroy(&graph); return out; }