43 #include <fast_methods/fm/fmm.hpp>
44 #include <fast_methods/gradientdescent/gradientdescent.hpp>
49 template <
class gr
id_t,
class heap_t = FMDaryHeap<FMCell> >
class FM2 :
public Solver<grid_t> {
53 typedef std::vector< std::array<double, grid_t::getNDims()> >
path_t;
83 console::error(
"FM2-based solvers currently allow only 1 initial point.");
88 console::error(
"Map has no obstacles. FM2-based solver is not running.");
102 start_ = std::chrono::steady_clock::now();
105 std::vector <unsigned int> wave_init;
109 solver_->setInitialAndGoalPoints(wave_init, wave_goal);
112 grid_->setClean(
false);
120 grid_->setClean(
true);
124 start_ = std::chrono::steady_clock::now();
126 double maxValue =
grid_->getMaxValue();
127 double maxVelocity = 0;
132 for (
unsigned int i = 0; i <
grid_->size(); ++i) {
133 double vel =
grid_->getCell(i).getValue() / maxValue;
136 if (vel < maxVelocity)
137 grid_->getCell(i).setVelocity(vel / maxVelocity);
139 grid_->getCell(i).setVelocity(1);
141 grid_->getCell(i).setVelocity(vel);
144 grid_->getCell(i).setValue(std::numeric_limits<double>::infinity());
145 grid_->getCell(i).setState(FMState::OPEN);
146 grid_->setClean(
true);
148 end_ = std::chrono::steady_clock::now();
149 time_vels_ += std::chrono::duration_cast<std::chrono::milliseconds>(end_-
start_).count();
161 (
path_t * p, std::vector <double> * path_velocity,
double step = 1) {
FMM< grid_t, heap_t > * solver_
Underlying FMM-based solver.
virtual void setEnvironment(grid_t *g)
Sets and cleans the grid in which operations will be performed.
virtual void setup()
Checks that the solver is ready to run. Sets the grid unclean.
virtual void computeInternal()
Implements the actual FM2 method.
virtual void reset()
Clears temporal data, so it is ready to run again.
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 ...
Implements gradient descent to be used together with nDGridMap and FMCell or derived types...
virtual void setEnvironment(grid_t *g)
Sets the environment to run the solver and sets the sources for the velocities map computation...
virtual double getTimeVelocities() const
Returns velocities map computation time.
grid_t * grid_
Grid container.
virtual void computePath(path_t *p, std::vector< double > *path_velocity, double step=1)
Encapsulates the path extraction.
double maxDistance_
Distance value to saturate the first potential.
std::vector< unsigned int > init_points_
Initial index.
virtual void clear()
Clears the solver, it is not recommended to be used out of the destructor.
std::vector< unsigned int > fm2_sources_
Wave propagation sources for the Fast Marching Square velocities map computation. ...
Abstract class that serves as interface for the actual solvers implemented. It requires (at least) th...
static void apply(grid_t &grid, unsigned int &idx, Path &path, std::vector< double > &path_velocity, double step=1)
Computes the path over grid from idx to a minimum and extracts the velocity in every point...
virtual void setup()
Sets up the solver to check whether is ready to run.
std::chrono::time_point< std::chrono::steady_clock > start_
Time measurement variables.
std::vector< std::array< double, grid_t::getNDims()> > path_t
Path type encapsulation.
Implements the Fast Marching Square (FM2) planning algorithm.
unsigned int goal_idx_
Goal index.
double time_vels_
Time elapsed in the velocities map computation.
Implements the Fast Marching Method (FMM).
FM2(double maxDistance=-1)
maxDistance sets the velocities map saturation distance in real units (before normalization).
virtual void clear()
Clears the solver, it is not recommended to be used out of the destructor.
virtual void reset()
Clears temporal data, so it is ready to run again.