From c23ba5312bd4d21b2064f80885bead940cc17533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sun, 22 May 2016 14:40:52 +0200 Subject: [PATCH] Outsourced debug output into a separate header. --- include/plasp/sas/Debugging.h | 26 +++++ include/plasp/sas/Description.h | 2 - src/plasp/sas/Debugging.cpp | 170 ++++++++++++++++++++++++++++++++ src/plasp/sas/Description.cpp | 139 -------------------------- 4 files changed, 196 insertions(+), 141 deletions(-) create mode 100644 include/plasp/sas/Debugging.h create mode 100644 src/plasp/sas/Debugging.cpp diff --git a/include/plasp/sas/Debugging.h b/include/plasp/sas/Debugging.h new file mode 100644 index 0000000..1b281f9 --- /dev/null +++ b/include/plasp/sas/Debugging.h @@ -0,0 +1,26 @@ +#ifndef __SAS__DEBUGGING_H +#define __SAS__DEBUGGING_H + +#include + +#include + +namespace plasp +{ +namespace sas +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Debugging +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +std::ostream &operator >>(std::ostream &ostream, const Description &description); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/include/plasp/sas/Description.h b/include/plasp/sas/Description.h index f46675c..5baa938 100644 --- a/include/plasp/sas/Description.h +++ b/include/plasp/sas/Description.h @@ -40,8 +40,6 @@ class Description const Operators &operators() const; const AxiomRules &axiomRules() const; - void print(std::ostream &ostream) const; - private: Description(); diff --git a/src/plasp/sas/Debugging.cpp b/src/plasp/sas/Debugging.cpp new file mode 100644 index 0000000..9a5852e --- /dev/null +++ b/src/plasp/sas/Debugging.cpp @@ -0,0 +1,170 @@ +#include + +#include + +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; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 25bf85f..2a41dcc 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -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 { // Version section