summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbmp.cpp23
1 files 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<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++) {