diff options
-rw-r--r-- | aztec.hpp | 6 | ||||
-rw-r--r-- | excitation.cpp | 16 | ||||
-rw-r--r-- | free_energy.cpp | 7 | ||||
-rw-r--r-- | hungarian.cpp | 45 | ||||
-rw-r--r-- | order.cpp | 2 | ||||
-rw-r--r-- | uniform.cpp | 2 |
6 files changed, 33 insertions, 45 deletions
@@ -1,8 +1,8 @@ -#include <vector> #include <stack> +#include <vector> -#include "randutils/randutils.hpp" #include "pcg-cpp/include/pcg_random.hpp" +#include "randutils/randutils.hpp" #include "blossom5-v2.05.src/PerfectMatching.h" @@ -102,7 +102,7 @@ public: Real logPartitionFunction = 0; for (unsigned i = 1; i <= n; i++) { -#pragma omp parallel for reduction(+:logPartitionFunction) +#pragma omp parallel for reduction(+ : logPartitionFunction) for (unsigned j = 0; j < pow(i, 2); j++) { auto [e1, e2, e3, e4] = face(i, j); diff --git a/excitation.cpp b/excitation.cpp index d09410b..8a2c409 100644 --- a/excitation.cpp +++ b/excitation.cpp @@ -28,11 +28,8 @@ int main(int argc, char* argv[]) { 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::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()); @@ -41,7 +38,6 @@ int main(int argc, char* argv[]) { matching[i] = edgeMatched(pm, G.edges[i]); } - while (true) { unsigned eFlip = r.variate<unsigned, std::uniform_int_distribution>(0, G.edges.size() - 1); @@ -76,11 +72,9 @@ int main(int argc, char* argv[]) { for (unsigned i = 0; i < G.edges.size(); i++) { if (!matching[i] && edgeMatched(pm, G.edges[i])) { - std::cout - << G.edges[i].tail->coordinate[0] << " " - << G.edges[i].tail->coordinate[1] << " " - << G.edges[i].head->coordinate[0] << " " - << G.edges[i].head->coordinate[1] << std::endl; + std::cout << G.edges[i].tail->coordinate[0] << " " << G.edges[i].tail->coordinate[1] << " " + << G.edges[i].head->coordinate[0] << " " << G.edges[i].head->coordinate[1] + << std::endl; } } diff --git a/free_energy.cpp b/free_energy.cpp index 148423f..5cfaae1 100644 --- a/free_energy.cpp +++ b/free_energy.cpp @@ -1,5 +1,5 @@ -#include <iostream> #include <iomanip> +#include <iostream> #include "aztec.hpp" @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) { Rng r; AztecDiamond a(n); - a.setWeights(r); + a.setWeights(r); for (Real T = T0; T <= T1; T += ΔT) { Real avgFreeEnergy = 0; @@ -46,7 +46,8 @@ int main(int argc, char* argv[]) { avgFreeEnergy += a.computeProbabilities(); } - std::cout << std::setprecision(20) << T << " " << - T * avgFreeEnergy / m / a.vertices.size() << std::endl; + std::cout << std::setprecision(20) << T << " " << -T * avgFreeEnergy / m / a.vertices.size() + << std::endl; } return 0; diff --git a/hungarian.cpp b/hungarian.cpp index b8cb7ab..8c01a78 100644 --- a/hungarian.cpp +++ b/hungarian.cpp @@ -1,14 +1,14 @@ -#include <iostream> #include <cmath> #include <functional> -#include <random> -#include <vector> +#include <iostream> #include <limits> #include <queue> +#include <random> #include <stack> +#include <vector> -#include "randutils/randutils.hpp" #include "pcg-cpp/include/pcg_random.hpp" +#include "randutils/randutils.hpp" using Rng = randutils::random_generator<pcg32>; @@ -22,11 +22,9 @@ public: std::vector<std::reference_wrapper<Edge>> neighbors; std::array<unsigned, 2> coordinate; - Vertex() : y(0), inZ(false) {}; + Vertex() : y(0), inZ(false){}; - void addEdge(Edge& e) { - neighbors.push_back(e); - } + void addEdge(Edge& e) { neighbors.push_back(e); } bool inMatching() const; }; @@ -39,14 +37,14 @@ public: double weight; bool inPath; - Edge() : orientation(false) {}; + Edge() : orientation(false){}; void setVertices(Vertex& red, Vertex& blue) { s = &red; t = &blue; red.addEdge(*this); blue.addEdge(*this); } - Vertex& tail() { + Vertex& tail() { if (orientation) { return *t; } else { @@ -74,9 +72,7 @@ public: return *t; } } - bool isTight() const { - return std::abs(s->y + t->y - weight) < 1e-13; - } + bool isTight() const { return std::abs(s->y + t->y - weight) < 1e-13; } }; bool Vertex::inMatching() const { @@ -112,11 +108,11 @@ public: void hungarian() { std::queue<std::reference_wrapper<Vertex>> q; - for (Vertex &v : T) { + for (Vertex& v : T) { v.inZ = false; } - for (Vertex &v : S) { + for (Vertex& v : S) { v.inZ = false; if (!v.inMatching()) { @@ -141,7 +137,9 @@ public: for (Vertex& v : T) { if (v.inZ && !v.inMatching()) { - std::stack<std::tuple<std::vector<std::reference_wrapper<Edge>>::iterator, std::vector<std::reference_wrapper<Edge>>::iterator, unsigned>> path; + std::stack<std::tuple<std::vector<std::reference_wrapper<Edge>>::iterator, + std::vector<std::reference_wrapper<Edge>>::iterator, unsigned>> + path; for (Edge& e : E) { e.inPath = false; @@ -167,7 +165,7 @@ public: if (!e.tail().inMatching()) { break; } else { - e.inPath= true; + e.inPath = true; path.push({e.tail().neighbors.begin(), e.tail().neighbors.end(), e.tail().index}); } } else { @@ -209,25 +207,23 @@ public: v.y -= Δ; } } - } } bool isPerfect() const { for (const Vertex& v : S) { if (!v.inMatching()) { - return false; + return false; } } for (const Vertex& v : T) { if (!v.inMatching()) { - return false; + return false; } } return true; } - }; int main(int argc, char* argv[]) { @@ -265,11 +261,8 @@ int main(int argc, char* argv[]) { for (const Edge& e : G.E) { if (e.orientation) { - std::cout - << e.tail().coordinate[0] << " " - << e.tail().coordinate[1] << " " - << e.head().coordinate[0] << " " - << e.head().coordinate[1] << std::endl; + std::cout << e.tail().coordinate[0] << " " << e.tail().coordinate[1] << " " + << e.head().coordinate[0] << " " << e.head().coordinate[1] << std::endl; } } @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) { for (unsigned i = 0; i < G.edges.size(); i++) { const AztecDiamond::Edge& e = G.edges[i]; const AztecDiamond::Vertex& vt = *e.tail; - const AztecDiamond::Vertex& vh = *e.head; + const AztecDiamond::Vertex& vh = *e.head; data_x[vt.index] += avgProbabilities[i] * (vt.coordinate[0] - vh.coordinate[0]); data_y[vt.index] += avgProbabilities[i] * (vt.coordinate[1] - vh.coordinate[1]); data_x[vh.index] += avgProbabilities[i] * (vt.coordinate[0] - vh.coordinate[0]); diff --git a/uniform.cpp b/uniform.cpp index 6c8184c..1e8ae7d 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) { for (unsigned i = 0; i < a.edges.size(); i++) { const AztecDiamond::Edge& e = a.edges[i]; const AztecDiamond::Vertex& vt = *e.tail; - const AztecDiamond::Vertex& vh = *e.head; + const AztecDiamond::Vertex& vh = *e.head; data_x[vt.index] += avgProbabilities[i] * (vt.coordinate[0] - vh.coordinate[0]); data_y[vt.index] += avgProbabilities[i] * (vt.coordinate[1] - vh.coordinate[1]); data_x[vh.index] += avgProbabilities[i] * (vt.coordinate[0] - vh.coordinate[0]); |