Reimplemented plasp with PDDL parsing library.
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__ACTION_H
|
||||
#define __PLASP__PDDL__ACTION_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Action
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
static void parseDeclaration(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
|
||||
const expressions::Variables ¶meters() const;
|
||||
const Expression *precondition() const;
|
||||
const Expression *effect() const;
|
||||
|
||||
void normalize(expressions::DerivedPredicates &derivedPredicates);
|
||||
|
||||
private:
|
||||
Action() = default;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
expressions::Variables m_parameters;
|
||||
ExpressionPointer m_precondition;
|
||||
ExpressionPointer m_effect;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,57 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__CONSISTENCY_EXCEPTION_H
|
||||
#define __PLASP__PDDL__CONSISTENCY_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ConsistencyException
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ConsistencyException: public std::exception
|
||||
{
|
||||
public:
|
||||
explicit ConsistencyException()
|
||||
: ConsistencyException("unspecified consistency error")
|
||||
{
|
||||
}
|
||||
|
||||
explicit ConsistencyException(const char *message)
|
||||
: ConsistencyException(static_cast<std::string>(message))
|
||||
{
|
||||
}
|
||||
|
||||
explicit ConsistencyException(const std::string &message)
|
||||
: m_message{message}
|
||||
{
|
||||
}
|
||||
|
||||
~ConsistencyException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char *what() const throw()
|
||||
{
|
||||
if (m_message.empty())
|
||||
return "unspecified consistency error";
|
||||
|
||||
return m_message.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,59 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__CONTEXT_H
|
||||
#define __PLASP__PDDL__CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/output/Logger.h>
|
||||
#include <plasp/pddl/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Context
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
Context() = default;
|
||||
~Context() = default;
|
||||
|
||||
explicit Context(Tokenizer &&otherTokenizer, output::Logger &otherLogger)
|
||||
: tokenizer{std::move(otherTokenizer)},
|
||||
logger(otherLogger)
|
||||
{
|
||||
}
|
||||
|
||||
Context(const Context &other) = delete;
|
||||
Context &operator=(const Context &other) = delete;
|
||||
|
||||
Context(Context &&other)
|
||||
: tokenizer(std::move(other.tokenizer)),
|
||||
logger(other.logger)
|
||||
{
|
||||
}
|
||||
|
||||
Context &operator=(Context &&other) = delete;
|
||||
|
||||
constexpr static const char *auxiliaryPrefix()
|
||||
{
|
||||
return "__plasp_";
|
||||
}
|
||||
|
||||
Tokenizer tokenizer;
|
||||
output::Logger &logger;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,60 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__DESCRIPTION_H
|
||||
#define __PLASP__PDDL__DESCRIPTION_H
|
||||
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/Problem.h>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Description
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Description
|
||||
{
|
||||
public:
|
||||
static Description fromContext(Context &context);
|
||||
static Description fromStream(std::istream &istream, Context &context);
|
||||
static Description fromFile(const std::string &path, Context &context);
|
||||
static Description fromFiles(const std::vector<std::string> &paths, Context &context);
|
||||
|
||||
public:
|
||||
Context &context();
|
||||
const Context &context() const;
|
||||
|
||||
const Domain &domain() const;
|
||||
|
||||
bool containsProblem() const;
|
||||
const Problem &problem() const;
|
||||
|
||||
void normalize();
|
||||
|
||||
private:
|
||||
Description(Context &context);
|
||||
|
||||
void parse();
|
||||
void findSections();
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
Context &m_context;
|
||||
|
||||
tokenize::StreamPosition m_domainPosition;
|
||||
std::unique_ptr<Domain> m_domain;
|
||||
tokenize::StreamPosition m_problemPosition;
|
||||
std::unique_ptr<Problem> m_problem;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,101 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__DOMAIN_H
|
||||
#define __PLASP__PDDL__DOMAIN_H
|
||||
|
||||
#include <plasp/pddl/Action.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/Tokenizer.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>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Domain
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Domain
|
||||
{
|
||||
public:
|
||||
Domain(Context &context);
|
||||
|
||||
public:
|
||||
void findSections();
|
||||
void parse();
|
||||
|
||||
void setName(std::string name);
|
||||
const std::string &name() const;
|
||||
|
||||
const Requirements &requirements() const;
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void checkRequirement(Requirement::Type requirementType);
|
||||
|
||||
expressions::PrimitiveTypes &types();
|
||||
const expressions::PrimitiveTypes &types() const;
|
||||
|
||||
expressions::Constants &constants();
|
||||
const expressions::Constants &constants() const;
|
||||
|
||||
expressions::PredicateDeclarations &predicates();
|
||||
const expressions::PredicateDeclarations &predicates() const;
|
||||
|
||||
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();
|
||||
|
||||
private:
|
||||
void parseSection();
|
||||
|
||||
void parseRequirementSection();
|
||||
void computeDerivedRequirements();
|
||||
|
||||
void parseTypeSection();
|
||||
|
||||
void parseConstantSection();
|
||||
|
||||
void parsePredicateSection();
|
||||
|
||||
void parseActionSection();
|
||||
|
||||
Context &m_context;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
tokenize::StreamPosition m_requirementsPosition;
|
||||
Requirements m_requirements;
|
||||
|
||||
tokenize::StreamPosition m_typesPosition;
|
||||
expressions::PrimitiveTypes m_types;
|
||||
|
||||
tokenize::StreamPosition m_constantsPosition;
|
||||
expressions::Constants m_constants;
|
||||
|
||||
tokenize::StreamPosition m_predicatesPosition;
|
||||
expressions::PredicateDeclarations m_predicates;
|
||||
|
||||
std::vector<tokenize::StreamPosition> m_actionPositions;
|
||||
std::vector<std::unique_ptr<Action>> m_actions;
|
||||
|
||||
expressions::DerivedPredicates m_derivedPredicates;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,237 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION_H
|
||||
#define __PLASP__PDDL__EXPRESSION_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <set>
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Expression
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
class Domain;
|
||||
class ExpressionContext;
|
||||
class ExpressionVisitor;
|
||||
class Problem;
|
||||
|
||||
class Expression;
|
||||
using ExpressionPointer = boost::intrusive_ptr<Expression>;
|
||||
using Expressions = std::vector<ExpressionPointer>;
|
||||
|
||||
namespace expressions
|
||||
{
|
||||
class And;
|
||||
using AndPointer = boost::intrusive_ptr<And>;
|
||||
|
||||
class At;
|
||||
using AtPointer = boost::intrusive_ptr<At>;
|
||||
|
||||
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>;
|
||||
|
||||
class Either;
|
||||
using EitherPointer = boost::intrusive_ptr<Either>;
|
||||
|
||||
class Exists;
|
||||
using ExistsPointer = boost::intrusive_ptr<Exists>;
|
||||
|
||||
class ForAll;
|
||||
using ForAllPointer = boost::intrusive_ptr<ForAll>;
|
||||
|
||||
class Imply;
|
||||
using ImplyPointer = boost::intrusive_ptr<Imply>;
|
||||
|
||||
class Not;
|
||||
using NotPointer = boost::intrusive_ptr<Not>;
|
||||
|
||||
class Or;
|
||||
using OrPointer = boost::intrusive_ptr<Or>;
|
||||
|
||||
class Predicate;
|
||||
using PredicatePointer = boost::intrusive_ptr<Predicate>;
|
||||
using Predicates = std::vector<PredicatePointer>;
|
||||
|
||||
class PredicateDeclaration;
|
||||
using PredicateDeclarationPointer = boost::intrusive_ptr<PredicateDeclaration>;
|
||||
using PredicateDeclarations = std::vector<PredicateDeclarationPointer>;
|
||||
|
||||
class PrimitiveType;
|
||||
using PrimitiveTypePointer = boost::intrusive_ptr<PrimitiveType>;
|
||||
using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
|
||||
|
||||
class Quantified;
|
||||
using QuantifiedPointer = boost::intrusive_ptr<Quantified>;
|
||||
|
||||
template<class Type>
|
||||
class Reference;
|
||||
template<class Type>
|
||||
using ReferencePointer = boost::intrusive_ptr<Reference<Type>>;
|
||||
|
||||
class Unsupported;
|
||||
using UnsupportedPointer = boost::intrusive_ptr<Unsupported>;
|
||||
|
||||
class Variable;
|
||||
using VariablePointer = boost::intrusive_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
|
||||
class When;
|
||||
using WhenPointer = boost::intrusive_ptr<When>;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Expression
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
And,
|
||||
At,
|
||||
Binary,
|
||||
Constant,
|
||||
DerivedPredicate,
|
||||
Dummy,
|
||||
Either,
|
||||
Exists,
|
||||
ForAll,
|
||||
Imply,
|
||||
Not,
|
||||
Or,
|
||||
PredicateDeclaration,
|
||||
Predicate,
|
||||
PrimitiveType,
|
||||
Reference,
|
||||
Unsupported,
|
||||
Variable,
|
||||
When,
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~Expression() = default;
|
||||
|
||||
virtual Type expressionType() const = 0;
|
||||
|
||||
template<class T>
|
||||
bool is() const;
|
||||
template<class T>
|
||||
T &as();
|
||||
template<class T>
|
||||
const T &as() const;
|
||||
|
||||
virtual ExpressionPointer copy();
|
||||
|
||||
// Transform into a normal form as used for the translation to ASP
|
||||
ExpressionPointer normalized();
|
||||
// Reduce the set of used expressions (eliminates implications, for instance)
|
||||
virtual ExpressionPointer reduced();
|
||||
// Transform such that only existential (and no universal) quantifiers are used
|
||||
virtual ExpressionPointer existentiallyQuantified();
|
||||
// Simplify the expression equivalently
|
||||
virtual ExpressionPointer simplified();
|
||||
// Decompose expression into derived predicates (eliminate recursively nested expressions)
|
||||
virtual ExpressionPointer decomposed(expressions::DerivedPredicates &derivedPredicates);
|
||||
// Negate the expression
|
||||
ExpressionPointer negated();
|
||||
|
||||
virtual void collectParameters(std::set<expressions::VariablePointer> ¶meters);
|
||||
|
||||
virtual void print(std::ostream &ostream) const = 0;
|
||||
|
||||
private:
|
||||
friend void intrusive_ptr_add_ref(Expression *expression);
|
||||
friend void intrusive_ptr_release(Expression *expression);
|
||||
|
||||
size_t m_referenceCount = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
bool Expression::is() const
|
||||
{
|
||||
return expressionType() == T::ExpressionType;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
T &Expression::as()
|
||||
{
|
||||
return dynamic_cast<T &>(*this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
const T &Expression::as() const
|
||||
{
|
||||
return dynamic_cast<const T &>(*this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void intrusive_ptr_add_ref(Expression *expression)
|
||||
{
|
||||
expression->m_referenceCount++;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void intrusive_ptr_release(Expression *expression)
|
||||
{
|
||||
if (--expression->m_referenceCount == 0)
|
||||
delete expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class ExpressionCRTP: public Expression
|
||||
{
|
||||
public:
|
||||
Type expressionType() const override final
|
||||
{
|
||||
return Derived::ExpressionType;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer parseLiteral(Context &context, ExpressionContext &expressionContext);
|
||||
ExpressionPointer parseAtomicFormula(Context &context, ExpressionContext &expressionContext);
|
||||
|
||||
ExpressionPointer parsePreconditionExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
ExpressionPointer parseExpression(Context &context, ExpressionContext &expressionContext);
|
||||
|
||||
ExpressionPointer parseEffectExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
ExpressionPointer parseConditionalEffectExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,39 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION_CONTEXT_H
|
||||
#define __PLASP__PDDL__EXPRESSION_CONTEXT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/VariableStack.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ExpressionContext
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ExpressionContext
|
||||
{
|
||||
public:
|
||||
ExpressionContext(Domain &domain);
|
||||
ExpressionContext(Domain &domain, Problem *problem);
|
||||
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void checkRequirement(Requirement::Type requirementType) const;
|
||||
|
||||
Domain &domain;
|
||||
Problem *problem;
|
||||
|
||||
VariableStack variables;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,45 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__IO_H
|
||||
#define __PLASP__PDDL__IO_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/pddl/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IO
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void skipSection(Tokenizer &tokenizer)
|
||||
{
|
||||
size_t openParentheses = 1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const auto character = tokenizer.currentCharacter();
|
||||
tokenizer.advance();
|
||||
|
||||
if (character == '(')
|
||||
openParentheses++;
|
||||
else if (character == ')')
|
||||
{
|
||||
openParentheses--;
|
||||
|
||||
if (openParentheses == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,35 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// InitialState
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class InitialState
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<InitialState> parseDeclaration(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
public:
|
||||
const Expressions &facts() const;
|
||||
|
||||
private:
|
||||
Expressions m_facts;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,87 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__PROBLEM_H
|
||||
#define __PLASP__PDDL__PROBLEM_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/InitialState.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Problem
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Problem
|
||||
{
|
||||
public:
|
||||
Problem(Context &context, Domain &domain);
|
||||
|
||||
void findSections();
|
||||
void parse();
|
||||
|
||||
Domain &domain();
|
||||
const Domain &domain() const;
|
||||
|
||||
const std::string &name() const;
|
||||
|
||||
const Requirements &requirements() const;
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void checkRequirement(Requirement::Type requirementType);
|
||||
|
||||
expressions::Constants &objects();
|
||||
const expressions::Constants &objects() const;
|
||||
|
||||
InitialState &initialState();
|
||||
const InitialState &initialState() const;
|
||||
|
||||
const Expression &goal() const;
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
void normalize();
|
||||
|
||||
private:
|
||||
void parseRequirementSection();
|
||||
void computeDerivedRequirements();
|
||||
|
||||
void parseDomainSection();
|
||||
|
||||
void parseObjectSection();
|
||||
|
||||
void parseInitialStateSection();
|
||||
|
||||
void parseGoalSection();
|
||||
|
||||
Context &m_context;
|
||||
Domain &m_domain;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
tokenize::StreamPosition m_domainPosition;
|
||||
|
||||
tokenize::StreamPosition m_requirementsPosition;
|
||||
Requirements m_requirements;
|
||||
|
||||
tokenize::StreamPosition m_objectsPosition;
|
||||
expressions::Constants m_objects;
|
||||
|
||||
tokenize::StreamPosition m_initialStatePosition;
|
||||
std::unique_ptr<InitialState> m_initialState;
|
||||
|
||||
tokenize::StreamPosition m_goalPosition;
|
||||
ExpressionPointer m_goal;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,72 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__REQUIREMENT_H
|
||||
#define __PLASP__PDDL__REQUIREMENT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Requirement
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Requirement;
|
||||
using Requirements = std::vector<Requirement>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Requirement
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
STRIPS,
|
||||
Typing,
|
||||
NegativePreconditions,
|
||||
DisjunctivePreconditions,
|
||||
Equality,
|
||||
ExistentialPreconditions,
|
||||
UniversalPreconditions,
|
||||
QuantifiedPreconditions,
|
||||
ConditionalEffects,
|
||||
Fluents,
|
||||
NumericFluents,
|
||||
ObjectFluents,
|
||||
ADL,
|
||||
DurativeActions,
|
||||
DurationInequalities,
|
||||
ContinuousEffects,
|
||||
DerivedPredicates,
|
||||
TimedInitialLiterals,
|
||||
Preferences,
|
||||
Constraints,
|
||||
ActionCosts,
|
||||
GoalUtilities
|
||||
};
|
||||
|
||||
static Requirement parse(Context &context);
|
||||
|
||||
public:
|
||||
Requirement(Type type);
|
||||
|
||||
Type type() const;
|
||||
|
||||
std::string toPDDL() const;
|
||||
std::string toASP() const;
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,54 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__TOKENIZER_H
|
||||
#define __PLASP__PDDL__TOKENIZER_H
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Tokenizer
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PDDLTokenizerPolicy
|
||||
{
|
||||
public:
|
||||
static char transformCharacter(char c) noexcept
|
||||
{
|
||||
return std::tolower(c);
|
||||
}
|
||||
|
||||
static bool isWhiteSpaceCharacter(char c)
|
||||
{
|
||||
return std::iswspace(c);
|
||||
}
|
||||
|
||||
static bool isBlankCharacter(char c)
|
||||
{
|
||||
return std::isblank(c);
|
||||
}
|
||||
|
||||
static bool isIdentifierCharacter(char c)
|
||||
{
|
||||
return c != '?'
|
||||
&& c != '('
|
||||
&& c != ')'
|
||||
&& c != ';'
|
||||
&& std::isgraph(c);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Tokenizer = tokenize::Tokenizer<PDDLTokenizerPolicy>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,9 +1,10 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATOR_ASP_H
|
||||
#define __PLASP__PDDL__TRANSLATOR_ASP_H
|
||||
|
||||
#include <plasp/pddl/Description.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace pddl
|
||||
class TranslatorASP
|
||||
{
|
||||
public:
|
||||
explicit TranslatorASP(Description &description, output::ColorStream &outputStream);
|
||||
explicit TranslatorASP(const ::pddl::ast::Description &description, output::ColorStream &outputStream);
|
||||
|
||||
void translate() const;
|
||||
|
||||
@@ -27,15 +28,14 @@ class TranslatorASP
|
||||
void translateDomain() const;
|
||||
void translateTypes() const;
|
||||
void translatePredicates() const;
|
||||
void translateDerivedPredicates() const;
|
||||
void translateActions() const;
|
||||
|
||||
void translateProblem() const;
|
||||
void translateInitialState() const;
|
||||
void translateGoal() const;
|
||||
void translateConstants(const std::string &heading, const expressions::Constants &constants) const;
|
||||
void translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const;
|
||||
|
||||
Description &m_description;
|
||||
const ::pddl::ast::Description &m_description;
|
||||
output::ColorStream &m_outputStream;
|
||||
};
|
||||
|
||||
|
@@ -1,34 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__VARIABLE_STACK_H
|
||||
#define __PLASP__PDDL__VARIABLE_STACK_H
|
||||
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// VariableStack
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class VariableStack
|
||||
{
|
||||
public:
|
||||
void push(expressions::Variables *variables);
|
||||
void pop();
|
||||
|
||||
expressions::VariablePointer parseAndFind(Context &context);
|
||||
|
||||
private:
|
||||
std::vector<expressions::Variables *> m_variableStack;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,36 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__AND_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__AND_H
|
||||
|
||||
#include <plasp/pddl/expressions/NAry.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// And
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class And: public NAry<And>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::And;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,112 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__AT_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__AT_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// At
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class At: public ExpressionCRTP<At>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::At;
|
||||
|
||||
template<typename ExpressionParser>
|
||||
static AtPointer parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression);
|
||||
|
||||
static const size_t TimePointStart = std::numeric_limits<size_t>::max();
|
||||
static const size_t TimePointEnd = std::numeric_limits<size_t>::max() - 1;
|
||||
|
||||
public:
|
||||
At();
|
||||
|
||||
ExpressionPointer copy() override;
|
||||
|
||||
size_t timePoint() const;
|
||||
|
||||
void setArgument(ExpressionPointer argument);
|
||||
ExpressionPointer argument() const;
|
||||
|
||||
ExpressionPointer reduced() override;
|
||||
ExpressionPointer existentiallyQuantified() override;
|
||||
ExpressionPointer simplified() override;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
protected:
|
||||
size_t m_timePoint;
|
||||
|
||||
ExpressionPointer m_argument;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ExpressionParser>
|
||||
AtPointer At::parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip("at"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t timePoint;
|
||||
|
||||
const auto timePointPosition = tokenizer.position();
|
||||
|
||||
if (tokenizer.testIdentifierAndSkip("start"))
|
||||
timePoint = TimePointStart;
|
||||
else if (tokenizer.testIdentifierAndSkip("end"))
|
||||
timePoint = TimePointEnd;
|
||||
else if (tokenizer.probeNumber())
|
||||
{
|
||||
tokenizer.seek(timePointPosition);
|
||||
timePoint = tokenizer.get<size_t>();
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = AtPointer(new At);
|
||||
|
||||
expression->m_timePoint = timePoint;
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
// Parse argument
|
||||
expression->setArgument(parseExpression(context, expressionContext));
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,195 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__BINARY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__BINARY_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
#include <plasp/pddl/expressions/Exists.h>
|
||||
#include <plasp/pddl/expressions/ForAll.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Binary
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class Binary: public ExpressionCRTP<Derived>
|
||||
{
|
||||
public:
|
||||
template<typename ExpressionParser>
|
||||
static boost::intrusive_ptr<Derived> parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
ExpressionPointer copy() override;
|
||||
|
||||
void setArgument(size_t i, ExpressionPointer argument);
|
||||
std::array<ExpressionPointer, 2> &arguments();
|
||||
const std::array<ExpressionPointer, 2> &arguments() const;
|
||||
|
||||
ExpressionPointer reduced() override;
|
||||
ExpressionPointer existentiallyQuantified() override;
|
||||
ExpressionPointer simplified() override;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
protected:
|
||||
std::array<ExpressionPointer, 2> m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<typename ExpressionParser>
|
||||
boost::intrusive_ptr<Derived> Binary<Derived>::parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip(Derived::Identifier))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = boost::intrusive_ptr<Derived>(new Derived);
|
||||
|
||||
// Parse arguments of the expression
|
||||
expression->Binary<Derived>::setArgument(0, parseExpression(context, expressionContext));
|
||||
expression->Binary<Derived>::setArgument(1, parseExpression(context, expressionContext));
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
ExpressionPointer Binary<Derived>::copy()
|
||||
{
|
||||
auto result = new Derived;
|
||||
|
||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||
result->m_arguments[i] = m_arguments[i]->copy();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
void Binary<Derived>::setArgument(size_t i, ExpressionPointer expression)
|
||||
{
|
||||
BOOST_ASSERT_MSG(i <= m_arguments.size(), "Index out of range");
|
||||
|
||||
m_arguments[i] = expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
std::array<ExpressionPointer, 2> &Binary<Derived>::arguments()
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const std::array<ExpressionPointer, 2> &Binary<Derived>::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer Binary<Derived>::reduced()
|
||||
{
|
||||
for (auto &argument : m_arguments)
|
||||
{
|
||||
BOOST_ASSERT(argument);
|
||||
|
||||
argument = argument->reduced();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer Binary<Derived>::existentiallyQuantified()
|
||||
{
|
||||
for (auto &argument : m_arguments)
|
||||
{
|
||||
BOOST_ASSERT(argument);
|
||||
|
||||
argument = argument->existentiallyQuantified();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer Binary<Derived>::simplified()
|
||||
{
|
||||
for (auto &argument : m_arguments)
|
||||
{
|
||||
BOOST_ASSERT(argument);
|
||||
|
||||
argument = argument->simplified();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline void Binary<Derived>::collectParameters(std::set<VariablePointer> ¶meters)
|
||||
{
|
||||
for (const auto &argument : m_arguments)
|
||||
argument->collectParameters(parameters);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline void Binary<Derived>::print(std::ostream &ostream) const
|
||||
{
|
||||
ostream << "(" << Derived::Identifier;
|
||||
|
||||
std::for_each(m_arguments.begin(), m_arguments.end(),
|
||||
[&](auto &argument)
|
||||
{
|
||||
ostream << " ";
|
||||
argument->print(ostream);
|
||||
});
|
||||
|
||||
ostream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,64 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constant
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Constant: public ExpressionCRTP<Constant>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Constant;
|
||||
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain);
|
||||
static void parseTypedDeclarations(Context &context, Domain &domain);
|
||||
static void parseTypedDeclaration(Context &context, Problem &problem);
|
||||
static void parseTypedDeclarations(Context &context, Problem &problem);
|
||||
|
||||
static ConstantPointer parseAndFind(Context &context, const Domain &domain);
|
||||
static ConstantPointer parseAndFind(Context &context, const Problem &problem);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
PrimitiveTypePointer type() const;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
static ConstantPointer parseDeclaration(Context &context);
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
|
||||
|
||||
static ConstantPointer parseAndFind(const std::string &constantName, const Constants &constants);
|
||||
|
||||
Constant();
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setType(PrimitiveTypePointer parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
PrimitiveTypePointer m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,59 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__DERIVED_PREDICATE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__DERIVED_PREDICATE_H
|
||||
|
||||
#include <set>
|
||||
|
||||
#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:
|
||||
explicit DerivedPredicate(size_t id);
|
||||
|
||||
size_t id() const;
|
||||
|
||||
void setPreconditions(std::vector<Expressions> &&preconditions);
|
||||
const std::vector<Expressions> &preconditions() const;
|
||||
|
||||
const std::set<VariablePointer> ¶meters() const;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
void collectParameters();
|
||||
|
||||
size_t m_id;
|
||||
|
||||
// The arguments are interpreted as a disjunction of conjunctions
|
||||
std::vector<Expressions> m_preconditions;
|
||||
|
||||
std::set<VariablePointer> m_parameters;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,39 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__DUMMY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__DUMMY_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dummy
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Dummy: public ExpressionCRTP<Dummy>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Dummy;
|
||||
|
||||
public:
|
||||
Dummy(std::string name);
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,33 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__EITHER_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__EITHER_H
|
||||
|
||||
#include <plasp/pddl/expressions/NAry.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Either
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Either: public NAry<Either>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Either;
|
||||
|
||||
static const std::string Identifier;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,33 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__EXISTS_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__EXISTS_H
|
||||
|
||||
#include <plasp/pddl/expressions/Quantified.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Exists
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Exists: public QuantifiedCRTP<Exists>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Exists;
|
||||
|
||||
static const std::string Identifier;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,36 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__FOR_ALL_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__FOR_ALL_H
|
||||
|
||||
#include <plasp/pddl/expressions/Quantified.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ForAll
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ForAll: public QuantifiedCRTP<ForAll>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::ForAll;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer existentiallyQuantified() override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,36 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__IMPLY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__IMPLY_H
|
||||
|
||||
#include <plasp/pddl/expressions/Binary.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Imply
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Imply: public Binary<Imply>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Imply;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer reduced() override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,239 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__N_ARY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__N_ARY_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
#include <plasp/pddl/expressions/Exists.h>
|
||||
#include <plasp/pddl/expressions/ForAll.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// NAry
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class NAry: public ExpressionCRTP<Derived>
|
||||
{
|
||||
public:
|
||||
template<typename ExpressionParser>
|
||||
static boost::intrusive_ptr<Derived> parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
ExpressionPointer copy() override;
|
||||
|
||||
void setArgument(size_t i, ExpressionPointer argument);
|
||||
void addArgument(ExpressionPointer argument);
|
||||
Expressions &arguments();
|
||||
const Expressions &arguments() const;
|
||||
|
||||
ExpressionPointer reduced() override;
|
||||
ExpressionPointer existentiallyQuantified() override;
|
||||
ExpressionPointer simplified() override;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
protected:
|
||||
Expressions m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<typename ExpressionParser>
|
||||
boost::intrusive_ptr<Derived> NAry<Derived>::parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip(Derived::Identifier))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = boost::intrusive_ptr<Derived>(new Derived);
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
// Parse arguments of the expression
|
||||
while (tokenizer.currentCharacter() != ')')
|
||||
{
|
||||
expression->addArgument(parseExpression(context, expressionContext));
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
}
|
||||
|
||||
if (expression->m_arguments.empty())
|
||||
context.logger.log(output::Priority::Warning, tokenizer, "“" + Derived::Identifier + "” expressions should not be empty");
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
ExpressionPointer NAry<Derived>::copy()
|
||||
{
|
||||
auto result = new Derived;
|
||||
|
||||
result->m_arguments.resize(m_arguments.size());
|
||||
|
||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||
result->m_arguments[i] = m_arguments[i]->copy();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
void NAry<Derived>::setArgument(size_t i, ExpressionPointer expression)
|
||||
{
|
||||
BOOST_ASSERT_MSG(i <= m_arguments.size(), "Index out of range");
|
||||
|
||||
m_arguments[i] = expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
void NAry<Derived>::addArgument(ExpressionPointer argument)
|
||||
{
|
||||
if (!argument)
|
||||
return;
|
||||
|
||||
m_arguments.emplace_back(argument);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const Expressions &NAry<Derived>::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
Expressions &NAry<Derived>::arguments()
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer NAry<Derived>::reduced()
|
||||
{
|
||||
for (auto &argument : m_arguments)
|
||||
{
|
||||
BOOST_ASSERT(argument);
|
||||
|
||||
argument = argument->reduced();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer NAry<Derived>::existentiallyQuantified()
|
||||
{
|
||||
for (auto &argument : m_arguments)
|
||||
{
|
||||
BOOST_ASSERT(argument);
|
||||
|
||||
argument = argument->existentiallyQuantified();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer NAry<Derived>::simplified()
|
||||
{
|
||||
// Associate same-type children, such as (a && (b && c)) == (a && b && c)
|
||||
for (size_t i = 0; i < m_arguments.size();)
|
||||
{
|
||||
auto &argument = m_arguments[i];
|
||||
argument = argument->simplified();
|
||||
|
||||
if (argument->expressionType() != Derived::ExpressionType)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto &nAryExpression = argument->template as<Derived>();
|
||||
|
||||
BOOST_ASSERT(!nAryExpression.arguments().empty());
|
||||
|
||||
// Remove former child by replacing it with the first one of the child
|
||||
m_arguments[i] = nAryExpression.arguments().front();
|
||||
|
||||
// Reserve space for new arguments
|
||||
m_arguments.reserve(m_arguments.size() + nAryExpression.arguments().size() - 1);
|
||||
|
||||
// Copy all but first element
|
||||
m_arguments.insert(m_arguments.end(), nAryExpression.arguments().begin() + 1, nAryExpression.arguments().end());
|
||||
}
|
||||
|
||||
// TODO: recognize tautologies
|
||||
// TODO: introduce/handle boolean values
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline void NAry<Derived>::collectParameters(std::set<VariablePointer> ¶meters)
|
||||
{
|
||||
for (const auto &argument : m_arguments)
|
||||
argument->collectParameters(parameters);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline void NAry<Derived>::print(std::ostream &ostream) const
|
||||
{
|
||||
ostream << "(" << Derived::Identifier;
|
||||
|
||||
for (const auto &argument : m_arguments)
|
||||
{
|
||||
ostream << " ";
|
||||
argument->print(ostream);
|
||||
}
|
||||
|
||||
ostream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,85 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__NOT_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__NOT_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Not
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Not: public ExpressionCRTP<Not>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Not;
|
||||
|
||||
template<typename ExpressionParser>
|
||||
static NotPointer parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
Not();
|
||||
|
||||
ExpressionPointer copy() override;
|
||||
|
||||
void setArgument(ExpressionPointer argument);
|
||||
ExpressionPointer argument() const;
|
||||
|
||||
ExpressionPointer reduced() override;
|
||||
ExpressionPointer existentiallyQuantified() override;
|
||||
ExpressionPointer simplified() override;
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
protected:
|
||||
ExpressionPointer m_argument;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ExpressionParser>
|
||||
NotPointer Not::parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip("not"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = NotPointer(new Not);
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
// Parse argument
|
||||
expression->setArgument(parseExpression(context, expressionContext));
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,36 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__OR_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__OR_H
|
||||
|
||||
#include <plasp/pddl/expressions/NAry.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Or
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Or: public NAry<Or>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Or;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
public:
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,56 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__PREDICATE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PREDICATE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Predicate: public ExpressionCRTP<Predicate>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Predicate;
|
||||
|
||||
static PredicatePointer parse(Context &context, ExpressionContext &expressionContext);
|
||||
static PredicatePointer parse(Context &context, const Problem &problem);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Expressions &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
Predicate();
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
Expressions m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,53 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__PREDICATE_DECLARATION_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PREDICATE_DECLARATION_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PredicateDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PredicateDeclaration: public ExpressionCRTP<PredicateDeclaration>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::PredicateDeclaration;
|
||||
|
||||
static void parse(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Variables ¶meters() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
void normalizeParameterNames();
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
PredicateDeclaration();
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
Variables m_parameters;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,55 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PrimitiveType: public ExpressionCRTP<PrimitiveType>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::PrimitiveType;
|
||||
|
||||
static void parseDeclaration(Context &context, Domain &domain);
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain);
|
||||
|
||||
static PrimitiveTypePointer parseAndFind(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
PrimitiveType();
|
||||
PrimitiveType(std::string name);
|
||||
|
||||
const std::string &name() const;
|
||||
const PrimitiveTypes &parentTypes() const;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
PrimitiveTypes m_parentTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,250 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__QUANTIFIED_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__QUANTIFIED_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
#include <plasp/pddl/expressions/DerivedPredicate.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Quantified
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Quantified: public Expression
|
||||
{
|
||||
public:
|
||||
void setArgument(ExpressionPointer argument);
|
||||
ExpressionPointer argument() const;
|
||||
|
||||
Variables &variables();
|
||||
const Variables &variables() const;
|
||||
|
||||
protected:
|
||||
Variables m_variables;
|
||||
ExpressionPointer m_argument;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class QuantifiedCRTP: public Quantified
|
||||
{
|
||||
public:
|
||||
template<typename ExpressionParser>
|
||||
static boost::intrusive_ptr<Derived> parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
Type expressionType() const override final
|
||||
{
|
||||
return Derived::ExpressionType;
|
||||
}
|
||||
|
||||
ExpressionPointer copy() override;
|
||||
|
||||
ExpressionPointer reduced() override;
|
||||
ExpressionPointer existentiallyQuantified() override;
|
||||
ExpressionPointer simplified() override;
|
||||
ExpressionPointer decomposed(DerivedPredicates &derivedPredicates) override;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<typename ExpressionParser>
|
||||
boost::intrusive_ptr<Derived> QuantifiedCRTP<Derived>::parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip(Derived::Identifier))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = boost::intrusive_ptr<Derived>(new Derived);
|
||||
|
||||
// Parse variable list
|
||||
tokenizer.expect<std::string>("(");
|
||||
Variable::parseTypedDeclarations(context, expressionContext, expression->m_variables);
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
// Push newly parsed variables to the stack
|
||||
expressionContext.variables.push(&expression->m_variables);
|
||||
|
||||
// Parse argument of the expression
|
||||
expression->Quantified::setArgument(parseExpression(context, expressionContext));
|
||||
|
||||
// Clean up variable stack
|
||||
expressionContext.variables.pop();
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
ExpressionPointer QuantifiedCRTP<Derived>::copy()
|
||||
{
|
||||
auto result = new Derived;
|
||||
|
||||
result->m_argument = m_argument->copy();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void Quantified::setArgument(ExpressionPointer expression)
|
||||
{
|
||||
m_argument = expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ExpressionPointer Quantified::argument() const
|
||||
{
|
||||
return m_argument;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline Variables &Quantified::variables()
|
||||
{
|
||||
return m_variables;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline const Variables &Quantified::variables() const
|
||||
{
|
||||
return m_variables;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer QuantifiedCRTP<Derived>::reduced()
|
||||
{
|
||||
BOOST_ASSERT(m_argument);
|
||||
|
||||
m_argument = m_argument->reduced();
|
||||
|
||||
// Child quantifiers may not move before this quantifier, the order matters
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer QuantifiedCRTP<Derived>::existentiallyQuantified()
|
||||
{
|
||||
BOOST_ASSERT(m_argument);
|
||||
|
||||
m_argument = m_argument->existentiallyQuantified();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer QuantifiedCRTP<Derived>::simplified()
|
||||
{
|
||||
BOOST_ASSERT(m_argument);
|
||||
|
||||
m_argument = m_argument->simplified();
|
||||
|
||||
// Associate same-type children, such as (forall (?x) (forall (?y) (...)))
|
||||
if (m_argument->expressionType() != Derived::ExpressionType)
|
||||
return this;
|
||||
|
||||
auto &quantifiedExpression = m_argument->template as<Derived>();
|
||||
|
||||
// Unify variables
|
||||
m_variables.insert(m_variables.end(), quantifiedExpression.variables().begin(), quantifiedExpression.variables().end());
|
||||
|
||||
// Move child expression up
|
||||
m_argument = quantifiedExpression.argument();
|
||||
|
||||
// TODO: introduce/handle boolean values
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline ExpressionPointer QuantifiedCRTP<Derived>::decomposed(DerivedPredicates &derivedPredicates)
|
||||
{
|
||||
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
||||
auto derivedPredicate = derivedPredicates.back();
|
||||
|
||||
m_argument = m_argument->decomposed(derivedPredicates);
|
||||
|
||||
derivedPredicate->setPreconditions({{this}});
|
||||
|
||||
return derivedPredicate;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline void QuantifiedCRTP<Derived>::collectParameters(std::set<VariablePointer> ¶meters)
|
||||
{
|
||||
m_argument->collectParameters(parameters);
|
||||
|
||||
// Remove bound variables
|
||||
for (const auto &variable : m_variables)
|
||||
parameters.erase(variable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
inline void QuantifiedCRTP<Derived>::print(std::ostream &ostream) const
|
||||
{
|
||||
ostream << "(" << Derived::Identifier << " (";
|
||||
|
||||
for (size_t i = 0; i < m_variables.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
ostream << " ";
|
||||
|
||||
m_variables[i]->print(ostream);
|
||||
}
|
||||
|
||||
ostream << ") ";
|
||||
|
||||
m_argument->print(ostream);
|
||||
|
||||
ostream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,28 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__TYPE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__TYPE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Type
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PrimitiveTypePointer parseExistingPrimitiveType(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,42 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Unsupported
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Unsupported: public ExpressionCRTP<Unsupported>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Unsupported;
|
||||
|
||||
static UnsupportedPointer parse(Context &context);
|
||||
|
||||
public:
|
||||
const std::string &type() const;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
std::string m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,63 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__VARIABLE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__VARIABLE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Variable: public ExpressionCRTP<Variable>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Variable;
|
||||
|
||||
static void parseTypedDeclaration(Context &context, ExpressionContext &expressionContext,
|
||||
Variables &variables);
|
||||
static void parseTypedDeclarations(Context &context, ExpressionContext &expressionContext,
|
||||
Variables &variables);
|
||||
|
||||
public:
|
||||
Variable();
|
||||
Variable(std::string name);
|
||||
|
||||
void setName(std::string name);
|
||||
const std::string &name() const;
|
||||
|
||||
void setType(ExpressionPointer type);
|
||||
ExpressionPointer type() const;
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void collectParameters(std::set<VariablePointer> ¶meters) override;
|
||||
|
||||
void print(std::ostream &ostream) const override;
|
||||
|
||||
private:
|
||||
static void parseDeclaration(Context &context, Variables ¶meters);
|
||||
|
||||
private:
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
ExpressionPointer m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,67 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__WHEN_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__WHEN_H
|
||||
|
||||
#include <plasp/pddl/expressions/Binary.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// When
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class When: public Binary<When>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::When;
|
||||
|
||||
static const std::string Identifier;
|
||||
|
||||
template<typename ConditionExpressionParser, typename ImplicationExpressionParser>
|
||||
static WhenPointer parse(Context &context, ExpressionContext &expressionContext,
|
||||
ConditionExpressionParser parseConditionExpression,
|
||||
ImplicationExpressionParser parseImplicationExpression);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ConditionExpressionParser, typename ImplicationExpressionParser>
|
||||
WhenPointer When::parse(Context &context, ExpressionContext &expressionContext,
|
||||
ConditionExpressionParser parseConditionExpression,
|
||||
ImplicationExpressionParser parseImplicationExpression)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip(Identifier))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = WhenPointer(new When);
|
||||
|
||||
// Parse arguments of the expression
|
||||
expression->setArgument(0, parseConditionExpression(context, expressionContext));
|
||||
expression->setArgument(1, parseImplicationExpression(context, expressionContext));
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
79
include/plasp/pddl/translation/Effect.h
Normal file
79
include/plasp/pddl/translation/Effect.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__EFFECT_H
|
||||
#define __PLASP__PDDL__TRANSLATION__EFFECT_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Effect
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
inline void translateEffect(output::ColorStream &outputStream, const ::pddl::ast::Effect &effect, const std::string &objectType, PrintObjectName printObjectName)
|
||||
{
|
||||
const auto handleUnsupported =
|
||||
[](const auto &)
|
||||
{
|
||||
throw output::TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently");
|
||||
};
|
||||
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << output::Function("postcondition") << "(";
|
||||
printObjectName();
|
||||
outputStream
|
||||
<< ", " << output::Keyword("effect") << "("
|
||||
<< output::Reserved("unconditional") << ")"
|
||||
<< ", ";
|
||||
translatePredicateToVariable(outputStream, *predicate, isPositive);
|
||||
outputStream << ") :- " << output::Function(objectType.c_str()) << "(";
|
||||
printObjectName();
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleUnsupported);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::Effect> ¬_)
|
||||
{
|
||||
if (!not_->argument.is<::pddl::ast::AtomicFormula>() || !not_->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
||||
handleUnsupported(not_);
|
||||
|
||||
const auto &predicate = not_->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
||||
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::ast::AndPointer<::pddl::ast::Effect> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
translateEffect(outputStream, argument, objectType, printObjectName);
|
||||
};
|
||||
|
||||
effect.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
72
include/plasp/pddl/translation/Goal.h
Normal file
72
include/plasp/pddl/translation/Goal.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__GOAL_H
|
||||
#define __PLASP__PDDL__TRANSLATION__GOAL_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Goal
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateGoal(output::ColorStream &outputStream, const ::pddl::ast::Goal &goal)
|
||||
{
|
||||
const auto handleUnsupported =
|
||||
[](const auto &)
|
||||
{
|
||||
throw output::TranslatorException("only “and” expressions and (negated) predicates supported as goals currently");
|
||||
};
|
||||
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << output::Function("goal") << "(";
|
||||
// TODO: assert that goal is variable-free
|
||||
translatePredicateToVariable(outputStream, *predicate, isPositive);
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleUnsupported);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::Goal> ¬_)
|
||||
{
|
||||
if (!not_->argument.is<::pddl::ast::AtomicFormula>() || !not_->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
||||
handleUnsupported(not_);
|
||||
|
||||
const auto &predicate = not_->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
||||
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::ast::AndPointer<::pddl::ast::Goal> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
translateGoal(outputStream, argument);
|
||||
};
|
||||
|
||||
goal.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,16 +1,18 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PRECONDITION_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PRECONDITION_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/pddl/Description.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace translation
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -18,57 +20,56 @@ namespace translation
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class PrintObjectName>
|
||||
void translatePreconditionDisjunction(output::ColorStream &outputStream, const std::string &objectType, PrintObjectName printObjectName, const std::vector<Expressions> &preconditionDisjunction);
|
||||
template<class PrintObjectName>
|
||||
void translatePreconditionConjunction(output::ColorStream &outputStream, const std::string &objectType, PrintObjectName printObjectName, size_t disjunctionID, const Expressions &preconditionConjunction);
|
||||
template<class PrintObjectName>
|
||||
void translatePrecondition(output::ColorStream &outputStream, const std::string &objectType, PrintObjectName printObjectName, size_t disjunctionID, const Expression &precondition);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class PrintObjectName>
|
||||
inline void translatePreconditionDisjunction(output::ColorStream &outputStream, const std::string &objectType, PrintObjectName printObjectName, const std::vector<Expressions> &preconditionDisjunction)
|
||||
template<typename PrintObjectName>
|
||||
inline void translatePrecondition(output::ColorStream &outputStream, const ::pddl::ast::Precondition &precondition, const std::string &objectType, PrintObjectName printObjectName)
|
||||
{
|
||||
for (size_t i = 0; i < preconditionDisjunction.size(); i++)
|
||||
translatePreconditionConjunction(outputStream, objectType, printObjectName, i, preconditionDisjunction[i]);
|
||||
const auto handleUnsupported =
|
||||
[](const auto &)
|
||||
{
|
||||
throw output::TranslatorException("only “and” expressions and (negated) predicates supported as action preconditions currently");
|
||||
};
|
||||
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << output::Function("precondition") << "(";
|
||||
printObjectName();
|
||||
outputStream << ", ";
|
||||
translatePredicateToVariable(outputStream, *predicate, isPositive);
|
||||
outputStream << ") :- " << output::Function(objectType.c_str()) << "(";
|
||||
printObjectName();
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleUnsupported);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::Precondition> ¬_)
|
||||
{
|
||||
if (!not_->argument.is<::pddl::ast::AtomicFormula>() || !not_->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
||||
handleUnsupported(not_);
|
||||
|
||||
const auto &predicate = not_->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
||||
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::ast::AndPointer<::pddl::ast::Precondition> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
translatePrecondition(outputStream, argument, objectType, printObjectName);
|
||||
};
|
||||
|
||||
precondition.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class PrintObjectName>
|
||||
inline void translatePreconditionConjunction(output::ColorStream &outputStream, const std::string &objectType, PrintObjectName printObjectName, size_t disjunctionID, const Expressions &preconditionConjunction)
|
||||
{
|
||||
for (size_t i = 0; i < preconditionConjunction.size(); i++)
|
||||
translatePrecondition(outputStream, objectType, printObjectName, disjunctionID, *preconditionConjunction[i]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class PrintObjectName>
|
||||
inline void translatePrecondition(output::ColorStream &outputStream, const std::string &objectType, PrintObjectName printObjectName, size_t disjunctionID, const Expression &precondition)
|
||||
{
|
||||
outputStream << std::endl << output::Function("precondition") << "(";
|
||||
|
||||
printObjectName(outputStream);
|
||||
|
||||
outputStream
|
||||
<< ", " << output::Keyword("disjunct")
|
||||
<< "(" << output::Number<decltype(disjunctionID)>(disjunctionID)
|
||||
<< "), ";
|
||||
|
||||
translateLiteral(outputStream, precondition);
|
||||
|
||||
outputStream << ") :- " << output::Function(objectType.c_str()) << "(";
|
||||
|
||||
printObjectName(outputStream);
|
||||
|
||||
outputStream << ").";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,20 +1,18 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PREDICATE_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PREDICATE_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
#include <plasp/pddl/expressions/DerivedPredicate.h>
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
#include <plasp/pddl/translation/Variables.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace translation
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -22,44 +20,46 @@ namespace translation
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void translatePredicate(output::ColorStream &outputStream, const expressions::Predicate &predicate);
|
||||
void translateDerivedPredicate(output::ColorStream &outputStream, const expressions::DerivedPredicate &derivedPredicate);
|
||||
void printPredicateName(output::ColorStream &outputStream, const expressions::PredicateDeclaration &predicateDeclaration);
|
||||
void printDerivedPredicateName(output::ColorStream &outputStream, const expressions::DerivedPredicate &derivedPredicate);
|
||||
void translatePredicate(output::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate);
|
||||
void translatePredicateDeclaration(output::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translatePredicate(output::ColorStream &outputStream, const expressions::Predicate &predicate)
|
||||
inline void translatePredicate(output::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate)
|
||||
{
|
||||
const auto &arguments = predicate.arguments();
|
||||
const auto &arguments = predicate.arguments;
|
||||
|
||||
if (arguments.empty())
|
||||
{
|
||||
outputStream << output::String(predicate.name().c_str());
|
||||
|
||||
outputStream << *predicate.declaration;
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << output::String(predicate.name().c_str());
|
||||
outputStream << "(" << *predicate.declaration;
|
||||
|
||||
for (const auto &argument : arguments)
|
||||
{
|
||||
outputStream << ", ";
|
||||
|
||||
if (argument->is<expressions::Constant>())
|
||||
{
|
||||
const auto &constant = argument->as<expressions::Constant>();
|
||||
const auto handleConstant =
|
||||
[&](const ::pddl::ast::ConstantPointer &constant)
|
||||
{
|
||||
outputStream << output::Keyword("constant") << "(" << *constant << ")";
|
||||
};
|
||||
|
||||
outputStream << output::Keyword("constant") << "(" << output::String(constant.name().c_str()) << ")";
|
||||
}
|
||||
else if (argument->is<expressions::Variable>())
|
||||
{
|
||||
const auto &variable = argument->as<expressions::Variable>();
|
||||
const auto handleVariable =
|
||||
[&](const ::pddl::ast::VariablePointer &variable)
|
||||
{
|
||||
outputStream << *variable;
|
||||
};
|
||||
|
||||
outputStream << output::Variable(variable.name().c_str());
|
||||
}
|
||||
else
|
||||
throw output::TranslatorException("only variables and constants supported in predicates currently");
|
||||
const auto handleUnsupported =
|
||||
[&](const auto &)
|
||||
{
|
||||
throw output::TranslatorException("only variables and constants supported in predicates currently");
|
||||
};
|
||||
|
||||
argument.match(handleConstant, handleVariable, handleUnsupported);
|
||||
}
|
||||
|
||||
outputStream << ")";
|
||||
@@ -67,64 +67,41 @@ inline void translatePredicate(output::ColorStream &outputStream, const expressi
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateDerivedPredicate(output::ColorStream &outputStream, const expressions::DerivedPredicate &derivedPredicate)
|
||||
{
|
||||
const auto ¶meters = derivedPredicate.parameters();
|
||||
const auto id = derivedPredicate.id();
|
||||
|
||||
if (parameters.empty())
|
||||
{
|
||||
outputStream << output::Number<decltype(id)>(id);
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << output::Number<decltype(id)>(id);
|
||||
|
||||
for (const auto ¶meter : parameters)
|
||||
outputStream << ", " << output::Variable(parameter->name().c_str());
|
||||
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void printPredicateName(output::ColorStream &outputStream, const expressions::PredicateDeclaration &predicateDeclaration)
|
||||
inline void translatePredicateDeclaration(output::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration)
|
||||
{
|
||||
outputStream << output::Keyword("variable") << "(";
|
||||
|
||||
if (predicateDeclaration.parameters().empty())
|
||||
if (predicateDeclaration.parameters.empty())
|
||||
{
|
||||
outputStream << output::String(predicateDeclaration.name().c_str()) << ")";
|
||||
outputStream << predicateDeclaration << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << output::String(predicateDeclaration.name().c_str());
|
||||
translation::translateVariablesForRuleHead(outputStream, predicateDeclaration.parameters());
|
||||
outputStream << "(" << predicateDeclaration;
|
||||
translateVariablesForRuleHead(outputStream, predicateDeclaration.parameters);
|
||||
outputStream << "))";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void printDerivedPredicateName(output::ColorStream &outputStream, const expressions::DerivedPredicate &derivedPredicate)
|
||||
void translatePredicateToVariable(output::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << output::Keyword("derivedVariable") << "(";
|
||||
outputStream << output::Keyword("variable") << "(";
|
||||
translatePredicate(outputStream, predicate);
|
||||
outputStream << "), " << output::Keyword("value") << "(";
|
||||
translatePredicate(outputStream, predicate);
|
||||
outputStream << ", ";
|
||||
|
||||
const auto id = derivedPredicate.id();
|
||||
if (isPositive)
|
||||
outputStream << output::Boolean("true");
|
||||
else
|
||||
outputStream << output::Boolean("false");
|
||||
|
||||
if (derivedPredicate.parameters().empty())
|
||||
{
|
||||
outputStream << output::Number<decltype(id)>(id) << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << output::Number<decltype(id)>(id);
|
||||
translation::translateVariablesForRuleHead(outputStream, derivedPredicate.parameters());
|
||||
outputStream << "))";
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,19 +1,15 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PRIMITIVES_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PRIMITIVES_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
#include <plasp/pddl/Description.h>
|
||||
#include <plasp/pddl/expressions/Not.h>
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace translation
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -21,56 +17,91 @@ namespace translation
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void translateLiteral(output::ColorStream &outputStream, const Expression &literal);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateLiteral(output::ColorStream &outputStream, const Expression &literal)
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::ConstantDeclaration &constantDeclaration)
|
||||
{
|
||||
// Translate single predicate
|
||||
if (literal.is<expressions::Predicate>())
|
||||
{
|
||||
const auto &predicate = literal.as<expressions::Predicate>();
|
||||
assert(!constantDeclaration.name.empty());
|
||||
|
||||
outputStream << output::Keyword("variable") << "(";
|
||||
translation::translatePredicate(outputStream, predicate);
|
||||
outputStream << "), " << output::Keyword("value") << "(";
|
||||
translation::translatePredicate(outputStream, predicate);
|
||||
outputStream << ", " << output::Boolean("true") << ")";
|
||||
}
|
||||
// Assuming that "not" expression may only contain a predicate
|
||||
else if (literal.is<expressions::Not>())
|
||||
{
|
||||
const auto ¬Expression = literal.as<expressions::Not>();
|
||||
|
||||
if (notExpression.argument()->expressionType() != Expression::Type::Predicate)
|
||||
throw output::TranslatorException("only negations of primitive predicates supported as literals currently");
|
||||
|
||||
const auto &predicate = notExpression.argument()->as<expressions::Predicate>();
|
||||
|
||||
outputStream << output::Keyword("variable") << "(";
|
||||
translation::translatePredicate(outputStream, predicate);
|
||||
outputStream << "), " << output::Keyword("value") << "(";
|
||||
translation::translatePredicate(outputStream, predicate);
|
||||
outputStream << ", " << output::Boolean("false") << ")";
|
||||
}
|
||||
else if (literal.is<expressions::DerivedPredicate>())
|
||||
{
|
||||
const auto &derivedPredicate = literal.as<expressions::DerivedPredicate>();
|
||||
|
||||
outputStream << output::Keyword("derivedVariable") << "(";
|
||||
translation::translateDerivedPredicate(outputStream, derivedPredicate);
|
||||
outputStream << "), " << output::Keyword("value") << "(";
|
||||
translation::translateDerivedPredicate(outputStream, derivedPredicate);
|
||||
outputStream << ", " << output::Boolean("true") << ")";
|
||||
}
|
||||
else
|
||||
throw output::TranslatorException("only primitive predicates and their negations supported as literals currently");
|
||||
return (stream << output::String(constantDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::Constant &constant)
|
||||
{
|
||||
assert(constant.declaration != nullptr);
|
||||
|
||||
return (stream << *constant.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::PrimitiveTypeDeclaration &primitiveTypeDeclaration)
|
||||
{
|
||||
assert(!primitiveTypeDeclaration.name.empty());
|
||||
|
||||
return (stream << output::String(primitiveTypeDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::PrimitiveType &primitiveType)
|
||||
{
|
||||
assert(primitiveType.declaration != nullptr);
|
||||
|
||||
return (stream << *primitiveType.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, ::pddl::ast::VariableDeclaration &variableDeclaration)
|
||||
{
|
||||
assert(!variableDeclaration.name.empty());
|
||||
assert(std::isalpha(variableDeclaration.name[0]));
|
||||
|
||||
if (!std::isupper(variableDeclaration.name[0]))
|
||||
variableDeclaration.name[0] = std::toupper(variableDeclaration.name[0]);
|
||||
|
||||
return (stream
|
||||
<< output::Format({output::Color::Green, output::FontWeight::Bold})
|
||||
<< variableDeclaration.name
|
||||
<< output::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, ::pddl::ast::Variable &variable)
|
||||
{
|
||||
assert(variable.declaration != nullptr);
|
||||
|
||||
return (stream << *variable.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::Action &action)
|
||||
{
|
||||
return (stream << output::String(action.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration)
|
||||
{
|
||||
return (stream << output::String(predicateDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline output::ColorStream &operator<<(output::ColorStream &stream, const ::pddl::ast::Predicate &predicate)
|
||||
{
|
||||
return (stream << *predicate.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLES_H
|
||||
#define __PLASP__PDDL__TRANSLATION__VARIABLES_H
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/Parse.h>
|
||||
|
||||
#include <plasp/output/Formatting.h>
|
||||
#include <plasp/output/TranslatorException.h>
|
||||
|
||||
@@ -8,8 +11,6 @@ namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace translation
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -30,12 +31,8 @@ inline void translateVariablesForRuleHead(output::ColorStream &outputStream, con
|
||||
if (variables.empty())
|
||||
return;
|
||||
|
||||
for (auto i = variables.cbegin(); i != variables.cend(); i++)
|
||||
{
|
||||
const auto &variable = **i;
|
||||
|
||||
outputStream << ", " << output::Variable(variable.name().c_str());
|
||||
}
|
||||
for (const auto &variable : variables)
|
||||
outputStream << ", " << *variable;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -48,28 +45,25 @@ inline void translateVariablesForRuleBody(output::ColorStream &outputStream, con
|
||||
|
||||
outputStream << " :- ";
|
||||
|
||||
for (auto i = variables.cbegin(); i != variables.cend(); i++)
|
||||
for (const auto &variable : variables)
|
||||
{
|
||||
const auto &variable = **i;
|
||||
|
||||
if (i != variables.cbegin())
|
||||
if (variable.get() != variables.begin()->get())
|
||||
outputStream << ", ";
|
||||
|
||||
if (variable.type() != nullptr)
|
||||
if (variable->type)
|
||||
{
|
||||
if (variable.type()->expressionType() != Expression::Type::PrimitiveType)
|
||||
if (!variable->type.value().template is<::pddl::ast::PrimitiveTypePointer>())
|
||||
throw output::TranslatorException("only primitive types supported currently");
|
||||
|
||||
const auto &type = variable.type()->template as<expressions::PrimitiveType>();
|
||||
const auto &type = variable->type.value().template get<::pddl::ast::PrimitiveTypePointer>();
|
||||
|
||||
outputStream << output::Function("has") << "("
|
||||
<< output::Variable(variable.name().c_str()) << ", "
|
||||
<< output::Keyword("type") << "(" << output::String(type.name().c_str()) << "))";
|
||||
<< *variable << ", " << output::Keyword("type") << "(" << *type << "))";
|
||||
}
|
||||
else
|
||||
{
|
||||
outputStream << output::Function("has") << "("
|
||||
<< output::Variable(variable.name().c_str()) << ", "
|
||||
<< *variable << ", "
|
||||
<< output::Keyword("type") << "(" << output::String("object") << "))";
|
||||
}
|
||||
}
|
||||
@@ -77,7 +71,6 @@ inline void translateVariablesForRuleBody(output::ColorStream &outputStream, con
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user