Fix: Plan instantiation not respecting types of action parameters#195
Fix: Plan instantiation not respecting types of action parameters#195RichardGubijev wants to merge 3 commits into
Conversation
|
For context on why this might be needed, I need the terms in the effects to be typed and to achieve that I've done it by looking up the items in the def type_action_list_terms(pddl_problem: Problem, actions: list[Action]):
new_actions = []
for action in actions:
new_actions.append(Action(action.name, action.parameters, type_formula_terms(pddl_problem, action.precondition), type_formula_terms(pddl_problem, action.effect)))
return new_actions
def type_formula_terms(problem: Problem, formula: Formula):
if isinstance(formula, And):
return And(*[type_formula_terms(problem, pred) for pred in formula._operands])
if isinstance(formula, Not):
return Not(type_predicate_terms(problem, formula.argument))
else:
return type_predicate_terms(problem, formula)
def type_predicate_terms(pddl_problem: Problem, predicate: Predicate):
have_to_type = False
for term in predicate.terms:
if len(term.type_tags) <= 0:
have_to_type = True
break
if have_to_type:
new_terms = []
for term in predicate.terms:
if len(term.type_tags) <= 0:
new_terms.append(Constant(term.name, get_type_tag(pddl_problem, term.name)))
else:
new_terms.append(term)
return Predicate(predicate.name, *new_terms)
return predicate
def get_type_tag(pddl_problem: Problem, name: str):
for obj in pddl_problem.objects:
if name == obj.name:
return obj.type_tag
else:
return None |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #195 +/- ##
==========================================
+ Coverage 88.12% 89.83% +1.70%
==========================================
Files 24 27 +3
Lines 1752 1997 +245
Branches 233 216 -17
==========================================
+ Hits 1544 1794 +250
+ Misses 148 140 -8
- Partials 60 63 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Thanks, @RichardGubijev ! I think this change makes sense. The instantiation of plans is fairly new functionality, so it makes sense that we're missing some things. Want to throw in some tests that fail before your fix, but pass now? After that, feel free to mark it as "Ready for review" |
cacb0ba to
df51c37
Compare
|
I modified a test to check if the instantiated action's parameter terms are typed, it's not the most robust possible test, but I am not sure on how to test this feature/fix. Let me know what y'all think and if you want more robust test coverage I'd appreciate some pointers/help with it! |
Proposed changes
Type the parameters used in instantiating actions in
Plan.instantiate()using the existingtype_tagsvariables of the to-be instantiated actions.Demonstration:
Without the fix (truncated):
With the fix (truncated):
Fixes
When you instantiate a plan, the actions are instantiated with terms without
type_tags, even if the variables in the actions do.Types of changes
Checklist
Further comments
I'm looking for feedback for if this is something the
Plan.instantiate()should do, if it's better to do it somewhere else, or if the terms are meant to be untyped.