Corrected grammar of initial state facts.
This commit is contained in:
parent
9360ad3487
commit
2851f8d286
@ -245,9 +245,8 @@ class Fact;
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
using FactT = Variant<
|
using FactT = Variant<
|
||||||
AtomicFormula,
|
|
||||||
AtPointer<Literal>,
|
AtPointer<Literal>,
|
||||||
NotPointer<Fact>>;
|
Literal>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Fact : public detail::FactT
|
class Fact : public detail::FactT
|
||||||
|
@ -37,7 +37,7 @@ std::experimental::optional<ast::Fact> parseFact(Context &context, ASTContext &a
|
|||||||
// Now, test supported expressions
|
// Now, test supported expressions
|
||||||
std::experimental::optional<ast::Fact> fact;
|
std::experimental::optional<ast::Fact> fact;
|
||||||
|
|
||||||
if ((fact = parseNot<ast::Fact>(context, astContext, variableStack, parseAtomicFormula))
|
if ((fact = parseNot<ast::AtomicFormula>(context, astContext, variableStack, parseAtomicFormula))
|
||||||
|| (fact = parseAtomicFormula(context, astContext, variableStack)))
|
|| (fact = parseAtomicFormula(context, astContext, variableStack)))
|
||||||
{
|
{
|
||||||
return std::move(fact.value());
|
return std::move(fact.value());
|
||||||
|
@ -79,7 +79,9 @@ TEST_CASE("[PDDL parser issues] Check past issues", "[PDDL parser issues]")
|
|||||||
{
|
{
|
||||||
return
|
return
|
||||||
fact.template is<pddl::ast::AtPointer<pddl::ast::Literal>>()
|
fact.template is<pddl::ast::AtPointer<pddl::ast::Literal>>()
|
||||||
|| (fact.template is<pddl::ast::AtomicFormula>() && fact.template get<pddl::ast::AtomicFormula>().template is<pddl::ast::UnsupportedPointer>());
|
|| (fact.template is<pddl::ast::Literal>()
|
||||||
|
&& fact.template get<pddl::ast::Literal>().template is<pddl::ast::AtomicFormula>()
|
||||||
|
&& fact.template get<pddl::ast::Literal>().template get<pddl::ast::AtomicFormula>().template is<pddl::ast::UnsupportedPointer>());
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto containsInvalidFact = (invalidFact != facts.cend());
|
const auto containsInvalidFact = (invalidFact != facts.cend());
|
||||||
|
@ -143,17 +143,17 @@ TEST_CASE("[PDDL instances] The official PDDL instances are parsed correctly", "
|
|||||||
const auto &facts = problem->initialState.facts;
|
const auto &facts = problem->initialState.facts;
|
||||||
|
|
||||||
REQUIRE(facts.size() == 9);
|
REQUIRE(facts.size() == 9);
|
||||||
const auto &fact0 = facts[0].get<pddl::ast::AtomicFormula>().get<pddl::ast::PredicatePointer>();
|
const auto &fact0 = facts[0].get<pddl::ast::Literal>().get<pddl::ast::AtomicFormula>().get<pddl::ast::PredicatePointer>();
|
||||||
// TODO: check declaration once implemented
|
// TODO: check declaration once implemented
|
||||||
REQUIRE(fact0->arguments.size() == 1);
|
REQUIRE(fact0->arguments.size() == 1);
|
||||||
CHECK(fact0->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->name == "c");
|
CHECK(fact0->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->name == "c");
|
||||||
CHECK(fact0->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration == typeBlock.get());
|
CHECK(fact0->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration == typeBlock.get());
|
||||||
const auto &fact5 = facts[5].get<pddl::ast::AtomicFormula>().get<pddl::ast::PredicatePointer>();
|
const auto &fact5 = facts[5].get<pddl::ast::Literal>().get<pddl::ast::AtomicFormula>().get<pddl::ast::PredicatePointer>();
|
||||||
// TODO: check declaration once implemented
|
// TODO: check declaration once implemented
|
||||||
REQUIRE(fact5->arguments.size() == 1);
|
REQUIRE(fact5->arguments.size() == 1);
|
||||||
CHECK(fact5->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->name == "a");
|
CHECK(fact5->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->name == "a");
|
||||||
CHECK(fact5->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration == typeBlock.get());
|
CHECK(fact5->arguments[0].get<pddl::ast::ConstantPointer>()->declaration->type.value().get<pddl::ast::PrimitiveTypePointer>()->declaration == typeBlock.get());
|
||||||
const auto &fact8 = facts[8].get<pddl::ast::AtomicFormula>().get<pddl::ast::PredicatePointer>();
|
const auto &fact8 = facts[8].get<pddl::ast::Literal>().get<pddl::ast::AtomicFormula>().get<pddl::ast::PredicatePointer>();
|
||||||
// TODO: check declaration once implemented
|
// TODO: check declaration once implemented
|
||||||
REQUIRE(fact8->arguments.empty());
|
REQUIRE(fact8->arguments.empty());
|
||||||
|
|
||||||
|
@ -289,31 +289,41 @@ void TranslatorASP::translateInitialState() const
|
|||||||
|
|
||||||
const auto &facts = m_description.problem.value()->initialState.facts;
|
const auto &facts = m_description.problem.value()->initialState.facts;
|
||||||
|
|
||||||
|
// TODO: move to separate header
|
||||||
for (const auto &fact : facts)
|
for (const auto &fact : facts)
|
||||||
{
|
{
|
||||||
m_outputStream << std::endl << colorlog::Function("initialState") << "(";
|
m_outputStream << std::endl << colorlog::Function("initialState") << "(";
|
||||||
|
|
||||||
// Translate single predicate
|
const auto handleUnsupported =
|
||||||
if (fact.is<::pddl::ast::AtomicFormula>() && fact.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
[&](const auto &)
|
||||||
{
|
{
|
||||||
const auto &predicate = fact.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
throw TranslatorException("only predicates and their negations supported in initial state currently");
|
||||||
|
};
|
||||||
|
|
||||||
translatePredicateToVariable(m_outputStream, *predicate, true);
|
const auto handleAtomicFormula =
|
||||||
}
|
[&](const ::pddl::ast::AtomicFormula &atomicFormula, bool isPositive = true)
|
||||||
// Assuming that "not" expression may only contain a predicate
|
{
|
||||||
else if (fact.is<::pddl::ast::NotPointer<::pddl::ast::Fact>>())
|
if (!atomicFormula.is<::pddl::ast::PredicatePointer>())
|
||||||
{
|
handleUnsupported(atomicFormula);
|
||||||
const auto ¬Expression = fact.get<::pddl::ast::NotPointer<::pddl::ast::Fact>>();
|
|
||||||
|
|
||||||
if (!notExpression->argument.is<::pddl::ast::AtomicFormula>() || !notExpression->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
const auto &predicate = atomicFormula.get<::pddl::ast::PredicatePointer>();
|
||||||
throw TranslatorException("only negations of simple predicates supported in initial state currently");
|
|
||||||
|
|
||||||
const auto &predicate = notExpression->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
translatePredicateToVariable(m_outputStream, *predicate, isPositive);
|
||||||
|
};
|
||||||
|
|
||||||
translatePredicateToVariable(m_outputStream, *predicate, false);
|
const auto handleNot =
|
||||||
}
|
[&](const ::pddl::ast::NotPointer<::pddl::ast::AtomicFormula> ¬_)
|
||||||
else
|
{
|
||||||
throw TranslatorException("only predicates and their negations supported in initial state currently");
|
handleAtomicFormula(not_->argument, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleLiteral =
|
||||||
|
[&](const ::pddl::ast::Literal &literal)
|
||||||
|
{
|
||||||
|
literal.match(handleAtomicFormula, handleNot);
|
||||||
|
};
|
||||||
|
|
||||||
|
fact.match(handleLiteral, handleUnsupported);
|
||||||
|
|
||||||
m_outputStream << ").";
|
m_outputStream << ").";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user