1 #ifndef PMPL_VALIDATION_STRATEGY_H_ 
    2 #define PMPL_VALIDATION_STRATEGY_H_ 
   13 template <
typename MPTraits>
 
   24     typedef typename RoadmapType::VID       
VID;
 
   62     virtual void Run() 
override;
 
   80         const std::vector<CfgType>& _output);
 
   89     std::string m_targetLabel;                  
 
   90     std::vector<GoldStandard> m_goldStandards;  
 
   98 template <
typename MPTraits>
 
  101   this->SetName(
"ValidationStrategy");
 
  105 template <
typename MPTraits>
 
  108   this->SetName(
"ValidationStrategy");
 
  110   m_targetLabel = _node.
Read(
"target", 
true, 
"",
 
  111       "The label of the target strategy to validate.");
 
  115   for(
auto& child : _node) {
 
  116     if(child.Name() != 
"GoldStandard")
 
  117       throw ParseException(child.Where()) << 
"Only child nodes of type " 
  118                                           << 
"'GoldStandard' are permitted.";
 
  123     std::string type = child.Read(
"type", 
true, 
"", 
"The output type.");
 
  124     std::transform(type.begin(), type.end(), type.begin(), ::tolower);
 
  125     if(type == 
"roadmap")
 
  127     else if(type == 
"blockroadmap")
 
  129     else if(type == 
"cfgpath")
 
  131     else if(type == 
"fullcfgpath")
 
  133     else if(type == 
"history")
 
  136       throw ParseException(child.Where()) << 
"Unrecognized type '" << type
 
  145         g.
label = child.Read(
"robot", 
true, 
"", 
"The robot label.");
 
  148         g.
label = child.Read(
"label", 
true, 
"", 
"The history label.");
 
  155     g.
filename = child.Read(
"filename", 
true, 
"", 
"The input file name.");
 
  157     m_goldStandards.push_back(g);
 
  160   if(m_goldStandards.empty())
 
  167 template <
typename MPTraits>
 
  171   auto problem = this->GetMPProblem();
 
  174   for(
auto& g : m_goldStandards) {
 
  177       case GoldStandard::Type::Roadmap:
 
  178       case GoldStandard::Type::BlockRoadmap:
 
  179       case GoldStandard::Type::CfgPath:
 
  180       case GoldStandard::Type::FullCfgPath:
 
  181         g.robot = problem->GetRobot(g.label);
 
  183       case GoldStandard::Type::History:
 
  190     g.filename = problem->GetPath(g.filename);
 
  191     if(!std::ifstream(g.filename).good())
 
  193                                   << g.filename << 
"'.";
 
  198 template <
typename MPTraits>
 
  203   auto target = this->GetMPStrategy(m_targetLabel);
 
  204   target->EnableOutputFiles(
false);
 
  209 template <
typename MPTraits>
 
  214   for(
const auto& g : m_goldStandards)
 
  220 template <
typename MPTraits>
 
  225     case GoldStandard::Type::Roadmap:
 
  227       auto output = this->GetRoadmap(_g.robot);
 
  228       ValidateRoadmap(_g, output);
 
  231     case GoldStandard::Type::BlockRoadmap:
 
  233       auto output = this->GetBlockRoadmap(_g.robot);
 
  234       ValidateRoadmap(_g, output);
 
  237     case GoldStandard::Type::CfgPath:
 
  239       const std::vector<CfgType> output = this->GetPath(_g.robot)->Cfgs();
 
  240       ValidatePath(_g, output);
 
  243     case GoldStandard::Type::FullCfgPath:
 
  245       const std::vector<CfgType> output = this->GetPath(_g.robot)->FullCfgs(
 
  246           this->GetMPLibrary());
 
  247       ValidatePath(_g, output);
 
  250     case GoldStandard::Type::History:
 
  261 template <
typename MPTraits>
 
  266     std::cout << 
"Validating " 
  267               << (_g.type == GoldStandard::Type::BlockRoadmap ? 
"blocked " : 
"")
 
  268               << 
"roadmap file '" << _g.filename << 
"'" 
  269               << 
" for robot '" << _g.label << 
"'" 
  273   RoadmapType input(_g.robot);
 
  274   ::Read(&input, _g.filename);
 
  277   const bool ok = *_output == input;
 
  281     std::cout << 
"\t" << (ok ? 
"Passed" : 
"Failed") << std::endl;
 
  286   const std::string base = this->GetBaseFilename();
 
  288   if(_g.type == GoldStandard::Type::Roadmap)
 
  289     _output->Write(base + 
".map", this->GetEnvironment());
 
  291     _output->Write(base + 
".block.map", this->GetEnvironment());
 
  295 template <
typename MPTraits>
 
  298 ValidatePath(
const GoldStandard& _g, 
const std::vector<CfgType>& _output) {
 
  300     std::cout << 
"Validating " 
  301               << (_g.type == GoldStandard::Type::FullCfgPath ? 
"full " : 
"")
 
  302               << 
"cfg path file '" << _g.filename << 
"'" 
  303               << 
" for robot '" << _g.label << 
"'" 
  307   const std::vector<CfgType> input = ReadPath<CfgType>(_g.filename, _g.robot);
 
  310   const bool ok = _output == input;
 
  314     std::cout << 
"\t" << (ok ? 
"Passed" : 
"Failed") << std::endl;
 
  319   const std::string base = this->GetBaseFilename();
 
  320   if(_g.type == GoldStandard::Type::CfgPath)
 
  327 template <
typename MPTraits>
 
  332     std::cout << 
"Validating history file '" << _g.filename << 
"' for history " 
  333               << 
"stat '" << _g.label << 
"'" 
  337   auto stats = this->GetStatClass();
 
  338   const std::vector<double> output = stats->GetHistory(_g.label);
 
  342   std::vector<double> input;
 
  343   input.reserve(output.size());
 
  344   std::ifstream ifs(_g.filename);
 
  346     input.push_back(buffer);
 
  349   constexpr 
double tolerance = std::numeric_limits<double>::epsilon() * 100;
 
  350   bool ok = output.size() == input.size();
 
  351   for(
size_t i = 0; ok and i < output.size(); ++i)
 
  352     ok &= nonstd::approx(output[i], input[i], tolerance);
 
  356     std::cout << 
"\t" << (ok ? 
"Passed" : 
"Failed") << std::endl;
 
  361   stats->WriteHistory(_g.label);
 
void Read(GenericStateGraph *_g, const std::string &_filename)
Definition: GenericStateGraph.h:1337
 
void WritePath(const std::string &_filename, const std::vector< CfgType > &_path)
Write a list of Cfgs from a path to file.
Definition: IOUtils.h:145
 
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
 
Definition: MPStrategyMethod.h:33
 
Definition: ValidationStrategy.h:14
 
MPTraits::CfgType CfgType
Definition: ValidationStrategy.h:21
 
MPTraits::WeightType WeightType
Definition: ValidationStrategy.h:22
 
virtual void Finalize() override
Clean-up and output results.
Definition: ValidationStrategy.h:212
 
RoadmapType::VID VID
Definition: ValidationStrategy.h:24
 
virtual void Initialize() override
Definition: ValidationStrategy.h:170
 
virtual ~ValidationStrategy()=default
 
MPTraits::RoadmapType RoadmapType
Definition: ValidationStrategy.h:23
 
ValidationStrategy()
Definition: ValidationStrategy.h:100
 
virtual void Run() override
Call Iterate until EvaluateMap is true.
Definition: ValidationStrategy.h:201
 
std::string Where() const
Definition: XMLNode.cpp:243
 
T Read(const std::string &_name, const bool _req, const T &_default, const T &_min, const T &_max, const std::string &_desc)
Definition: XMLNode.h:274
 
Defines available methods in the Motion Planning Universe for Cfg under parallel compile.
Definition: ParallelCfgTraits.h:144
 
C CfgType
Definition: ParallelCfgTraits.h:145
 
W WeightType
Definition: ParallelCfgTraits.h:146
 
Definition: PMPLExceptions.h:38
 
Definition: PMPLExceptions.h:62
 
A gold standard input to validate against the target strategy.
Definition: ValidationStrategy.h:31
 
Type type
The type of output to check.
Definition: ValidationStrategy.h:40
 
Type
The types of gold standard files we can read.
Definition: ValidationStrategy.h:34
 
std::string filename
The input filename.
Definition: ValidationStrategy.h:43
 
Robot * robot
The robot represented in the output.
Definition: ValidationStrategy.h:42
 
std::string label
Label for the generated object.
Definition: ValidationStrategy.h:41