Skip to content

Commit e61d34d

Browse files
cwrx777mxgreyluca-della-vedova
authored
Add API to clear planner inner cache (#123)
* add API to clear planner inner cache Signed-off-by: Charly Wu <charlywu@medinno.com> * removed debug print Signed-off-by: Charly Wu <charlywu@medinno.com> * Revert whitespace changes Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai> * Revert more whitespace Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai> * Do not use exception for unimplemented method Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai> * Revert more whitespace changes Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai> --------- Signed-off-by: Charly Wu <charlywu@medinno.com> Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai> Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai> Co-authored-by: Michael X. Grey <mxgrey@intrinsic.ai> Co-authored-by: Luca Della Vedova <lucadv@intrinsic.ai>
1 parent d067489 commit e61d34d

File tree

9 files changed

+53
-7
lines changed

9 files changed

+53
-7
lines changed

rmf_traffic/include/rmf_traffic/agv/Planner.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ class Planner
618618
/// It is advisable to not clear the cache more than once per minute.
619619
void clear_differential_drive_cache() const;
620620

621+
void clear_inner_cache() const;
622+
621623
class Implementation;
622624
class Debug;
623625
private:

rmf_traffic/src/rmf_traffic/agv/Planner.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,12 @@ void Planner::clear_differential_drive_cache() const
10631063
_pimpl->interface->clear_cache();
10641064
}
10651065

1066+
//==============================================================================
1067+
void Planner::clear_inner_cache() const
1068+
{
1069+
_pimpl->interface->clear_inner_cache();
1070+
}
1071+
10661072
//==============================================================================
10671073
const Eigen::Vector3d& Plan::Waypoint::position() const
10681074
{

rmf_traffic/src/rmf_traffic/agv/internal_planning.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class Interface
131131

132132
virtual void clear_cache() const = 0;
133133

134+
virtual void clear_inner_cache() const = 0;
135+
134136
virtual ~Interface() = default;
135137
};
136138

rmf_traffic/src/rmf_traffic/agv/planning/DifferentialDriveHeuristic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ ConstForestSolutionPtr DifferentialDriveHeuristic::inner_heuristic(
707707
return _heuristic->get(start, finish);
708708
}
709709

710+
//==============================================================================
711+
void DifferentialDriveHeuristic::clear_inner_heuristic() const
712+
{
713+
_heuristic->clear_cache();
714+
}
715+
710716
//==============================================================================
711717
CacheManagerPtr<DifferentialDriveHeuristic>
712718
DifferentialDriveHeuristic::make_manager(

rmf_traffic/src/rmf_traffic/agv/planning/DifferentialDriveHeuristic.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class DifferentialDriveHeuristic : public Generator<DifferentialDriveMap>
5757
ConstForestSolutionPtr inner_heuristic(
5858
std::size_t start, std::size_t finish) const;
5959

60+
void clear_inner_heuristic() const;
61+
6062
static CacheManagerPtr<DifferentialDriveHeuristic> make_manager(
6163
std::shared_ptr<const Supergraph> graph,
6264
ConstChildHeuristicPtr child_heuristic);

rmf_traffic/src/rmf_traffic/agv/planning/DifferentialDrivePlanner.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,12 @@ void DifferentialDrivePlanner::clear_cache() const
29302930
_cache->get().clear();
29312931
}
29322932

2933+
//==============================================================================
2934+
void DifferentialDrivePlanner::clear_inner_cache() const
2935+
{
2936+
_cache->inner()->clear_inner_heuristic();
2937+
}
2938+
29332939
} // namespace planning
29342940
} // namespace agv
29352941
} // namespace rmf_traffic

rmf_traffic/src/rmf_traffic/agv/planning/DifferentialDrivePlanner.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class DifferentialDrivePlanner : public Interface
6464

6565
void clear_cache() const final;
6666

67+
void clear_inner_cache() const final;
68+
6769
std::optional<double> compute_heuristic(const Planner::Start& start) const;
6870

6971
private:

rmf_traffic/src/rmf_traffic/agv/planning/Tree.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,12 @@ class BidirectionalForest
242242

243243
std::size_t cache_size() const;
244244

245+
void clear_cache() const;
246+
245247
std::size_t heuristic_cache_size() const;
246248

249+
void clear_heuristic_cache() const;
250+
247251
~BidirectionalForest();
248252

249253
private:

rmf_traffic/src/rmf_traffic/agv/planning/impl_Tree.hpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,22 @@ std::optional<double> BidirectionalForest<T>::get_cost(
376376
template<typename T>
377377
std::size_t BidirectionalForest<T>::cache_size() const
378378
{
379-
SpinLock lock(_solutions_mutex);
380-
std::size_t count = 0;
381-
for (const auto& [_, goals] : _solutions)
382-
{
383-
count += goals.size();
384-
}
379+
SpinLock lock(_solutions_mutex);
380+
std::size_t count = 0;
381+
for (const auto& [_, goals] : _solutions)
382+
{
383+
count += goals.size();
384+
}
385385

386-
return count;
386+
return count;
387+
}
388+
389+
//==============================================================================
390+
template<typename T>
391+
void BidirectionalForest<T>::clear_cache() const
392+
{
393+
SpinLock lock(_solutions_mutex);
394+
_solutions.clear();
387395
}
388396

389397
//==============================================================================
@@ -393,6 +401,14 @@ std::size_t BidirectionalForest<T>::heuristic_cache_size() const
393401
return _heuristic_cache->net_size();
394402
}
395403

404+
//==============================================================================
405+
template<typename T>
406+
void BidirectionalForest<T>::clear_heuristic_cache() const
407+
{
408+
// TODO: This is not implemented yet, but there should not be any negative
409+
// impact on behavior by doing nothing here.
410+
}
411+
396412
//==============================================================================
397413
template<typename T>
398414
BidirectionalForest<T>::~BidirectionalForest()

0 commit comments

Comments
 (0)