Made AxiomRule a proper class.
This commit is contained in:
69
src/plasp/sas/AxiomRule.cpp
Normal file
69
src/plasp/sas/AxiomRule.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <plasp/sas/AxiomRule.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/sas/VariableTransition.h>
|
||||
#include <plasp/utils/Parsing.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// AxiomRule
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AxiomRule::AxiomRule(AxiomRule::Conditions conditions, AxiomRule::Condition postcondition)
|
||||
: m_conditions(std::move(conditions)),
|
||||
m_postcondition(std::move(postcondition))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AxiomRule AxiomRule::fromSAS(std::istream &istream, const Variables &variables)
|
||||
{
|
||||
utils::parseExpected<std::string>(istream, "begin_rule");
|
||||
|
||||
const auto numberOfConditions = utils::parse<size_t>(istream);
|
||||
|
||||
Conditions conditions;
|
||||
conditions.reserve(numberOfConditions);
|
||||
|
||||
for (size_t j = 0; j < numberOfConditions; j++)
|
||||
conditions.emplace_back(AssignedVariable::fromSAS(istream, variables));
|
||||
|
||||
const auto variableTransition = VariableTransition::fromSAS(istream, variables);
|
||||
|
||||
if (&variableTransition.valueBefore() != &Value::Any)
|
||||
conditions.emplace_back(AssignedVariable(variableTransition.variable(), variableTransition.valueBefore()));
|
||||
|
||||
utils::parseExpected<std::string>(istream, "end_rule");
|
||||
|
||||
const Condition postcondition(variableTransition.variable(), variableTransition.valueAfter());
|
||||
const AxiomRule axiomRule(std::move(conditions), std::move(postcondition));
|
||||
|
||||
return axiomRule;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const AxiomRule::Conditions &AxiomRule::conditions() const
|
||||
{
|
||||
return m_conditions;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const AxiomRule::Condition &AxiomRule::postcondition() const
|
||||
{
|
||||
return m_postcondition;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
@@ -145,9 +145,12 @@ std::ostream &operator >>(std::ostream &ostream, const Description &description)
|
||||
[&](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 conditions = axiomRule.conditions();
|
||||
|
||||
ostream << "\t\tconditions: " << conditions.size() << std::endl;
|
||||
|
||||
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||
[&](const auto &condition)
|
||||
{
|
||||
ostream << "\t\t\t" << condition.variable().name() << " = ";
|
||||
@@ -156,8 +159,8 @@ std::ostream &operator >>(std::ostream &ostream, const Description &description)
|
||||
});
|
||||
|
||||
ostream << "\t\tpostcondition:" << std::endl;
|
||||
ostream << "\t\t\t" << axiomRule.postcondition.variable().name() << " = ";
|
||||
axiomRule.postcondition.value().printAsSAS(ostream);
|
||||
ostream << "\t\t\t" << axiomRule.postcondition().variable().name() << " = ";
|
||||
axiomRule.postcondition().value().printAsSAS(ostream);
|
||||
ostream << std::endl;
|
||||
});
|
||||
|
||||
|
@@ -189,28 +189,7 @@ void Description::parseAxiomSection(std::istream &istream)
|
||||
m_axiomRules.reserve(numberOfAxiomRules);
|
||||
|
||||
for (size_t i = 0; i < numberOfAxiomRules; i++)
|
||||
{
|
||||
utils::parseExpected<std::string>(istream, "begin_rule");
|
||||
|
||||
const auto numberOfConditions = utils::parse<size_t>(istream);
|
||||
|
||||
AxiomRule::Conditions conditions;
|
||||
conditions.reserve(numberOfConditions);
|
||||
|
||||
for (size_t j = 0; j < numberOfConditions; j++)
|
||||
conditions.emplace_back(AssignedVariable::fromSAS(istream, m_variables));
|
||||
|
||||
const auto variableTransition = VariableTransition::fromSAS(istream, m_variables);
|
||||
|
||||
if (&variableTransition.valueBefore() != &Value::Any)
|
||||
conditions.emplace_back(AssignedVariable(variableTransition.variable(), variableTransition.valueBefore()));
|
||||
|
||||
const AxiomRule::Condition postcondition = {variableTransition.variable(), variableTransition.valueAfter()};
|
||||
const AxiomRule axiomRule = {std::move(conditions), std::move(postcondition)};
|
||||
m_axiomRules.push_back(std::move(axiomRule));
|
||||
|
||||
utils::parseExpected<std::string>(istream, "end_rule");
|
||||
}
|
||||
m_axiomRules.emplace_back(AxiomRule::fromSAS(istream, m_variables));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user