Skip to content

Commit

Permalink
Reduce copies of grid
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysgoldstein committed Feb 6, 2024
1 parent 12e1a15 commit 21365bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
23 changes: 11 additions & 12 deletions include/central64/PathPlanner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PathPlanner

int NeighborhoodSize() const { return L; } ///< Get the neighborhood size.

const Grid2D<L>& Grid() const { return grid_; } ///< Obtain a const reference to the grid.
const Grid2D<L>& Grid() const { return searchPtr_->Grid(); } ///< Obtain a const reference to the grid.
AbstractSearch<L>& Search() { return *searchPtr_; } ///< Obtain a reference to the path search object.
AbstractSmoothing<L>& Smoothing() { return *smoothingPtr_; } ///< Obtain a reference to the path smoothing object.

Expand All @@ -72,7 +72,6 @@ class PathPlanner
PathPlanner(const PathPlanner&) = delete;
PathPlanner& operator=(const PathPlanner&) = delete;

Grid2D<L> grid_;
std::unique_ptr<AbstractSearch<L>> searchPtr_{};
std::unique_ptr<AbstractSmoothing<L>> smoothingPtr_{};
bool centralize_;
Expand All @@ -86,21 +85,21 @@ PathPlanner<L>::PathPlanner(const std::vector<std::vector<bool>>& inputCells,
SmoothingMethod smoothingMethod,
bool centralize,
bool fromSource)
: grid_{ inputCells, alignment }
, centralize_{ centralize }
: centralize_{ centralize }
, fromSource_{ fromSource }
{
Grid2D<L> grid{ inputCells, alignment };
switch (searchMethod) {
case SearchMethod::AStar: searchPtr_ = std::make_unique< AStarSearch<L>>(grid_); break;
case SearchMethod::JumpPoint: searchPtr_ = std::make_unique< JumpPointSearch<L>>(grid_); break;
case SearchMethod::BoundedJumpPoint: searchPtr_ = std::make_unique< JumpPointSearch<L>>(grid_, PathCost(8)); break;
case SearchMethod::MixedAStar: searchPtr_ = std::make_unique< MixedAStarSearch<L>>(grid_); break;
case SearchMethod::MixedJumpPoint: searchPtr_ = std::make_unique<MixedJumpPointSearch<L>>(grid_); break;
case SearchMethod::AStar: searchPtr_ = std::make_unique< AStarSearch<L>>(grid); break;
case SearchMethod::JumpPoint: searchPtr_ = std::make_unique< JumpPointSearch<L>>(grid); break;
case SearchMethod::BoundedJumpPoint: searchPtr_ = std::make_unique< JumpPointSearch<L>>(grid, PathCost(8)); break;
case SearchMethod::MixedAStar: searchPtr_ = std::make_unique< MixedAStarSearch<L>>(grid); break;
case SearchMethod::MixedJumpPoint: searchPtr_ = std::make_unique<MixedJumpPointSearch<L>>(grid); break;
}
switch (smoothingMethod) {
case SmoothingMethod::No: smoothingPtr_ = std::make_unique< NoSmoothing<L>>(grid_); break;
case SmoothingMethod::Greedy: smoothingPtr_ = std::make_unique< GreedySmoothing<L>>(grid_); break;
case SmoothingMethod::Tentpole: smoothingPtr_ = std::make_unique<TentpoleSmoothing<L>>(grid_); break;
case SmoothingMethod::No: smoothingPtr_ = std::make_unique< NoSmoothing<L>>(grid); break;
case SmoothingMethod::Greedy: smoothingPtr_ = std::make_unique< GreedySmoothing<L>>(grid); break;
case SmoothingMethod::Tentpole: smoothingPtr_ = std::make_unique<TentpoleSmoothing<L>>(grid); break;
}
assert(searchPtr_);
assert(smoothingPtr_);
Expand Down
4 changes: 2 additions & 2 deletions include/central64/search/AbstractSearch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ AbstractSearch<L>::AbstractSearch(const Grid2D<L>& grid)
, centralize_{ true }
, fromSource_{ true }
{
pathTreePtr_ = std::make_unique<PathTree<L>>(grid);
pathFlowPtr_ = std::make_unique<PathFlow<L>>(grid, *pathTreePtr_);
pathTreePtr_ = std::make_unique<PathTree<L>>(grid_);
pathFlowPtr_ = std::make_unique<PathFlow<L>>(grid_, *pathTreePtr_);
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion include/central64/search/PathTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PathTree

template <int L>
PathTree<L>::PathTree(const Grid2D<L>& grid)
: gridPtr_{&grid}
: gridPtr_{ &grid }
, nodes_{ grid.Dims() }
, currentSearchID_{ 0 }
, sourceCoords_{ InvalidCoords() }
Expand Down

0 comments on commit 21365bc

Please sign in to comment.