Skip to content

Commit

Permalink
fix hierarchical typing edge case (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsilver authored Oct 17, 2023
1 parent 7aa8f59 commit fba285d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 11 additions & 3 deletions predicators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2806,9 +2806,17 @@ def create_pddl_domain(operators: Collection[NSRTOrSTRIPSOperator],
for parent_type in sorted(parent_to_children_types):
child_types = parent_to_children_types[parent_type]
if not child_types:
continue
child_type_str = " ".join(t.name for t in child_types)
types_str += f"\n {child_type_str} - {parent_type.name}"
# Special case: type has no children and also does not appear
# as a child of another type.
is_child_type = any(
parent_type in children
for children in parent_to_children_types.values())
if not is_child_type:
types_str += f"\n {parent_type.name}"
# Otherwise, the type will appear as a child elsewhere.
else:
child_type_str = " ".join(t.name for t in child_types)
types_str += f"\n {child_type_str} - {parent_type.name}"
ops_lst = sorted(operators)
preds_str = "\n ".join(pred.pddl_str() for pred in preds_lst)
ops_strs = "\n\n ".join(op.pddl_str() for op in ops_lst)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2318,12 +2318,16 @@ def test_create_pddl():
env = ProceduralTasksSpannerPDDLEnv()
nsrts = get_gt_nsrts(env.get_name(), env.predicates,
get_gt_options(env.get_name()))
domain_str = utils.create_pddl_domain(nsrts, env.predicates, env.types,
# Test case where there is a special type with no parents or children.
monkey_type = Type("monkey", [])
types = env.types | {monkey_type}
domain_str = utils.create_pddl_domain(nsrts, env.predicates, types,
"spanner")
assert domain_str == """(define (domain spanner)
(:requirements :typing)
(:types
man nut spanner - locatable
monkey
locatable location - object)
(:predicates
Expand Down

0 comments on commit fba285d

Please sign in to comment.