From 15289a0c8c986ae6e974a593996ed5f7adf1205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 21 May 2016 01:17:17 +0200 Subject: [PATCH] Implemented parsing the signs of values. --- include/plasp/sas/Value.h | 12 ++++++++++++ src/plasp/sas/Description.cpp | 32 +++++++++++++++++++++----------- src/plasp/sas/Value.cpp | 14 +++++++++++++- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/include/plasp/sas/Value.h b/include/plasp/sas/Value.h index dbbcd7a..9613678 100644 --- a/include/plasp/sas/Value.h +++ b/include/plasp/sas/Value.h @@ -1,6 +1,7 @@ #ifndef __SAS__VALUE_H #define __SAS__VALUE_H +#include #include namespace plasp @@ -16,13 +17,24 @@ namespace sas struct Value { + enum class Sign + { + Positive, + Negative + }; + static const Value Any; + Sign sign; std::string name; }; //////////////////////////////////////////////////////////////////////////////////////////////////// +std::ostream &operator <<(std::ostream &ostream, const Value &value); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + } } diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 175f35c..30560da 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -125,7 +125,7 @@ void Description::print(std::ostream &ostream) const std::for_each(variable.values.cbegin(), variable.values.cend(), [&](const auto &value) { - ostream << "\t\t\t" << value.name << std::endl; + ostream << "\t\t\t" << value << std::endl; }); ostream << "\t\taxiom layer: " << variable.axiomLayer << std::endl; @@ -142,7 +142,7 @@ void Description::print(std::ostream &ostream) const std::for_each(mutexGroup.facts.cbegin(), mutexGroup.facts.cend(), [&](const auto &fact) { - ostream << "\t\t" << fact.variable.name << " = " << fact.value.name << std::endl; + ostream << "\t\t" << fact.variable.name << " = " << fact.value << std::endl; }); }); @@ -152,7 +152,7 @@ void Description::print(std::ostream &ostream) const std::for_each(m_initialStateFacts.cbegin(), m_initialStateFacts.cend(), [&](const auto &initialStateFact) { - ostream << "\t" << initialStateFact.variable.name << " = " << initialStateFact.value.name << std::endl; + ostream << "\t" << initialStateFact.variable.name << " = " << initialStateFact.value << std::endl; }); // Goal section @@ -161,7 +161,7 @@ void Description::print(std::ostream &ostream) const std::for_each(m_goalFacts.cbegin(), m_goalFacts.cend(), [&](const auto &goalFact) { - ostream << "\t" << goalFact.variable.name << " = " << goalFact.value.name << std::endl; + ostream << "\t" << goalFact.variable.name << " = " << goalFact.value << std::endl; }); // Operator section @@ -176,7 +176,7 @@ void Description::print(std::ostream &ostream) const std::for_each(operator_.preconditions.cbegin(), operator_.preconditions.cend(), [&](const auto &precondition) { - std::cout << "\t\t\t" << precondition.variable.name << " = " << precondition.value.name << std::endl; + std::cout << "\t\t\t" << precondition.variable.name << " = " << precondition.value << std::endl; }); ostream << "\t\teffects: " << operator_.effects.size() << std::endl; @@ -190,11 +190,11 @@ void Description::print(std::ostream &ostream) const std::for_each(effect.conditions.cbegin(), effect.conditions.cend(), [&](const auto &condition) { - ostream << "\t\t\t\t\t" << condition.variable.name << " = " << condition.value.name << std::endl; + ostream << "\t\t\t\t\t" << condition.variable.name << " = " << condition.value << std::endl; }); ostream << "\t\t\t\tpostcondition:" << std::endl; - ostream << "\t\t\t\t\t" << effect.postcondition.variable.name << " = " << effect.postcondition.value.name << std::endl; + ostream << "\t\t\t\t\t" << effect.postcondition.variable.name << " = " << effect.postcondition.value << std::endl; }); ostream << "\t\tcosts: " << operator_.costs << std::endl; @@ -212,11 +212,11 @@ void Description::print(std::ostream &ostream) const std::for_each(axiomRule.conditions.cbegin(), axiomRule.conditions.cend(), [&](const auto &condition) { - ostream << "\t\t\t" << condition.variable.name << " = " << condition.value.name << std::endl; + ostream << "\t\t\t" << condition.variable.name << " = " << condition.value << std::endl; }); ostream << "\t\tpostcondition:" << std::endl; - ostream << "\t\t\t" << axiomRule.postcondition.variable.name << " = " << axiomRule.postcondition.value.name << std::endl; + ostream << "\t\t\t" << axiomRule.postcondition.variable.name << " = " << axiomRule.postcondition.value << std::endl; }); } @@ -344,11 +344,21 @@ void Description::parseVariablesSection(std::istream &istream) try { - istream.ignore(std::numeric_limits::max(), '\n'); - for (size_t j = 0; j < numberOfValues; j++) { auto &value = variable.values[j]; + + const auto sasSign = parse(istream); + + if (sasSign == "Atom") + value.sign = Value::Sign::Positive; + else if (sasSign == "NegatedAtom") + value.sign = Value::Sign::Negative; + else + throw ParserException("Invalid value sign \"" + sasSign + "\""); + + istream.ignore(1); + std::getline(istream, value.name); } } diff --git a/src/plasp/sas/Value.cpp b/src/plasp/sas/Value.cpp index 532ed77..4d42110 100644 --- a/src/plasp/sas/Value.cpp +++ b/src/plasp/sas/Value.cpp @@ -1,5 +1,7 @@ #include +#include + namespace plasp { namespace sas @@ -11,7 +13,17 @@ namespace sas // //////////////////////////////////////////////////////////////////////////////////////////////////// -const Value Value::Any = {"(any)"}; +const Value Value::Any = {Value::Sign::Positive, "(any)"}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +std::ostream &operator <<(std::ostream &ostream, const Value &value) +{ + if (value.sign == Value::Sign::Negative) + ostream << "not "; + + return (ostream << value.name); +} ////////////////////////////////////////////////////////////////////////////////////////////////////