n-Dimensional Fast Methods  0.7
 All Classes Functions Variables Typedefs Pages
fm2star.hpp
1 
32 #ifndef FM2STAR_HPP_
33 #define FM2STAR_HPP_
34 
35 #include <iostream>
36 #include <cmath>
37 #include <algorithm>
38 #include <numeric>
39 #include <fstream>
40 #include <array>
41 #include <limits>
42 
43 #include <fast_methods/ndgridmap/fmcell.h>
44 #include <fast_methods/fm/fmm.hpp>
45 #include <fast_methods/fm2/fm2.hpp>
46 #include <fast_methods/gradientdescent/gradientdescent.hpp>
47 
49 // template < class grid_t, class solver_t = FMM<grid_t> > class FM2Star : public FM2<grid_t> {
50 
51 template < class grid_t, class heap_t = FMDaryHeap<FMCell> > class FM2Star : public FM2<grid_t, heap_t> {
52 
54  typedef std::vector< std::array<double, grid_t::getNDims()> > path_t;
55 
58 
59  public:
61  FM2Star
62  (HeurStrategy heurStrategy = TIME, double maxDistance = -1) : FM2Base("FM2*", maxDistance), heurStrategy_(heurStrategy) { }
63 
65  FM2Star
66  (const char * name, HeurStrategy heurStrategy = TIME, double maxDistance = -1) : FM2Base(name, maxDistance), heurStrategy_(heurStrategy) { }
67 
69  virtual void setInitialAndGoalPoints
70  (const std::vector<unsigned int> & init_points, unsigned int goal_idx) {
71  FM2Base::setInitialAndGoalPoints(init_points, goal_idx);
72  solver_->precomputeDistances();
73  }
74 
76  virtual void setup
77  () {
79  if(int(goal_idx_) == -1)
80  {
81  console::error("A goal point has to be set for FM2-based solvers.");
82  exit(1);
83  }
84  }
85 
87  virtual void computeInternal
88  () {
89  if (!setup_)
90  setup();
91 
93 
94  // Reset time counter so that time_ returns the time of the second wave.
95  start_ = std::chrono::steady_clock::now();
96 
97  // According to the theoretical basis the wave is expanded from the goal point to the initial point.
98  std::vector <unsigned int> wave_init;
99  wave_init.push_back(goal_idx_);
100  unsigned int wave_goal = init_points_[0];
101 
102  solver_->setInitialAndGoalPoints(wave_init, wave_goal);
103  solver_->setHeuristics(heurStrategy_);
104  solver_->compute();
105  // Restore the actual grid status.
106  grid_->setClean(false);
107  }
108 
109  protected:
110  using FM2Base::grid_;
111  using FM2Base::init_points_;
112  using FM2Base::goal_idx_;
113  using FM2Base::solver_;
114  using FM2Base::setup;
115  using FM2Base::setup_;
116  using FM2Base::start_;
118  using FM2Base::maxDistance_;
119 
121  HeurStrategy heurStrategy_;
122 };
123 
124 #endif /* FM2STAR_HPP_*/
virtual void setInitialAndGoalPoints(const std::vector< unsigned int > &init_points, unsigned int goal_idx)
Overloaded from FM2. In this case the precomputeDistances() method is called.
Definition: fm2star.hpp:70
FMM< grid_t, heap_t > * solver_
Underlying FMM-based solver.
Definition: fm2.hpp:200
HeurStrategy heurStrategy_
Stores the heuristic strategy to be used.
Definition: fm2star.hpp:121
static void error(const std::string &val)
void computeVelocitiesMap()
Computes the velocities map of the FM2 algorithm. If maxDistance_ != -1 then the map is saturated to ...
Definition: fm2.hpp:118
FM2< grid_t, heap_t > FM2Base
Shorthand of the base clase.
Definition: fm2star.hpp:57
Implements the Fast Marching Square Star (FM2*) planning algorithm.
Definition: fm2star.hpp:51
grid_t * grid_
Grid container.
Definition: solver.hpp:219
double maxDistance_
Distance value to saturate the first potential.
Definition: fm2.hpp:203
virtual void setInitialAndGoalPoints(const std::vector< unsigned int > &init_points, unsigned int goal_idx)
Sets the initial and goal points by the indices of the grid.
Definition: solver.hpp:58
std::vector< std::array< double, grid_t::getNDims()> > path_t
Path type encapsulation.
Definition: fm2star.hpp:54
std::vector< unsigned int > init_points_
Initial index.
Definition: solver.hpp:228
virtual void computeInternal()
Implements the actual FM2 method.
Definition: fm2star.hpp:88
virtual void setup()
Sets up the solver to check whether is ready to run.
Definition: fm2star.hpp:77
bool setup_
Setup status.
Definition: solver.hpp:225
virtual void setup()
Sets up the solver to check whether is ready to run.
Definition: fm2.hpp:79
std::chrono::time_point< std::chrono::steady_clock > start_
Time measurement variables.
Definition: solver.hpp:234
Implements the Fast Marching Square (FM2) planning algorithm.
Definition: fm2.hpp:49
unsigned int goal_idx_
Goal index.
Definition: solver.hpp:231
FM2Star(HeurStrategy heurStrategy=TIME, double maxDistance=-1)
maxDistance sets the velocities map saturation distance in real units (before normalization).
Definition: fm2star.hpp:62