20 #ifndef BENCHMARK_HPP_ 
   21 #define BENCHMARK_HPP_ 
   26 #include <boost/filesystem.hpp> 
   27 #include <boost/progress.hpp> 
   29 #include <fast_methods/fm/solver.hpp> 
   30 #include <fast_methods/io/gridwriter.hpp> 
   32 template <
class gr
id_t>
 
   84         (
const boost::filesystem::path & path) {
 
   96         (
const std::vector<unsigned int> & init_points, 
unsigned int goal_idx) {
 
  112                 boost::filesystem::create_directory(
path_);
 
  113                 boost::filesystem::create_directory(
path_ / 
name_);
 
  116                 boost::filesystem::create_directory(
path_);
 
  126                 for (
unsigned int i = 0; i < 
nruns_; ++i)
 
  147                 std::cout << 
"Name\t#Runs\t#Dims\tDim1...DimN\t#Starts\tStartIdx\tGoalIdx"<<
'\n';
 
  148                 std::cout << 
"RunID\tName\tTime (ms)" << 
'\n';
 
  149                 std::cout << 
log_.str() << 
'\n';
 
  158             init.copyfmt(std::cout);
 
  162             std::cout.copyfmt(init);
 
  163             log_ << 
'\t' << s->
getName() << 
"\t" << s->getTime();
 
  169             thread_local boost::filesystem::path filename;
 
  175             filename.replace_extension(
".grid");
 
  182             std::ofstream ofs (
path_.string() + 
"/" + 
name_ + 
".log");
 
  189         (
const std::string & n)
 
  211                  << 
'\t' << 
grid_->getDimSizesStr();
 
  236             thread_local std::ostringstream oss; 
 
  239             oss << std::setw(4) << std::setfill(
'0') << 
runID_;
 
  256         std::chrono::time_point<std::chrono::system_clock>  
start_, end_;
 
void setPath(const boost::filesystem::path &path)
Set the path where results will be saved. 
std::vector< Solver< grid_t > * > solvers_
Stores the solvers to be run in the benchmark. 
std::stringstream log_
Log stream. 
virtual void setEnvironment(grid_t *g)
Sets and cleans the grid in which operations will be performed. 
std::string fmtID_
Formatted run ID: 
unsigned int saveGrid_
If 1, the resulting grids (times) of the first run of each solver are saved to files. If 2, the grids for all runs of each solver are saved. 
static void saveGridValues(const char *filename, nDGridMap< T, ndims > &grid)
Saves grid values in ASCII format into the specified file. 
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. 
void logConfig()
Logs the benchmark configuration. 
void clear()
Clears and free memory allocated by the benchmark. 
void setEnvironment(grid_t *grid)
Sets the environment (grid map) the benchmark will be run on. 
boost::filesystem::path path_
Path were the results will be saved. 
bool fromCFG_
If true, benchmark configured from CFG file, used to selectively free memory. 
unsigned int runID_
ID of the current run. 
void formatID()
Formats as a string the run ID. 
const std::string & getName() const 
Returns name of the solver. 
grid_t * grid_
Grid the benchmark will be run on. 
void saveGrid(Solver< grid_t > *s) const 
Saves the grid values result of the last run of solver s. 
bool saveLog_
If true, the log is saved to file. Output on terminal otherwise. 
void addSolver(Solver< grid_t > *solver)
Adds a new solver to be benchmarked. 
static void info(const std::string &val)
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. 
void configSolvers()
Configures each solver so they are ready to be run. 
std::string name_
Benchmark name. 
virtual void clear()
Clears the solver, it is not recommended to be used out of the destructor. 
void setInitialPoints(const std::vector< unsigned int > &init_points)
Sets the initial points (indices for the solvers). 
unsigned int goal_idx_
Index of the goal point. 
unsigned int nruns_
Number of runs for each solver. 
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...
std::vector< unsigned int > init_points_
Indices of the initial points. 
std::chrono::time_point< std::chrono::system_clock > start_
Time measurement variables. 
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. 
void logRun(const Solver< grid_t > *s)
Logs the last run of solver s. 
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). 
grid_t * getGrid() const 
Returns a pointer to the grid used. 
void run()
Automatically runs all the solvers. 
void setName(const std::string &n)
Sets the name of the benchmark. 
void saveLog() const 
Saves the log to a file: benchmark_name.log.