17 #ifndef BENCHMARKCFG_HPP_
18 #define BENCHMARKCFG_HPP_
21 #include <unordered_map>
24 #include <boost/program_options.hpp>
25 #include <boost/algorithm/string/case_conv.hpp>
27 #include <fast_methods/benchmark/benchmark.hpp>
28 #include <fast_methods/io/maploader.hpp>
30 #include <fast_methods/fm/fmm.hpp>
31 #include <fast_methods/fm/sfmm.hpp>
32 #include <fast_methods/fm/fmmstar.hpp>
33 #include <fast_methods/fm/sfmmstar.hpp>
34 #include <fast_methods/fm/fim.hpp>
35 #include <fast_methods/fm/gmm.hpp>
36 #include <fast_methods/fm/ufmm.hpp>
37 #include <fast_methods/fm/fsm.hpp>
38 #include <fast_methods/fm/lsm.hpp>
39 #include <fast_methods/fm/ddqm.hpp>
55 (
const char * filename) {
62 static const std::vector<std::string> knownSolvers = {
63 "fmm",
"fmmstar",
"fmmfib",
"fmmfibstar",
"sfmm",
"sfmmstar",
64 "gmm",
"fim",
"ufmm",
"fsm",
"lsm",
"ddqm"
67 std::fstream cfg(filename);
70 std::string error(
"Unable to open file: ");
76 path_ = boost::filesystem::absolute( boost::filesystem::path(filename) );
77 boost::filesystem::path name =
path_.filename();
78 name.replace_extension(
"");
80 boost::program_options::options_description desc;
82 (
"grid.file", boost::program_options::value<std::string>(),
"Path to load a velocities map from image.")
83 (
"grid.text", boost::program_options::value<std::string>(),
"Path to load a velocities map from a .grid file.")
84 (
"grid.ndims", boost::program_options::value<std::string>()->default_value(
"2"),
"Number of dimensions.")
85 (
"grid.cell", boost::program_options::value<std::string>()->default_value(
"FMCell"),
"Type of cell. FMCell by default.")
86 (
"grid.dimsize", boost::program_options::value<std::string>()->default_value(
"200,200"),
"Size of dimensions: N,M,O...")
87 (
"grid.leafsize", boost::program_options::value<std::string>()->default_value(
"1"),
"Leafsize (assuming cubic cells).")
88 (
"problem.start", boost::program_options::value<std::string>()->required(),
"Start point: s1,s2,s3...")
89 (
"problem.goal", boost::program_options::value<std::string>()->default_value(
"nan"),
"Goal point: g1,g2,g3... By default no goal point.")
90 (
"benchmark.name", boost::program_options::value<std::string>()->default_value(name.string()),
"Name of the benchmark.")
91 (
"benchmark.runs", boost::program_options::value<std::string>()->default_value(
"10"),
"Number of runs per solver.")
92 (
"benchmark.savegrid", boost::program_options::value<std::string>()->default_value(
"0"),
"Save grid values of each run.");
94 boost::program_options::variables_map vm;
95 boost::program_options::parsed_options po = boost::program_options::parse_config_file(cfg, desc,
true);
96 boost::program_options::store(po, vm);
97 boost::program_options::notify(vm);
101 for (
const auto& var : vm)
102 options_[var.first] = boost::any_cast<std::string>(var.second.value());
105 std::vector<std::string> unr = boost::program_options::collect_unrecognized(po.options, boost::program_options::exclude_positional);
106 for (std::size_t i = 0 ; i < unr.size()/2 ; ++i)
108 std::string key = boost::to_lower_copy(unr[i*2]);
109 std::string val = unr[i*2 + 1];
111 if (key.substr(0,8) ==
"solvers.")
113 std::string solver = key.substr(8);
116 for (std::size_t i = 0; i < knownSolvers.size(); ++i)
117 if (solver == knownSolvers[i]) {
127 template <
class gr
id_t,
class cell_t>
131 b.
setName(getValue<std::string>(
"benchmark.name"));
132 b.
setSaveGrid(getValue<unsigned int>(
"benchmark.savegrid"));
133 b.
setNRuns(getValue<unsigned int>(
"benchmark.runs"));
134 b.
setPath(boost::filesystem::path(
"results"));
141 bool defaultCtor =
true;
150 else if (name ==
"fmmstar")
152 else if (name ==
"fmmfib")
154 else if (name ==
"fmmfibstar")
156 else if (name ==
"sfmm")
158 else if (name ==
"sfmmstar")
160 else if (name ==
"gmm")
162 else if (name ==
"fim")
164 else if (name ==
"ufmm")
166 else if (name ==
"fsm")
168 else if (name ==
"lsm")
170 else if (name ==
"ddqm")
183 else if (name ==
"fmmstar") {
186 else if (p.size() == 2) {
189 else if (p[1] ==
"DISTANCE")
194 else if (name ==
"fmmfib")
196 else if (name ==
"fmmfibstar") {
199 else if (p.size() == 2) {
202 else if (p[1] ==
"DISTANCE")
207 else if (name ==
"sfmm")
209 else if (name ==
"sfmmstar") {
212 else if (p.size() == 2) {
215 else if (p[1] ==
"DISTANCE")
220 else if (name ==
"gmm") {
223 else if (p.size() == 2)
224 solver =
new GMM<grid_t>(p[0].c_str(), boost::lexical_cast<
double>(p[1]));
227 else if (name ==
"fim") {
230 else if (p.size() == 2)
231 solver =
new FIM<grid_t>(p[0].c_str(), boost::lexical_cast<
double>(p[1]));
234 else if (name ==
"ufmm") {
237 else if (p.size() == 2)
238 solver =
new UFMM<grid_t>(p[0].c_str(), boost::lexical_cast<
unsigned>(p[1]));
239 else if (p.size() == 3)
240 solver =
new UFMM<grid_t>(p[0].c_str(), boost::lexical_cast<
unsigned>(p[1]), boost::lexical_cast<double>(p[2]));
243 else if (name ==
"fsm") {
246 else if (p.size() == 2)
247 solver =
new FSM<grid_t>(p[0].c_str(), boost::lexical_cast<
unsigned>(p[1]));
250 else if (name ==
"lsm") {
253 else if (p.size() == 2)
254 solver =
new LSM<grid_t>(p[0].c_str(), boost::lexical_cast<
unsigned>(p[1]));
257 else if (name ==
"ddqm") {
269 constexpr
size_t N = grid_t::getNDims();
270 grid_t * grid =
new grid_t();
278 const std::string & strToSplit =
options_.find(
"grid.dimsize")->second;
279 std::array<unsigned int, N> dimSize = splitAndCast<unsigned int, N>(strToSplit);
280 grid->resize(dimSize);
283 grid->setLeafSize(getValue<double>(
"grid.leafsize"));
285 const std::string & strToSplit2 =
options_.find(
"problem.start")->second;
286 std::array<unsigned int, N> startCoords = splitAndCast<unsigned int, N>(strToSplit2);
287 unsigned int startIdx;
288 std::vector<unsigned int> startIndices;
289 grid->coord2idx(startCoords, startIdx);
290 startIndices.push_back(startIdx);
292 const std::string & strToSplit3 =
options_.find(
"problem.goal")->second;
293 if (strToSplit3 !=
"nan")
295 unsigned int goalIdx;
296 std::array<unsigned int, N> goalCoords = splitAndCast<unsigned int, N>(strToSplit3);
297 grid->coord2idx(goalCoords, goalIdx);
309 (
const std::string & key)
const {
310 std::unordered_map<std::string, std::string>::const_iterator iter =
options_.find(key);
312 return boost::lexical_cast<T>(iter->second);
314 return boost::lexical_cast<T>(0);
320 template <
typename T,
size_t N>
322 (
const std::string & s)
324 std::array<T,N> elems;
325 std::stringstream ss(s);
327 for (
size_t i = 0; i < N; ++i)
329 std::getline(ss, item,
',');
330 elems[i] = boost::lexical_cast<T>(item);
336 std::vector<std::string>
split
337 (
const std::string & s) {
338 std::vector<std::string> elems;
339 std::stringstream ss(s);
341 size_t pos = 1, str_size = s.length()-1;
342 while (pos < str_size) {
343 std::getline(ss, item,
',');
344 elems.push_back(item);
345 pos += item.length();
357 std::unordered_map<std::string, std::string>
options_;
Implements Fast Sweeping Method.
void setPath(const boost::filesystem::path &path)
Set the path where results will be saved.
Fast Marching Method using a untidy priority queue (UFMM).
Configures a Benchmark class from a CFG file. Inspired in the OMPLapp benchmarking software: http://o...
std::unordered_map< std::string, std::string > options_
Option-value map.
std::vector< std::string > split(const std::string &s)
From a string of format XXX,YY,ZZZ,... splis the elements (comma-separated) as a vector of strings...
Encapsulates the calls to FMM with heuristics enabled.
This class provides the utilities to benchmark Fast Marching Solvers (configuration, running and logging). It works for FMM (any heap and SFMM), FIM and UFMM. It has not been tested with FM2 solvers.
Implements the Simplified Fast Marching Method, encapsulating FMM with a priority queue...
void setEnvironment(grid_t *grid)
Sets the environment (grid map) the benchmark will be run on.
static void error(const std::string &val)
bool readOptions(const char *filename)
Parses the CFG file given.
void addSolver(Solver< grid_t > *solver)
Adds a new solver to be benchmarked.
boost::filesystem::path path_
Stores the absolute path to the CFG file.
void setInitialPoints(const std::vector< unsigned int > &init_points)
Sets the initial points (indices for the solvers).
T getValue(const std::string &key) const
Get the value for a given key (option).
std::vector< std::string > solverNames_
Stores the names of the parsed solvers.
Implements Double Dynamic Queue Method.
std::array< T, N > splitAndCast(const std::string &s)
From a string of format XXX,YY,ZZZ,... splis the N elements and cast as type T (comma-separated) as a...
static int loadMapFromText(const char *filename, nDGridMap< T, ndims > &grid)
Loads the initial binary map for a given grid. It is based on the nDGridMap::setOccupancy() which has...
void setSaveGrid(unsigned int s)
Sets the saveGrid_ flag.
Abstract class that serves as interface for the actual solvers implemented. It requires (at least) th...
static void loadMapFromImg(const char *filename, nDGridMap< T, ndims > &grid)
Loads the initial binary map for a given grid. It is based on the nDGridMap::setOccupancy() which has...
Implements Lock Sweeping Method.
BenchmarkCFG()
Requires readOptions to be manually called after this constructor.
Implements Fast Iterative Method.
void setNRuns(unsigned int n)
Set number of runs for each solver.
void fromCFG(bool cfg)
Set true if the benchmark is configured from a cfg file.
Templated class which computes Group Marching Method (GMM).
Implements the Fast Marching Method (FMM).
void setInitialAndGoalPoints(const std::vector< unsigned int > &init_points, unsigned int goal_idx)
Sets the initial and goal points (indices) for the solvers.
void setSaveLog(bool s)
Sets the flag to save the log to a file (true) or output in terminal (false).
std::vector< std::string > ctorParams_
Stores the constructor parameters for the parsed solvers.
void setName(const std::string &n)
Sets the name of the benchmark.