hfoffani / pddl-lib

A PDDL library that parse PDDL files and provides a very simple interface to interact with domain-problems.
Apache License 2.0
82 stars 20 forks source link

Support for durative-action #23

Open franzlst opened 6 years ago

franzlst commented 6 years ago

There is an issue with durative-action. I created the following minimal test domain:

(define (domain test-domain)
    (:requirements :strips :typing :durative-actions :fluents :timed-initial-literals)

    (:action test
        :parameters (?a)
        :effect ()
    )

    (:durative-action test2
        :parameters (?a)
        :duration (= ?duration 1)
        :condition ()
        :effect ()
    )
)

I parse it with the following code:

inp = FileStream("testdomain.pddl")
lexer = pddlLexer(inp)
stream = CommonTokenStream(lexer)
parser = pddlParser(stream)
tree = parser.domain()
domain = DomainListener()
walker = ParseTreeWalker()
walker.walk(domain, tree)

This causes the following exception:

Traceback (most recent call last):
  File "/home/stei_fn/.PyCharm2018.1/config/scratches/scratch_13.py", line 25, in <module>
    walker.walk(domain, tree)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/antlr4/tree/Tree.py", line 151, in walk
    self.walk(listener, child)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/antlr4/tree/Tree.py", line 151, in walk
    self.walk(listener, child)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/antlr4/tree/Tree.py", line 151, in walk
    self.walk(listener, child)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/antlr4/tree/Tree.py", line 149, in walk
    self.enterRule(listener, t)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/antlr4/tree/Tree.py", line 163, in enterRule
    ctx.enterRule(listener)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/pddlpy/pddlParser.py", line 1818, in enterRule
    listener.enterTypedVariableList(self)
  File "/home/stei_fn/.local_leap/lib/python3.4/site-packages/pddlpy/pddl.py", line 116, in enterTypedVariableList
    self.scopes[-1].variable_list[v.getText()] = None
IndexError: list index out of range

I used PyCharm for debugging and discovered the following. The action scope is successfully parsed. The exception occures, when the parameter scope of the duractive-action is to be parsed. The list of scopes is empty, which I think means the duractive-action scope has not been parsed successfully.

I had a look at the source code of pddl.py. The class DomainListener has methods enterActionDef / exitActionDef. I would expect corresponding methods for durative-actions, but there is no enterDurativeActionDef / exitDurativeActionDef. So I guess this is the root of this issue.

Could you please fix this? I am very happy that I found this Python package, as it look very useful to me. Yet, this issue prevents me from using it.

(I am using the latest release on PyPi, 0.1.9).

franzlst commented 6 years ago

There are probably more methods that need to be implemented:

Here is an extended durative-action, which I would like to parse:

(:durative-action pick
        :parameters (?obj - thing ?manip - manipulator ?loc - location)
        :duration (= ?duration 40)
        :condition
            (and
                (at start (clear ?obj))
                (at start (at ?obj ?loc))
                (at start (not (at ?obj ?manip)))
                (over all (closeto ?loc ?manip)))
        :effect
            (and
                (at end (holding ?obj ?manip) )
                (at end (not (clear ?obj)))
                (at start (at ?obj ?manip))
                (at start (not (at ?obj ?loc)))
            )
    )
hfoffani commented 6 years ago

Thanks for trying pddl-lib.

I'm sorry Franz, buy this implementation currently only supports the strips definition. The library should report any non-supported flag in the requirements field so users can see right away the (limited) scope of the library. There's a long standing bug that I've never find the time to fix. My apologies.

There are many other feature subsets that are not implemented yet also requested by other users. Any PR is very welcome.

franzlst commented 6 years ago

Thanks for your fast feedback. Here's your pull request: #24 :smile:

I don't know whether you really want to merge it, as it makes non-backward compatible changes. The description describes the coarse changes.

hfoffani commented 6 years ago

Wow, thanks a lot! I'll take a look. Looks very promising!