#include #include #include #include "rbmp.hpp" int main(int argc, char* argv[]) { unsigned n = 100; unsigned m = 100; int opt; while ((opt = getopt(argc, argv, "n:m:")) != -1) { switch (opt) { case 'n': n = atoi(optarg); break; case 'm': m = atoi(optarg); break; default: exit(1); } } Rng r; Graph G(n, r); #pragma omp declare reduction(vec_int_plus : std::vector : \ std::transform(omp_out.begin(), omp_out.end(), omp_in.begin(), omp_out.begin(), std::plus())) \ initializer(omp_priv = decltype(omp_orig)(omp_orig.size())) std::vector data_x(G.vertices.size()); std::vector data_y(G.vertices.size()); std::string filename = "order_" + std::to_string(n) + ".dat"; std::ifstream input(filename); if (input.is_open()) { for (unsigned i = 0; i < G.vertices.size(); i++) { input >> data_x[i]; input >> data_y[i]; } input.close(); } #pragma omp parallel for reduction(vec_int_plus : data_x) reduction(vec_int_plus : data_y) for (unsigned i = 0; i < m; i++) { PerfectMatching pm(G.vertices.size(), G.edges.size()); for (const Edge& e : G.edges) { pm.AddEdge(e.halfedges[0].getHead().index, e.halfedges[0].getTail().index, r.variate(1)); } pm.options.verbose = false; pm.Solve(); for (unsigned i = 0; i < G.vertices.size() / 2; i++) { unsigned j = pm.GetMatch(i); data_x[i] += G.vertices[i].coordinate[0]; data_y[i] += G.vertices[i].coordinate[1]; data_x[i] -= G.vertices[j].coordinate[0]; data_y[i] -= G.vertices[j].coordinate[1]; data_x[j] += G.vertices[i].coordinate[0]; data_y[j] += G.vertices[i].coordinate[1]; data_x[j] -= G.vertices[j].coordinate[0]; data_y[j] -= G.vertices[j].coordinate[1]; } } std::ofstream output(filename); for (unsigned i = 0; i < G.vertices.size(); i++) { output << data_x[i] << " " << data_y[i] << std::endl; } output.close(); return 0; }