diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-09-14 11:05:21 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-09-14 11:05:21 +0200 |
commit | 93012fb0f56a2c79f6131a09769a6278526d5dbf (patch) | |
tree | 4b69e7a1a053235421a69880cd526e14371fd48a | |
parent | 5f2eb218e6b91bb2556ed79eb530b1298b423d99 (diff) | |
download | code-93012fb0f56a2c79f6131a09769a6278526d5dbf.tar.gz code-93012fb0f56a2c79f6131a09769a6278526d5dbf.tar.bz2 code-93012fb0f56a2c79f6131a09769a6278526d5dbf.zip |
Readded threshold-based stopping conditions.
-rw-r--r-- | rbmp.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -63,8 +63,11 @@ public: red.addEdge(halfedges[0]); blue.addEdge(halfedges[1]); } + double belief() const { + return halfedges[0].X + halfedges[1].X; + } bool active() const { - return halfedges[0].X + halfedges[1].X >= 0; + return belief() >= 0; } }; @@ -89,7 +92,7 @@ public: } } - void propagateBeliefs() { + double propagateBeliefs() { for (Edge& e : edges) { for (HalfEdge& h : e.halfedges) { h.X = std::numeric_limits<double>::infinity(); @@ -101,22 +104,32 @@ public: } } + double minBelief = std::numeric_limits<double>::infinity(); for (Edge& e : edges) { + minBelief = std::min(std::abs(e.belief()), minBelief); for (HalfEdge& he : e.halfedges) { he.oldX = he.X; } } + + return minBelief; } }; int main() { unsigned n = 100; - unsigned steps = 1e5; + unsigned maxSteps = 1e7; + double beliefThreshold = 0.1; + Rng r; Graph G(n, r); - for (unsigned i = 0; i < steps; i++) { - G.propagateBeliefs(); + unsigned steps = 0; + double minBelief = 0; + + while (minBelief < beliefThreshold && steps < maxSteps) { + minBelief = G.propagateBeliefs(); + steps++; } for (unsigned i = 0; i < G.edges.size(); i++) { |