Skip to content

Commit

Permalink
Merge pull request #12 from Timisorean/non-deterministic-new
Browse files Browse the repository at this point in the history
Non deterministic
  • Loading branch information
drexlerd authored Oct 2, 2024
2 parents a3d1da3 + 83bbf9b commit c79b38f
Show file tree
Hide file tree
Showing 30 changed files with 464 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ build
*.exe
*.out
*.app

dependencies
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Loki is a C++20 library for syntactic and semantic parsing of PDDL files.
- [ ] :preferences
- [ ] :constraints
- [x] :action-costs
- [x] :non-deterministic


## Dependencies
Expand Down
73 changes: 73 additions & 0 deletions data/blocks-non-deterministic/domain-missing-requirement.pddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(define (domain blocks-domain)

(:requirements :negative-preconditions :equality :typing)

(:types
block
)

(:predicates
(holding-one)
(holding-two)
(holding ?b - block)
(emptyhand)
(on-table ?b - block)
(on ?b1 ?b2 - block)
(clear ?b - block)
)

(:action pick-up
:parameters (?b1 ?b2 - block)
:precondition (and (not (= ?b1 ?b2)) (emptyhand) (clear ?b1) (on ?b1 ?b2))
:effect (and (clear ?b2) (not (on ?b1 ?b2))
(oneof
(and (holding-one) (holding ?b1) (not (emptyhand)) (not (clear ?b1)))
(on-table ?b1)))
)

(:action pick-up-from-table
:parameters (?b - block)
:precondition (and (emptyhand) (clear ?b) (on-table ?b))
:effect (oneof
(and)
(and (holding-one) (holding ?b) (not (emptyhand)) (not (on-table ?b)) (not (clear ?b))))
)

(:action put-on-block
:parameters (?b1 ?b2 - block)
:precondition (and (not (= ?b1 ?b2)) (holding-one) (holding ?b1) (clear ?b2))
:effect (and (emptyhand) (clear ?b1) (not (holding-one)) (not (holding ?b1))
(oneof
(and (on ?b1 ?b2) (not (clear ?b2)))
(on-table ?b1)))
)

(:action put-down
:parameters (?b - block)
:precondition (and (holding-one) (holding ?b))
:effect (and (on-table ?b) (emptyhand) (clear ?b) (not (holding-one)) (not (holding ?b)))
)

(:action pick-tower
:parameters (?b1 ?b2 ?b3 - block)
:precondition (and (emptyhand) (on ?b1 ?b2) (on ?b2 ?b3) (clear ?b1))
:effect (oneof
(and)
(and (holding-two) (holding ?b2) (clear ?b3) (not (emptyhand)) (not (on ?b2 ?b3)) (not (clear ?b1))))
)

(:action put-tower-on-block
:parameters (?b1 ?b2 ?b3 - block)
:precondition (and (holding-two) (holding ?b2) (on ?b1 ?b2) (clear ?b3))
:effect (and (emptyhand) (not (holding-two)) (not (holding ?b2)) (clear ?b1)
(oneof
(and (on ?b2 ?b3) (not (clear ?b3)))
(and (on-table ?b1) (on-table ?b2) (clear ?b2) (not (on ?b1 ?b2)))))
)

(:action put-tower-down
:parameters (?b1 ?b2 - block)
:precondition (and (holding-two) (holding ?b2) (on ?b1 ?b2))
:effect (and (on-table ?b2) (emptyhand) (not (holding-two)) (not (holding ?b2)) (clear ?b1))
)
)
73 changes: 73 additions & 0 deletions data/blocks-non-deterministic/domain.pddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(define (domain blocks-domain)

(:requirements :non-deterministic :negative-preconditions :equality :typing)

(:types
block
)

(:predicates
(holding-one)
(holding-two)
(holding ?b - block)
(emptyhand)
(on-table ?b - block)
(on ?b1 ?b2 - block)
(clear ?b - block)
)

(:action pick-up
:parameters (?b1 ?b2 - block)
:precondition (and (not (= ?b1 ?b2)) (emptyhand) (clear ?b1) (on ?b1 ?b2))
:effect (and (clear ?b2) (not (on ?b1 ?b2))
(oneof
(and (holding-one) (holding ?b1) (not (emptyhand)) (not (clear ?b1)))
(on-table ?b1)))
)

(:action pick-up-from-table
:parameters (?b - block)
:precondition (and (emptyhand) (clear ?b) (on-table ?b))
:effect (oneof
(and)
(and (holding-one) (holding ?b) (not (emptyhand)) (not (on-table ?b)) (not (clear ?b))))
)

(:action put-on-block
:parameters (?b1 ?b2 - block)
:precondition (and (not (= ?b1 ?b2)) (holding-one) (holding ?b1) (clear ?b2))
:effect (and (emptyhand) (clear ?b1) (not (holding-one)) (not (holding ?b1))
(oneof
(and (on ?b1 ?b2) (not (clear ?b2)))
(on-table ?b1)))
)

(:action put-down
:parameters (?b - block)
:precondition (and (holding-one) (holding ?b))
:effect (and (on-table ?b) (emptyhand) (clear ?b) (not (holding-one)) (not (holding ?b)))
)

(:action pick-tower
:parameters (?b1 ?b2 ?b3 - block)
:precondition (and (emptyhand) (on ?b1 ?b2) (on ?b2 ?b3) (clear ?b1))
:effect (oneof
(and)
(and (holding-two) (holding ?b2) (clear ?b3) (not (emptyhand)) (not (on ?b2 ?b3)) (not (clear ?b1))))
)

(:action put-tower-on-block
:parameters (?b1 ?b2 ?b3 - block)
:precondition (and (holding-two) (holding ?b2) (on ?b1 ?b2) (clear ?b3))
:effect (and (emptyhand) (not (holding-two)) (not (holding ?b2)) (clear ?b1)
(oneof
(and (on ?b2 ?b3) (not (clear ?b3)))
(and (on-table ?b1) (on-table ?b2) (clear ?b2) (not (on ?b1 ?b2)))))
)

(:action put-tower-down
:parameters (?b1 ?b2 - block)
:precondition (and (holding-two) (holding ?b2) (on ?b1 ?b2))
:effect (and (on-table ?b2) (emptyhand) (not (holding-two)) (not (holding ?b2)) (clear ?b1))
)
)
6 changes: 6 additions & 0 deletions data/blocks-non-deterministic/p20.pddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(define (problem bw_10_20)
(:domain blocks-domain)
(:objects b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 - block)
(:init (emptyhand) (on b1 b6) (on b2 b8) (on-table b3) (on b4 b9) (on b5 b3) (on b6 b10) (on b7 b5) (on-table b8) (on b9 b1) (on b10 b2) (clear b4) (clear b7))
(:goal (and (emptyhand) (on b1 b9) (on b2 b1) (on-table b3) (on-table b4) (on-table b5) (on b6 b7) (on-table b7) (on-table b8) (on b9 b6) (on b10 b3) (clear b2) (clear b4) (clear b5) (clear b8) (clear b10)))
)
36 changes: 24 additions & 12 deletions include/loki/details/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct RequirementTimedInitialLiterals;
struct RequirementPreferences;
struct RequirementConstraints;
struct RequirementActionCosts;
struct RequirementNonDeterministic;
struct Requirement;

struct Type;
Expand Down Expand Up @@ -152,9 +153,10 @@ struct EffectProductionLiteral;
struct EffectProductionNumericFluentTotalCost;
struct EffectProductionNumericFluentGeneral;
struct EffectProduction;
struct EffectConditionalForall;
struct EffectConditionalWhen;
struct EffectConditional;
struct EffectCompositeForall;
struct EffectCompositeWhen;
struct EffectCompositeOneof;
struct EffectComposite;
struct EffectNumericFluentTotalCostOrEffect;
struct EffectRoot;

Expand Down Expand Up @@ -341,6 +343,10 @@ struct RequirementActionCosts : x3::position_tagged
{
};

struct RequirementNonDeterministic : x3::position_tagged
{
};

struct Requirement :
x3::position_tagged,
x3::variant<RequirementStrips,
Expand All @@ -361,7 +367,8 @@ struct Requirement :
RequirementTimedInitialLiterals,
RequirementPreferences,
RequirementConstraints,
RequirementActionCosts>
RequirementActionCosts,
RequirementNonDeterministic>
{
using base_type::base_type;
using base_type::operator=;
Expand Down Expand Up @@ -822,14 +829,14 @@ struct AssignOperator :
// <p-effect>
// struct EffectRoot :
// x3::position_tagged,
// x3::variant<x3::forward_ast<EffectProduction>, x3::forward_ast<EffectConditional>, x3::forward_ast<EffectProductionNumericFluentTotalCost>>,
// x3::variant<x3::forward_ast<EffectProduction>, x3::forward_ast<EffectComposite>, x3::forward_ast<EffectProductionNumericFluentTotalCost>>,
// std::vector<x3::variant<EffectProductionNumericFluentTotalCost, Effect>>>
//{
// using base_type::base_type;
// using base_type::operator=;
//};

struct Effect : x3::position_tagged, x3::variant<x3::forward_ast<EffectProduction>, x3::forward_ast<EffectConditional>, std::vector<Effect>>
struct Effect : x3::position_tagged, x3::variant<x3::forward_ast<EffectProduction>, x3::forward_ast<EffectComposite>, std::vector<Effect>>
{
using base_type::base_type;
using base_type::operator=;
Expand Down Expand Up @@ -860,19 +867,24 @@ struct EffectProduction : x3::position_tagged, x3::variant<EffectProductionLiter
using base_type::operator=;
};

struct EffectConditionalForall : x3::position_tagged
struct EffectCompositeForall : x3::position_tagged
{
TypedListOfVariables typed_list_of_variables;
Effect effect;
};

struct EffectConditionalWhen : x3::position_tagged
struct EffectCompositeWhen : x3::position_tagged
{
GoalDescriptor goal_descriptor;
Effect effect;
};

struct EffectConditional : x3::position_tagged, x3::variant<EffectConditionalForall, EffectConditionalWhen>
struct EffectCompositeOneof : x3::position_tagged
{
std::vector<Effect> possibilities;
};

struct EffectComposite : x3::position_tagged, x3::variant<EffectCompositeForall, EffectCompositeWhen, EffectCompositeOneof>
{
using base_type::base_type;
using base_type::operator=;
Expand All @@ -884,9 +896,9 @@ struct EffectNumericFluentTotalCostOrEffect : x3::position_tagged, x3::variant<E
using base_type::operator=;
};

struct EffectRoot :
struct EffectRoot:
x3::position_tagged,
x3::variant<EffectProduction, EffectConditional, EffectProductionNumericFluentTotalCost, std::vector<EffectNumericFluentTotalCostOrEffect>>
x3::variant<EffectProduction, EffectComposite, EffectProductionNumericFluentTotalCost, std::vector<EffectNumericFluentTotalCostOrEffect>>
{
using base_type::base_type;
using base_type::operator=;
Expand Down Expand Up @@ -1216,4 +1228,4 @@ struct Problem : x3::position_tagged
};
}

#endif
#endif
10 changes: 6 additions & 4 deletions include/loki/details/ast/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern std::string parse_text(const ast::RequirementTimedInitialLiterals& node,
extern std::string parse_text(const ast::RequirementPreferences& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::RequirementConstraints& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::RequirementActionCosts& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::RequirementNonDeterministic& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::Requirement& node, const DefaultFormatterOptions& options = {});

extern std::string parse_text(const ast::Type& node, const DefaultFormatterOptions& options = {});
Expand Down Expand Up @@ -152,9 +153,10 @@ extern std::string parse_text(const ast::EffectProductionLiteral& node, const De
extern std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectProduction& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectConditionalForall& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectConditionalWhen& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectConditional& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectCompositeForall& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectCompositeWhen& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectCompositeOneof& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectComposite& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const DefaultFormatterOptions& options = {});
extern std::string parse_text(const ast::EffectRoot& node, const DefaultFormatterOptions& options = {});

Expand Down Expand Up @@ -226,4 +228,4 @@ extern std::string parse_text(const ast::MetricSpecification& node, const Defaul
extern std::string parse_text(const ast::Problem& node, const DefaultFormatterOptions& options = {});
}

#endif
#endif
12 changes: 7 additions & 5 deletions include/loki/details/pddl/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ class EffectAndImpl;
using EffectAnd = const EffectAndImpl*;
class EffectNumericImpl;
using EffectNumeric = const EffectNumericImpl*;
class EffectConditionalForallImpl;
using EffectConditionalForall = const EffectConditionalForallImpl*;
class EffectConditionalWhenImpl;
using EffectConditionalWhen = const EffectConditionalWhenImpl*;
using EffectImpl = std::variant<EffectLiteralImpl, EffectAndImpl, EffectNumericImpl, EffectConditionalForallImpl, EffectConditionalWhenImpl>;
class EffectCompositeForallImpl;
using EffectCompositeForall = const EffectCompositeForallImpl*;
class EffectCompositeWhenImpl;
using EffectCompositeWhen = const EffectCompositeWhenImpl*;
class EffectCompositeOneofImpl;
using EffectCompositeOneof = const EffectCompositeOneofImpl*;
using EffectImpl = std::variant<EffectLiteralImpl, EffectAndImpl, EffectNumericImpl, EffectCompositeForallImpl, EffectCompositeWhenImpl, EffectCompositeOneofImpl>;
using Effect = const EffectImpl*;
using EffectList = std::vector<Effect>;

Expand Down
Loading

0 comments on commit c79b38f

Please sign in to comment.