Skip to content

Commit

Permalink
fix(interpreted functions): minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Nov 19, 2024
1 parent e19ecb1 commit e703358
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions unified_planning/engines/compilers/interpreted_functions_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,13 @@ def _compile(
new_problem.set_initial_value(f(o), val)

is_unknown_fluents: Dict = {}
# NOTE - contents is_unknown_fluents could be more optimal
# now tracking fluents are added for all fluents that can change from any effect
# in theory we do not need fluents that are completely isolated from IFs
for a in problem.actions:
# these fluents are created and added to the problem at the start as we
# might need some of them before we encounter them during the compilation
found_effects = self._get_effects(a)
for time, ef in found_effects:
f = ef.fluent.fluent()
if f in is_unknown_fluents.keys():
continue
new_f_name = get_fresh_name(new_problem, f"_{f.name}_is_unknown")
new_f = Fluent(new_f_name, BoolType())
new_problem.add_fluent(new_f, default_initial_value=False)
new_problem.set_initial_value(new_f, em.FALSE())
is_unknown_fluents[f] = new_f
changing_fluents = self._find_changing_fluents(problem)
for f in changing_fluents:
new_f_name = get_fresh_name(new_problem, f"_{f.name}_is_unknown")
new_f = Fluent(new_f_name, BoolType())
new_problem.add_fluent(new_f, default_initial_value=False)
new_problem.set_initial_value(new_f, em.FALSE())
is_unknown_fluents[f] = new_f

for a in problem.actions:
for new_params, dur, conds, effs in self._expand_action(
Expand Down Expand Up @@ -453,6 +444,18 @@ def _default_value_given_type(self, t):
else:
raise NotImplementedError

Check warning on line 445 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L445

Added line #L445 was not covered by tests

def _find_changing_fluents(self, problem):
found_fluents_set = set()
# TODO - improve this
# right now adds all fluents that can be modified by actions
# should only get those related to IFs or to other IF related fluents
for a in problem.actions:
found_effects = self._get_effects(a)
for _, ef in found_effects:
f = ef.fluent.fluent()
found_fluents_set.add(f)
return found_fluents_set

def _create_tracking_effect(self, ef, is_unknown_fluents, em):
# tracking fluent is set to is_unknown if at least one
# of the fluents in value is tagged with is_unknown
Expand Down

0 comments on commit e703358

Please sign in to comment.