Skip to content

Commit

Permalink
fixed parsing of derived predicates and axioms
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Apr 12, 2024
1 parent 0c064cc commit 0a562eb
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 305 deletions.
10 changes: 7 additions & 3 deletions Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
include(CMakeFindDependencyMacro)


##############################################################
# Debug prints
##############################################################

message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")


##############################################################
# CMake modules and macro files
##############################################################
Expand All @@ -16,11 +23,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/cmake/configure_boost.cmake")

# Boost
# Find Boost headers only according to https://cmake.org/cmake/help/latest/module/FindBoost.html
message("PACKAGE_PREFIX_DIR: ${PACKAGE_PREFIX_DIR}")
message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
configure_boost()
find_dependency(Boost ${BOOST_MIN_VERSION} REQUIRED PATHS ${CMAKE_PREFIX_PATH} NO_DEFAULT_PATH)

if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
message(STATUS "Found Boost: ${Boost_DIR} (found version ${Boost_VERSION})")
Expand Down
2 changes: 1 addition & 1 deletion cmake/configure_boost.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(Boost_NO_SYSTEM_PATHS ON)
macro(configure_boost)
set(BOOST_MIN_VERSION "1.84.0")
set(BOOST_MIN_VERSION "1.74.0")
endmacro()
52 changes: 3 additions & 49 deletions include/loki/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct FunctionSymbol;
struct Term;
struct Number;
struct Predicate;
struct DerivedPredicate; // ok

struct RequirementStrips;
struct RequirementTyping;
Expand Down Expand Up @@ -74,7 +73,6 @@ struct TypedListOfVariablesRecursively; // :typing
struct TypedListOfVariables;

struct AtomicFormulaSkeleton;
struct DerivedAtomicFormulaSkeleton; // ok

struct AtomicFunctionSkeletonTotalCost;
struct AtomicFunctionSkeletonGeneral;
Expand All @@ -89,11 +87,6 @@ struct Atom;
struct NegatedAtom;
struct Literal;

struct DerivedAtomicFormulaOfTerms; // new
struct DerivedAtom; // new
struct DerivedNegatedAtom; // new
struct DerivedLiteral; // new

struct MultiOperatorMul;
struct MultiOperatorPlus;
struct MultiOperator;
Expand All @@ -117,8 +110,7 @@ struct FunctionExpressionHead;

struct GoalDescriptor;
struct GoalDescriptorAtom;
struct GoalDescriptorLiteral; // :negative-preconditions
struct GoalDescriptorDerivedLiteral; // new
struct GoalDescriptorLiteral; // :negative-preconditions
struct GoalDescriptorAnd;
struct GoalDescriptorOr; // :disjunctive-preconditions
struct GoalDescriptorNot; // :disjunctive-preconditions
Expand Down Expand Up @@ -271,11 +263,6 @@ struct Predicate : x3::position_tagged
Name name;
};

struct DerivedPredicate : x3::position_tagged
{
Name name;
};

/* <require-def> */
struct RequirementStrips : x3::position_tagged
{
Expand Down Expand Up @@ -441,12 +428,6 @@ struct AtomicFormulaSkeleton : x3::position_tagged
TypedListOfVariables typed_list_of_variables;
};

struct DerivedAtomicFormulaSkeleton : x3::position_tagged
{
DerivedPredicate derived_predicate;
TypedListOfVariables typed_list_of_variables;
};

/* <function typed list (atomic function skeleton)> */
struct AtomicFunctionSkeletonTotalCost : x3::position_tagged
{
Expand Down Expand Up @@ -516,28 +497,6 @@ struct Literal : x3::position_tagged, x3::variant<Atom, NegatedAtom>
using base_type::operator=;
};

struct DerivedAtomicFormulaOfTerms : x3::position_tagged
{
DerivedPredicate derived_predicate;
std::vector<Term> terms;
};

struct DerivedAtom : x3::position_tagged
{
DerivedAtomicFormulaOfTerms derived_atomic_formula_of_terms;
};

struct DerivedNegatedAtom : x3::position_tagged
{
DerivedAtomicFormulaOfTerms derived_atomic_formula_of_terms;
};

struct DerivedLiteral : x3::position_tagged, x3::variant<DerivedAtom, DerivedNegatedAtom>
{
using base_type::base_type;
using base_type::operator=;
};

/* Operators */
struct MultiOperatorMul : x3::position_tagged
{
Expand Down Expand Up @@ -661,11 +620,6 @@ struct GoalDescriptorLiteral : x3::position_tagged
Literal literal;
};

struct GoalDescriptorDerivedLiteral : x3::position_tagged
{
DerivedLiteral derived_literal;
};

struct GoalDescriptorAnd : x3::position_tagged
{
std::vector<GoalDescriptor> goal_descriptors;
Expand Down Expand Up @@ -938,7 +892,7 @@ struct Action : x3::position_tagged
/* <derived-def> */
struct Axiom : x3::position_tagged
{
DerivedLiteral derived_literal;
Literal literal;
GoalDescriptor goal_descriptor;
};

Expand All @@ -962,7 +916,7 @@ struct Predicates : x3::position_tagged

struct DerivedPredicates : x3::position_tagged
{
std::vector<DerivedAtomicFormulaSkeleton> derived_atomic_formula_skeletons;
std::vector<AtomicFormulaSkeleton> atomic_formula_skeletons;
};

/* <functions-def> */
Expand Down
7 changes: 0 additions & 7 deletions include/loki/ast/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern std::string parse_text(const ast::Number& node, const FormattingOptions&
extern std::string parse_text(const ast::FunctionSymbol& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::Term& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::Predicate& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::DerivedPredicate& node, const FormattingOptions& options = {});

extern std::string parse_text(const ast::RequirementStrips& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::RequirementTyping& node, const FormattingOptions& options = {});
Expand Down Expand Up @@ -67,7 +66,6 @@ extern std::string parse_text(const ast::TypedListOfVariablesRecursively& node,
extern std::string parse_text(const ast::TypedListOfVariables& node, const FormattingOptions& options = {});

extern std::string parse_text(const ast::AtomicFormulaSkeleton& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::DerivedAtomicFormulaSkeleton& node, const FormattingOptions& options = {});

extern std::string parse_text(const ast::AtomicFunctionSkeletonTotalCost& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::AtomicFunctionSkeletonGeneral& node, const FormattingOptions& options = {});
Expand All @@ -81,10 +79,6 @@ extern std::string parse_text(const ast::AtomicFormulaOfTerms& node, const Forma
extern std::string parse_text(const ast::Atom& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::NegatedAtom& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::Literal& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::DerivedAtomicFormulaOfTerms& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::DerivedAtom& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::DerivedNegatedAtom& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::DerivedLiteral& node, const FormattingOptions& options = {});

extern std::string parse_text(const ast::MultiOperatorMul& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::MultiOperatorPlus& node, const FormattingOptions& options = {});
Expand All @@ -110,7 +104,6 @@ extern std::string parse_text(const ast::FunctionExpressionHead& node, const For
extern std::string parse_text(const ast::GoalDescriptor& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::GoalDescriptorAtom& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::GoalDescriptorLiteral& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::GoalDescriptorDerivedLiteral& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::GoalDescriptorAnd& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::GoalDescriptorOr& node, const FormattingOptions& options = {});
extern std::string parse_text(const ast::GoalDescriptorNot& node, const FormattingOptions& options = {});
Expand Down
6 changes: 3 additions & 3 deletions include/loki/pddl/axiom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ namespace loki::pddl
class AxiomImpl : public Base<AxiomImpl>
{
private:
Condition m_condition;
Literal m_literal;
Condition m_condition;

AxiomImpl(int identifier, Condition condition, Literal literal);
AxiomImpl(int identifier, Literal literal, Condition condition);

// Give access to the constructor.
friend class loki::PDDLFactory<AxiomImpl, loki::Hash<AxiomImpl*>, loki::EqualTo<AxiomImpl*>>;
Expand All @@ -52,8 +52,8 @@ class AxiomImpl : public Base<AxiomImpl>
friend class Base<AxiomImpl>;

public:
const Condition& get_condition() const;
const Literal& get_literal() const;
const Condition& get_condition() const;
};

}
Expand Down
1 change: 1 addition & 0 deletions include/loki/pddl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct Context
ReferencedPDDLObjects references;
// For convenience, to avoid an additional parameter during semantic parsing
pddl::Requirements requirements;
std::unordered_set<pddl::Predicate> derived_predicates;

Context(PDDLFactories& factories_, PDDLPositionCache& positions_, ScopeStack& scopes_) :
factories(factories_),
Expand Down
6 changes: 6 additions & 0 deletions include/loki/pddl/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ class MismatchedFunctionSkeletonTermListError : public SemanticParserError
const std::string& error_handler_output);
};

class DerivedPredicateInEffectError : public SemanticParserError
{
public:
DerivedPredicateInEffectError(const std::string& name, const std::string& error_handler_output);
};

/* Object */
class UnusedObjectError : public SemanticParserError
{
Expand Down
8 changes: 0 additions & 8 deletions include/loki/pddl/factories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,10 @@ struct PDDLFactories
AtomFactory atoms;
AtomFactory derived_atoms;
GroundAtomFactory ground_atoms;
GroundAtomFactory derived_ground_atoms;
LiteralFactory literals;
LiteralFactory derived_literals;
GroundLiteralFactory ground_literals;
GroundLiteralFactory derived_ground_literals;
ParameterFactory parameters;
PredicateFactory predicates;
PredicateFactory derived_predicates;
FunctionExpressionFactory function_expressions;
FunctionFactory functions;
FunctionSkeletonFactory function_skeletons;
Expand All @@ -135,14 +131,10 @@ struct PDDLFactories
atoms(AtomFactory(1000)),
derived_atoms(AtomFactory(1000)),
ground_atoms(GroundAtomFactory(1000)),
derived_ground_atoms(GroundAtomFactory(1000)),
literals(LiteralFactory(1000)),
derived_literals(LiteralFactory(1000)),
ground_literals(GroundLiteralFactory(1000)),
derived_ground_literals(GroundLiteralFactory(1000)),
parameters(ParameterFactory(1000)),
predicates(PredicateFactory(1000)),
derived_predicates(PredicateFactory(1000)),
function_expressions(FunctionExpressionFactory(1000)),
functions(FunctionFactory(1000)),
function_skeletons(FunctionSkeletonFactory(1000)),
Expand Down
10 changes: 2 additions & 8 deletions src/ast/ast_adapted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::Name, characters)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Variable, characters)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionSymbol, name)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Predicate, name)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedPredicate, name)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Number, value)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::TypeEither, types)
Expand All @@ -42,7 +41,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::TypedListOfNamesRecursively, names, type, t
BOOST_FUSION_ADAPT_STRUCT(loki::ast::TypedListOfVariablesRecursively, variables, type, typed_list_of_variables)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFormulaSkeleton, predicate, typed_list_of_variables)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedAtomicFormulaSkeleton, derived_predicate, typed_list_of_variables)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFunctionSkeletonTotalCost, function_symbol)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFunctionSkeletonGeneral, function_symbol, arguments)
Expand All @@ -55,9 +53,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFormulaOfTermsPredicate, predicate, t
BOOST_FUSION_ADAPT_STRUCT(loki::ast::AtomicFormulaOfTermsEquality, term_left, term_right)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Atom, atomic_formula_of_terms)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::NegatedAtom, atomic_formula_of_terms)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedAtomicFormulaOfTerms, derived_predicate, terms)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedAtom, derived_atomic_formula_of_terms)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedNegatedAtom, derived_atomic_formula_of_terms)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionHead, function_symbol, terms)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionExpressionNumber, number)
Expand All @@ -67,7 +62,6 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::FunctionExpressionHead, function_head)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorAtom, atom)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorLiteral, literal)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorDerivedLiteral, derived_literal)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorAnd, goal_descriptors)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorOr, goal_descriptors)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::GoalDescriptorNot, goal_descriptor)
Expand Down Expand Up @@ -105,14 +99,14 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::ActionSymbol, name)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::ActionBody, precondition_goal_descriptor, effect)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Action, action_symbol, typed_list_of_variables, action_body)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::Axiom, derived_literal, goal_descriptor)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Axiom, literal, goal_descriptor)

BOOST_FUSION_ADAPT_STRUCT(loki::ast::DomainName, name)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Requirements, requirements)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Types, typed_list_of_names)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Constants, typed_list_of_names)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Predicates, atomic_formula_skeletons)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedPredicates, derived_atomic_formula_skeletons)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::DerivedPredicates, atomic_formula_skeletons)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Functions, function_types_list_of_atomic_function_skeletons)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Constraints, constraint_goal_descriptor)
BOOST_FUSION_ADAPT_STRUCT(loki::ast::Domain, domain_name, requirements, types, constants, predicates, derived_predicates, functions, constraints, structures)
Expand Down
Loading

0 comments on commit 0a562eb

Please sign in to comment.