From 93012fb0f56a2c79f6131a09769a6278526d5dbf Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 14 Sep 2022 11:05:21 +0200 Subject: Readded threshold-based stopping conditions. --- rbmp.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/rbmp.cpp b/rbmp.cpp index 5ec8300..3c8833a 100644 --- a/rbmp.cpp +++ b/rbmp.cpp @@ -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::infinity(); @@ -101,22 +104,32 @@ public: } } + double minBelief = std::numeric_limits::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++) { -- cgit v1.2.3-70-g09d2