Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial pass on quantified conditions. #50

Merged
merged 8 commits into from
Nov 21, 2022
Merged

Initial pass on quantified conditions. #50

merged 8 commits into from
Nov 21, 2022

Conversation

haz
Copy link
Contributor

@haz haz commented Nov 17, 2022

Proposed changes

Support for quantified conditions. Closes #40 . Also added support for universal conditions.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have read the CONTRIBUTING doc
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

Further comments

None!

@haz
Copy link
Contributor Author

haz commented Nov 17, 2022

Code I've been using to test things out:

def test1():
    from pddl.formatter import domain_to_string, problem_to_string
    from pddl.parser.domain import DomainParser
    from pddl.parser.problem import ProblemParser

    dom_text = """(define (domain my_domain)
        (:requirements :strips :typing :quantified-preconditions)
        (:types type_1)
        (:constants a b c)
        (:predicates (p1 ?x - type_1 ?y - type_1 ?z - type_1)  (p2 ?x - type_1 ?y - type_1))
        (:action action-1
            :parameters (?x - type_1 ?y - type_1 )
            ;:precondition (and (forall (?z - type_1) (p1 ?x ?y ?x)))
            ;:precondition (and (forall (?z - type_1) (p1 ?x ?y ?z)))
            :precondition (and (forall (?z - type_1) (p1 ?x ?y ?z)) (exists (?z - type_1) (not (p2 ?y ?z))))
            :effect (p2 ?x ?y)
        )
    )"""

    print(domain_to_string(DomainParser()(dom_text)))

def test2():
    from pddl.logic import Predicate, constants, variables
    from pddl.core import Domain, Problem, Action, Requirements
    from pddl.formatter import domain_to_string, problem_to_string
    from pddl.logic.base import ForallCondition

    # set up variables and constants
    x, y, z, z2 = variables("x y z z2", types=["type_1"])
    a, b, c = constants("a b c", types=["type_1"])

    # define predicates
    p1 = Predicate("p1", x, y, z)
    p2 = Predicate("p2", x, y)

    # define actions
    a1 = Action(
        "action-1",
        parameters=[x, y, z],
        precondition=ForallCondition(p2(y,z2) & p1(x, y, z) & ~p2(y, z), [z2]),
        effect=p2(y, z)
    )

    # define the domain object.
    requirements = [Requirements.STRIPS, Requirements.TYPING]
    domain = Domain("my_domain",
        requirements=requirements,
        types=["type_1"],
        constants=[a, b, c],
        predicates=[p1, p2],
        actions=[a1])

    print(domain_to_string(domain))

test1()
test2()

@haz haz marked this pull request as draft November 17, 2022 05:49
@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2022

Codecov Report

Merging #50 (7bae013) into main (50ecfd4) will decrease coverage by 0.29%.
The diff coverage is 74.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #50      +/-   ##
==========================================
- Coverage   87.34%   87.04%   -0.30%     
==========================================
  Files          19       19              
  Lines         964     1027      +63     
  Branches       94      102       +8     
==========================================
+ Hits          842      894      +52     
- Misses         97      104       +7     
- Partials       25       29       +4     
Flag Coverage Δ
unittests 87.04% <74.02%> (-0.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pddl/parser/domain.py 79.89% <59.37%> (-0.11%) ⬇️
pddl/logic/base.py 85.61% <82.05%> (-1.43%) ⬇️
pddl/core.py 92.41% <100.00%> (+0.16%) ⬆️
pddl/parser/symbols.py 100.00% <100.00%> (ø)

@haz haz marked this pull request as ready for review November 18, 2022 04:55
Copy link
Collaborator

@francescofuggitti francescofuggitti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, thanks!

@haz
Copy link
Contributor Author

haz commented Nov 20, 2022

So this good to merge, or is there something else you'd like to see?

Copy link
Member

@marcofavorito marcofavorito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't reviewed the PR carefully, but it looks good, thank you!

@haz haz merged commit 7228c27 into AI-Planning:main Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Existential Preconditions
4 participants