summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2022-09-30 14:33:51 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2022-09-30 14:33:51 +0200
commit1b72f7ac0adb1b2ed007ad9cfaf4e7092679e4fa (patch)
tree0beb2ec8c37d4ee524acda32ab78f662b373a2ab
parentaee1e277d32878055680f1a20708c171f17d3d3d (diff)
downloadcode-1b72f7ac0adb1b2ed007ad9cfaf4e7092679e4fa.tar.gz
code-1b72f7ac0adb1b2ed007ad9cfaf4e7092679e4fa.tar.bz2
code-1b72f7ac0adb1b2ed007ad9cfaf4e7092679e4fa.zip
Added routine to try perturbations until a large one is found.
-rw-r--r--rbmp.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/rbmp.cpp b/rbmp.cpp
index e677a11..8ddc591 100644
--- a/rbmp.cpp
+++ b/rbmp.cpp
@@ -132,22 +132,41 @@ int main(int argc, char* argv[]) {
matching[i] = edgeMatched(pm, G.edges[i]);
}
- 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);
- }
+ while (true) {
+ unsigned eFlip = r.variate<unsigned, std::uniform_int_distribution>(0, G.edges.size() - 1);
- pm.StartUpdate();
- pm.UpdateCost(eFlip, 1e10);
- pm.FinishUpdate();
+ while (!matching[eFlip]) {
+ eFlip = r.variate<unsigned, std::uniform_int_distribution>(0, G.edges.size() - 1);
+ }
- pm.Solve();
+ 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();
+ }
+ }
- unsigned m = 0;
for (unsigned i = 0; i < G.edges.size(); i++) {
if (!matching[i] && edgeMatched(pm, G.edges[i])) {
- m++;
std::cout
<< G.edges[i].halfedges[0].getTail().coordinate[0] << " "
<< G.edges[i].halfedges[0].getTail().coordinate[1] << " "
@@ -156,7 +175,5 @@ int main(int argc, char* argv[]) {
}
}
- std::cerr << "Size of excitation: " << m << std::endl;
-
return 0;
}