]> rtime.felk.cvut.cz Git - hubacji1/rrts.git/commitdiff
Add cumulative cost function
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 26 Jul 2019 20:21:25 +0000 (22:21 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Sun, 28 Jul 2019 19:10:38 +0000 (21:10 +0200)
api/rrts.h
src/rrts.cc
ut/rrts.t.cc

index 2e7f53da46b9fd483edccfca7de43e50a72c6a77..427f6e1cd0968e2d6d4c50764bee53ce203626ae 100644 (file)
@@ -91,4 +91,10 @@ class RRTS {
                 RRTS();
 };
 
+/*! \brief Compute cumulative cost of RRT node.
+
+\param t RRT node to compute cumulative cost to.
+*/
+double cc(RRTNode &t);
+
 #endif /* RRTS_H */
index 3968da41fb18f4408473db28069351afb3f423b5..7ded4624d7d3a1e1f6b607ab497a2cfe3e33f93c 100644 (file)
@@ -151,3 +151,14 @@ RRTS::RRTS()
 {
         this->nodes().push_back(RRTNode()); // root
 }
+
+double cc(RRTNode &t)
+{
+        RRTNode *n = &t;
+        double cost = 0;
+        while (n != nullptr) {
+                cost += n->c();
+                n = n->p();
+        }
+        return cost;
+}
index a872cb0a1ab7de696eac0fa4072b6319988fe927..73b161a5a697f1a3caeee43b2eb35b10ce08fa46 100644 (file)
@@ -12,6 +12,7 @@ WVTEST_MAIN("RRT node basic tests")
 WVTEST_MAIN("RRT* basic tests")
 {
         RRTS rrts;
+        WVPASSEQ_DOUBLE(cc(rrts.nodes().front()), 0, 0.00001);
         WVPASSEQ(rrts.nodes().size(), 1);
         rrts.next();
         WVPASSEQ(rrts.nodes().size(), 2);