]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Add not better counter to template with reset
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 10 Sep 2021 10:43:21 +0000 (12:43 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 10 Sep 2021 14:44:31 +0000 (16:44 +0200)
Not better counter counts how many times the solution after reset was
NOT better. The counter is reset when the improvement was significant,
currently 25 %. The algorithm is finished when there is number of
consecutive NOT better results, the current threshold is 5 results.

src/template-with-reset.cc

index 75a177672be8e175e8551b3a54317cbc7195db67..3060190f57fde703bb686b5663d4c8dc0bca8e15 100644 (file)
@@ -75,6 +75,7 @@ int main()
        unsigned int icnt = 0;
        unsigned int rcnt = 0;
        unsigned int bcnt = 0;
+       unsigned int ncnt = 0; // not better counter
        Json::Value best_path;
        Json::Value pj;
        double cost = 0.0;
@@ -87,11 +88,19 @@ int main()
                        double gc = pj["goal_cc"].asDouble();
                        assert(gc > 0.0);
                        if (cost == 0.0 || gc < cost) {
+                               if (gc < 0.75 * cost) {
+                                       ncnt = 0;
+                               }
                                best_path = pj["path"];
                                cost = gc;
                                bcnt += 1;
+                       } else {
+                               ncnt++;
                        }
                }
+               if (ncnt > 5) {
+                       break;
+               }
                p.reset();
                rcnt += 1;
        }