JuliaPlanners / PDDL.jl

Julia parser, interpreter and compiler interface for the Planning Domain Definition Language (PDDL). Planners not included.
https://juliaplanners.github.io/PDDL.jl/dev
Apache License 2.0
80 stars 9 forks source link

Confusion over the `_extras` field of `Domain` #9

Closed wmanning-cra closed 2 years ago

wmanning-cra commented 2 years ago

We are experimenting with hierarchical PDDL planning, using an extension that adds "Methods" to the domain alongside actions. I noticed a field in the domain called _extras, which seems to hold parsed data that doesn't fit into the other known fields (actions, requirements, types, constants, etc.). This would be useful

However, when I parse a domain containing methods, I can't find them within the structure. Is this a bug with _extras, or am I misunderstanding it (and do I need to add custom parsing logic to handle methods)?

https://www.uni-ulm.de/fileadmin/website_uni_ulm/iui.inst.090/Publikationen/2020/Hoeller2020HDDL.pdf

Here is an example of the syntax for a method:

(:method my_method
    :parameters (?a - T1)
    :precondition (P1 ?a)
    :task (t_pursue_main_goal)
    :ordered-subtasks (and
        (action_1 ?a b c)
        (action_2 ?a)
    )
)

There are also new fields in the Problem as well, so I guess I have the same question for the Problem struct.

ztangent commented 2 years ago

Yes, you'll need to add custom parsing logic. Consider referring to how action definitions are currently parsed: https://github.com/JuliaPlanners/PDDL.jl/blob/a46d3be2c2d7523999aa5b334ffebd957fcb347c/src/parser/domain.jl#L109-L119

You first have to write a function, e.g. parse_method that takes in a Expr that is returned by the parse_string function at the end of https://github.com/JuliaPlanners/PDDL.jl/blob/master/src/parser/grammar.jl. After that, you have to tell that :method is a field that exists in the body of a :domain description by adding something like:

body_field_parsers[:domain][:method] = parse_method

Once you do this, the list of parsed methods should appear as a Vector in the domain._extras dictionary.

At some point, I'll document in more detail how one can extend the parser, but in the meantime I'd suggest looking at how things are currently implemented.

As for new fields in problems, you'll have to either modify the definition of GenericProblem to have something similar to an _extras field, or to add new explicit fields, or define a new concrete subtype of Problem that contains all the fields you care about.

wmanning-cra commented 2 years ago

Thank you for the info! I guess we can consider this issue closed.