Started implementing derived predicates for decomposing complex PDDL conditions.
This commit is contained in:
parent
cc0b9726ed
commit
a62cc8b3b9
@ -7,6 +7,7 @@
|
||||
#include <plasp/pddl/Parser.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
#include <plasp/pddl/expressions/DerivedPredicate.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||
|
||||
@ -49,6 +50,9 @@ class Domain
|
||||
std::vector<std::unique_ptr<Action>> &actions();
|
||||
const std::vector<std::unique_ptr<Action>> &actions() const;
|
||||
|
||||
expressions::DerivedPredicates &derivedPredicates();
|
||||
const expressions::DerivedPredicates &derivedPredicates() const;
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
void normalize();
|
||||
@ -85,6 +89,8 @@ class Domain
|
||||
|
||||
std::vector<utils::Stream::Position> m_actionPositions;
|
||||
std::vector<std::unique_ptr<Action>> m_actions;
|
||||
|
||||
expressions::DerivedPredicates m_derivedPredicates;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -40,6 +40,10 @@ class Constant;
|
||||
using ConstantPointer = boost::intrusive_ptr<Constant>;
|
||||
using Constants = std::vector<ConstantPointer>;
|
||||
|
||||
class DerivedPredicate;
|
||||
using DerivedPredicatePointer = boost::intrusive_ptr<DerivedPredicate>;
|
||||
using DerivedPredicates = std::vector<DerivedPredicatePointer>;
|
||||
|
||||
class Dummy;
|
||||
using DummyPointer = boost::intrusive_ptr<Dummy>;
|
||||
|
||||
@ -103,6 +107,7 @@ class Expression
|
||||
At,
|
||||
Binary,
|
||||
Constant,
|
||||
DerivedPredicate,
|
||||
Dummy,
|
||||
Either,
|
||||
Exists,
|
||||
@ -132,6 +137,7 @@ class Expression
|
||||
virtual ExpressionPointer prenex(Expression::Type lastQuantifierType = Expression::Type::Exists);
|
||||
virtual ExpressionPointer simplified();
|
||||
virtual ExpressionPointer disjunctionNormalized();
|
||||
virtual ExpressionPointer decomposed(expressions::DerivedPredicates &derivedPredicates);
|
||||
ExpressionPointer negated();
|
||||
|
||||
virtual void print(std::ostream &ostream) const = 0;
|
||||
|
@ -25,6 +25,7 @@ class And: public NAry<And>
|
||||
|
||||
public:
|
||||
ExpressionPointer disjunctionNormalized() override;
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
42
include/plasp/pddl/expressions/DerivedPredicate.h
Normal file
42
include/plasp/pddl/expressions/DerivedPredicate.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__DERIVED_PREDICATE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__DERIVED_PREDICATE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DerivedPredicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DerivedPredicate: public ExpressionCRTP<DerivedPredicate>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::DerivedPredicate;
|
||||
|
||||
// TODO: consider implementing parsing functions for compatibility with older PDDL versions
|
||||
|
||||
public:
|
||||
void setArgument(ExpressionPointer argument);
|
||||
ExpressionPointer argument() const;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
ExpressionPointer m_argument;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -22,6 +22,9 @@ class Exists: public QuantifiedCRTP<Exists>
|
||||
static const Expression::Type ExpressionType = Expression::Type::Exists;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -22,6 +22,9 @@ class ForAll: public QuantifiedCRTP<ForAll>
|
||||
static const Expression::Type ExpressionType = Expression::Type::ForAll;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -39,6 +39,7 @@ class Not: public ExpressionCRTP<Not>
|
||||
ExpressionPointer prenex(Expression::Type lastExpressionType) override;
|
||||
ExpressionPointer simplified() override;
|
||||
ExpressionPointer disjunctionNormalized() override;
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
|
@ -22,6 +22,9 @@ class Or: public NAry<Or>
|
||||
static const Expression::Type ExpressionType = Expression::Type::Or;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -232,6 +232,20 @@ const std::vector<std::unique_ptr<Action>> &Domain::actions() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
expressions::DerivedPredicates &Domain::derivedPredicates()
|
||||
{
|
||||
return m_derivedPredicates;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const expressions::DerivedPredicates &Domain::derivedPredicates() const
|
||||
{
|
||||
return m_derivedPredicates;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Domain::parseRequirementSection()
|
||||
{
|
||||
auto &parser = m_context.parser;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
#include <plasp/pddl/expressions/When.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -112,6 +113,13 @@ ExpressionPointer Expression::disjunctionNormalized()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Expression::decomposed(expressions::DerivedPredicates &)
|
||||
{
|
||||
throw utils::TranslatorException("Expression is not in first-order negation normal form and cannot be decomposed");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Expression::negated()
|
||||
{
|
||||
if (expressionType() == Type::Not)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/pddl/expressions/Or.h>
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -67,6 +68,29 @@ ExpressionPointer And::disjunctionNormalized()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer And::decomposed(DerivedPredicates &derivedPredicates)
|
||||
{
|
||||
// Check that all children are simple or negated predicates
|
||||
std::for_each(m_arguments.begin(), m_arguments.end(),
|
||||
[&](auto &argument)
|
||||
{
|
||||
if (argument->expressionType() == Expression::Type::Not)
|
||||
{
|
||||
argument = argument->decomposed(derivedPredicates);
|
||||
return;
|
||||
}
|
||||
|
||||
if (argument->expressionType() != Expression::Type::Predicate)
|
||||
return;
|
||||
|
||||
throw utils::TranslatorException("Expression is not in first-order negation normal form and cannot be decomposed");
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
44
src/plasp/pddl/expressions/DerivedPredicate.cpp
Normal file
44
src/plasp/pddl/expressions/DerivedPredicate.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <plasp/pddl/expressions/DerivedPredicate.h>
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DerivedPredicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DerivedPredicate::setArgument(ExpressionPointer argument)
|
||||
{
|
||||
m_argument = argument;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer DerivedPredicate::argument() const
|
||||
{
|
||||
return m_argument;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DerivedPredicate::print(std::ostream &ostream) const
|
||||
{
|
||||
ostream << "(:derived <no name> ";
|
||||
m_argument->print(ostream);
|
||||
ostream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,15 @@ const std::string Exists::Identifier = "exists";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Exists::decomposed(DerivedPredicates &derivedPredicates)
|
||||
{
|
||||
m_argument = m_argument->decomposed(derivedPredicates);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/pddl/expressions/DerivedPredicate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
@ -20,6 +22,18 @@ const std::string ForAll::Identifier = "forall";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer ForAll::decomposed(DerivedPredicates &derivedPredicates)
|
||||
{
|
||||
auto derivedPredicate = DerivedPredicatePointer(new DerivedPredicate);
|
||||
derivedPredicates.push_back(derivedPredicate);
|
||||
|
||||
derivedPredicate->setArgument(this);
|
||||
|
||||
return derivedPredicate;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <plasp/pddl/expressions/Exists.h>
|
||||
#include <plasp/pddl/expressions/ForAll.h>
|
||||
#include <plasp/pddl/expressions/Or.h>
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -183,6 +184,19 @@ void Not::print(std::ostream &ostream) const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Not::decomposed(DerivedPredicates &)
|
||||
{
|
||||
if (m_argument->expressionType() != Expression::Type::Not
|
||||
&& m_argument->expressionType() != Expression::Type::Predicate)
|
||||
{
|
||||
throw utils::TranslatorException("Expression is not in first-order negation normal form and cannot be decomposed");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <plasp/pddl/expressions/Or.h>
|
||||
|
||||
#include <plasp/pddl/expressions/DerivedPredicate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
@ -17,6 +19,25 @@ const std::string Or::Identifier = "or";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Or::decomposed(DerivedPredicates &derivedPredicates)
|
||||
{
|
||||
// Check that all children are simple or negated predicates
|
||||
std::for_each(m_arguments.begin(), m_arguments.end(),
|
||||
[&](auto &argument)
|
||||
{
|
||||
argument = argument->decomposed(derivedPredicates);
|
||||
});
|
||||
|
||||
auto derivedPredicate = DerivedPredicatePointer(new DerivedPredicate);
|
||||
derivedPredicates.push_back(derivedPredicate);
|
||||
|
||||
derivedPredicate->setArgument(this);
|
||||
|
||||
return derivedPredicate;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user