From b282229be03a242d09a7c0c6315a823aa1188f42 Mon Sep 17 00:00:00 2001 From: Jiri Vlasak Date: Fri, 10 Sep 2021 12:43:21 +0200 Subject: [PATCH] Add not better counter to template with reset 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/template-with-reset.cc b/src/template-with-reset.cc index 75a1776..3060190 100644 --- a/src/template-with-reset.cc +++ b/src/template-with-reset.cc @@ -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; } -- 2.39.2