diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-10-04 12:37:14 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-10-04 12:37:14 +0200 |
commit | 352e1be1bf05de2ba75f93b8375ac52036c8203e (patch) | |
tree | 6248835124e372f75f36160547e6f58e37111318 /excitation.cpp | |
parent | 1b72f7ac0adb1b2ed007ad9cfaf4e7092679e4fa (diff) | |
download | code-352e1be1bf05de2ba75f93b8375ac52036c8203e.tar.gz code-352e1be1bf05de2ba75f93b8375ac52036c8203e.tar.bz2 code-352e1be1bf05de2ba75f93b8375ac52036c8203e.zip |
Refactored base code and added new utility to measure the order paremeter.
Diffstat (limited to 'excitation.cpp')
-rw-r--r-- | excitation.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/excitation.cpp b/excitation.cpp new file mode 100644 index 0000000..05cb8c6 --- /dev/null +++ b/excitation.cpp @@ -0,0 +1,94 @@ +#include <iostream> + +#include "rbmp.hpp" + +int main(int argc, char* argv[]) { + unsigned n = 100; + + int opt; + + while ((opt = getopt(argc, argv, "n:")) != -1) { + switch (opt) { + case 'n': + n = atoi(optarg); + break; + default: + exit(1); + } + } + + Rng r; + Graph G(n, r); + + 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, e.weight); + } + + pm.options.verbose = false; + pm.Solve(); + + std::cout << n << std::endl; + + for (unsigned i = 0; i < G.vertices.size() / 2; i++) { + unsigned j1 = pm.GetMatch(i); + + std::cout + << G.vertices[i].coordinate[0] << " " + << G.vertices[i].coordinate[1] << " " + << G.vertices[j1].coordinate[0] << " " + << G.vertices[j1].coordinate[1] << std::endl; + } + + std::vector<bool> matching(G.edges.size()); + + for (unsigned i = 0; i < G.edges.size(); i++) { + matching[i] = edgeMatched(pm, G.edges[i]); + } + + + while (true) { + unsigned eFlip = r.variate<unsigned, std::uniform_int_distribution>(0, G.edges.size() - 1); + + while (!matching[eFlip]) { + eFlip = r.variate<unsigned, std::uniform_int_distribution>(0, G.edges.size() - 1); + } + + pm.StartUpdate(); + pm.UpdateCost(eFlip, 1e10); + pm.FinishUpdate(); + + pm.Solve(); + + unsigned m = 0; + for (unsigned i = 0; i < G.edges.size(); i++) { + if (!matching[i] && edgeMatched(pm, G.edges[i])) { + m++; + } + } + + if (m > 4 * n) { + std::cerr << "Size of excitation: " << m << std::endl; + break; + } else { + pm.StartUpdate(); + pm.UpdateCost(eFlip, -1e10); + pm.FinishUpdate(); + + pm.Solve(); + } + } + + for (unsigned i = 0; i < G.edges.size(); i++) { + if (!matching[i] && edgeMatched(pm, G.edges[i])) { + std::cout + << G.edges[i].halfedges[0].getTail().coordinate[0] << " " + << G.edges[i].halfedges[0].getTail().coordinate[1] << " " + << G.edges[i].halfedges[0].getHead().coordinate[0] << " " + << G.edges[i].halfedges[0].getHead().coordinate[1] << std::endl; + } + } + + return 0; +} |