Outsourced debug output into a separate header.

This commit is contained in:
Patrick Lühne 2016-05-22 14:40:52 +02:00
parent 21237ecac7
commit c23ba5312b
4 changed files with 196 additions and 141 deletions

View File

@ -0,0 +1,26 @@
#ifndef __SAS__DEBUGGING_H
#define __SAS__DEBUGGING_H
#include <iosfwd>
#include <plasp/sas/Description.h>
namespace plasp
{
namespace sas
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Debugging
//
////////////////////////////////////////////////////////////////////////////////////////////////////
std::ostream &operator >>(std::ostream &ostream, const Description &description);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -40,8 +40,6 @@ class Description
const Operators &operators() const; const Operators &operators() const;
const AxiomRules &axiomRules() const; const AxiomRules &axiomRules() const;
void print(std::ostream &ostream) const;
private: private:
Description(); Description();

170
src/plasp/sas/Debugging.cpp Normal file
View File

@ -0,0 +1,170 @@
#include <plasp/sas/Debugging.h>
#include <iostream>
namespace plasp
{
namespace sas
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Debugging
//
////////////////////////////////////////////////////////////////////////////////////////////////////
std::ostream &operator >>(std::ostream &ostream, const Description &description)
{
// Metric section
ostream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
// Variable section
const auto &variables = description.variables();
ostream << "variables: " << variables.size() << std::endl;
std::for_each(variables.cbegin(), variables.cend(),
[&](const auto &variable)
{
const auto &values = variable.values();
ostream << "\t" << variable.name() << ":" << std::endl;
ostream << "\t\tvalues: " << values.size() << std::endl;
std::for_each(values.cbegin(), values.cend(),
[&](const auto &value)
{
ostream << "\t\t\t";
value.printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\taxiom layer: " << variable.axiomLayer() << std::endl;
});
// Mutex section
const auto &mutexGroups = description.mutexGroups();
ostream << "mutex groups: " << mutexGroups.size() << std::endl;
std::for_each(mutexGroups.cbegin(), mutexGroups.cend(),
[&](const auto &mutexGroup)
{
ostream << "\tmutex group:" << std::endl;
std::for_each(mutexGroup.facts().cbegin(), mutexGroup.facts().cend(),
[&](const auto &fact)
{
ostream << "\t\t" << fact.variable().name() << " = ";
fact.value().printAsSAS(ostream);
ostream << std::endl;
});
});
// Initial state section
const auto &initialState = description.initialState();
ostream << "initial state:" << std::endl;
std::for_each(initialState.facts().cbegin(), initialState.facts().cend(),
[&](const auto &fact)
{
ostream << "\t" << fact.variable().name() << " = ";
fact.value().printAsSAS(ostream);
ostream << std::endl;
});
// Goal section
const auto &goal = description.goal();
ostream << "goal:" << std::endl;
std::for_each(goal.facts().cbegin(), goal.facts().cend(),
[&](const auto &fact)
{
ostream << "\t" << fact.variable().name() << " = ";
fact.value().printAsSAS(ostream);
ostream << std::endl;
});
// Operator section
const auto &operators = description.operators();
ostream << "operators: " << operators.size() << std::endl;
std::for_each(operators.cbegin(), operators.cend(),
[&](const auto &operator_)
{
ostream << "\t" << operator_.predicate() << ":" << std::endl;
const auto &preconditions = operator_.preconditions();
ostream << "\t\tpreconditions: " << preconditions.size() << std::endl;
std::for_each(preconditions.cbegin(), preconditions.cend(),
[&](const auto &precondition)
{
std::cout << "\t\t\t" << precondition.variable().name() << " = ";
precondition.value().printAsSAS(ostream);
ostream << std::endl;
});
const auto &effects = operator_.effects();
ostream << "\t\teffects: " << effects.size() << std::endl;
std::for_each(effects.cbegin(), effects.cend(),
[&](const auto &effect)
{
ostream << "\t\t\teffect:" << std::endl;
ostream << "\t\t\t\tconditions: " << effect.conditions.size() << std::endl;
std::for_each(effect.conditions.cbegin(), effect.conditions.cend(),
[&](const auto &condition)
{
ostream << "\t\t\t\t\t" << condition.variable().name() << " = ";
condition.value().printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\t\t\tpostcondition:" << std::endl;
ostream << "\t\t\t\t\t" << effect.postcondition.variable().name() << " = ";
effect.postcondition.value().printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\tcosts: " << operator_.costs() << std::endl;
});
// Axiom section
const auto &axiomRules = description.axiomRules();
ostream << "axiom rules: " << axiomRules.size() << std::endl;
std::for_each(axiomRules.cbegin(), axiomRules.cend(),
[&](const auto &axiomRule)
{
ostream << "\taxiom rule:" << std::endl;
ostream << "\t\tconditions: " << axiomRule.conditions.size() << std::endl;
std::for_each(axiomRule.conditions.cbegin(), axiomRule.conditions.cend(),
[&](const auto &condition)
{
ostream << "\t\t\t" << condition.variable().name() << " = ";
condition.value().printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\tpostcondition:" << std::endl;
ostream << "\t\t\t" << axiomRule.postcondition.variable().name() << " = ";
axiomRule.postcondition.value().printAsSAS(ostream);
ostream << std::endl;
});
return ostream;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -111,145 +111,6 @@ const AxiomRules &Description::axiomRules() const
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::print(std::ostream &ostream) const
{
// Metric section
ostream << "uses action costs: " << (m_usesActionCosts ? "yes" : "no") << std::endl;
// Variable section
ostream << "variables: " << m_variables.size() << std::endl;
std::for_each(m_variables.cbegin(), m_variables.cend(),
[&](const auto &variable)
{
const auto &values = variable.values();
ostream << "\t" << variable.name() << ":" << std::endl;
ostream << "\t\tvalues: " << values.size() << std::endl;
std::for_each(values.cbegin(), values.cend(),
[&](const auto &value)
{
ostream << "\t\t\t";
value.printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\taxiom layer: " << variable.axiomLayer() << std::endl;
});
// Mutex section
ostream << "mutex groups: " << m_mutexGroups.size() << std::endl;
std::for_each(m_mutexGroups.cbegin(), m_mutexGroups.cend(),
[&](const auto &mutexGroup)
{
ostream << "\tmutex group:" << std::endl;
std::for_each(mutexGroup.facts().cbegin(), mutexGroup.facts().cend(),
[&](const auto &fact)
{
ostream << "\t\t" << fact.variable().name() << " = ";
fact.value().printAsSAS(ostream);
ostream << std::endl;
});
});
// Initial state section
ostream << "initial state:" << std::endl;
std::for_each(m_initialState->facts().cbegin(), m_initialState->facts().cend(),
[&](const auto &fact)
{
ostream << "\t" << fact.variable().name() << " = ";
fact.value().printAsSAS(ostream);
ostream << std::endl;
});
// Goal section
ostream << "goal:" << std::endl;
std::for_each(m_goal->facts().cbegin(), m_goal->facts().cend(),
[&](const auto &fact)
{
ostream << "\t" << fact.variable().name() << " = ";
fact.value().printAsSAS(ostream);
ostream << std::endl;
});
// Operator section
ostream << "operators: " << m_operators.size() << std::endl;
std::for_each(m_operators.cbegin(), m_operators.cend(),
[&](const auto &operator_)
{
ostream << "\t" << operator_.predicate() << ":" << std::endl;
const auto &preconditions = operator_.preconditions();
ostream << "\t\tpreconditions: " << preconditions.size() << std::endl;
std::for_each(preconditions.cbegin(), preconditions.cend(),
[&](const auto &precondition)
{
std::cout << "\t\t\t" << precondition.variable().name() << " = ";
precondition.value().printAsSAS(ostream);
ostream << std::endl;
});
const auto &effects = operator_.effects();
ostream << "\t\teffects: " << effects.size() << std::endl;
std::for_each(effects.cbegin(), effects.cend(),
[&](const auto &effect)
{
ostream << "\t\t\teffect:" << std::endl;
ostream << "\t\t\t\tconditions: " << effect.conditions.size() << std::endl;
std::for_each(effect.conditions.cbegin(), effect.conditions.cend(),
[&](const auto &condition)
{
ostream << "\t\t\t\t\t" << condition.variable().name() << " = ";
condition.value().printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\t\t\tpostcondition:" << std::endl;
ostream << "\t\t\t\t\t" << effect.postcondition.variable().name() << " = ";
effect.postcondition.value().printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\tcosts: " << operator_.costs() << std::endl;
});
// Axiom section
ostream << "axiom rules: " << m_axiomRules.size() << std::endl;
std::for_each(m_axiomRules.cbegin(), m_axiomRules.cend(),
[&](const auto &axiomRule)
{
ostream << "\taxiom rule:" << std::endl;
ostream << "\t\tconditions: " << axiomRule.conditions.size() << std::endl;
std::for_each(axiomRule.conditions.cbegin(), axiomRule.conditions.cend(),
[&](const auto &condition)
{
ostream << "\t\t\t" << condition.variable().name() << " = ";
condition.value().printAsSAS(ostream);
ostream << std::endl;
});
ostream << "\t\tpostcondition:" << std::endl;
ostream << "\t\t\t" << axiomRule.postcondition.variable().name() << " = ";
axiomRule.postcondition.value().printAsSAS(ostream);
ostream << std::endl;
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseVersionSection(std::istream &istream) const void Description::parseVersionSection(std::istream &istream) const
{ {
// Version section // Version section