Skip to content

Commit

Permalink
fix(interpreted functions): fixed missing tracking fluent in some sit…
Browse files Browse the repository at this point in the history
…uation, minor refactoring
  • Loading branch information
Samuel Gobbi committed Nov 19, 2024
1 parent 5d47bfc commit 58ad206
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
38 changes: 23 additions & 15 deletions unified_planning/engines/compilers/interpreted_functions_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,24 +302,18 @@ def _expand_action(
conds.append((t, new_c))
for time, ef in self._get_effects(a):
ifuns = self.interpreted_functions_extractor.get(ef.value)

if ifuns:
ifs.append((time, ef.value, ifuns, ElementKind.EFFECT, ef))
else:
f = ef.fluent.fluent()
effs.append((time, ef))
f = ef.fluent.fluent()
# only if the fluent is one of the changing ones
# we need to set the tracker
if f not in has_changed_fluents.keys():
continue
# if the fluent is one of the changing ones
# this action sets it to a (possibly) known value
# so the tracking fluent is set to has_changed if at least one
# of the fluents in value is tagged with has_changed

f_list = [v.fluent() for v in self.free_vars_extractor.get(ef.value)]
o_e = em.Or([em.FluentExp(has_changed_fluents[vf]) for vf in f_list])

tracking_fluent_exp = em.FluentExp(has_changed_fluents[f])
reset_tracker_eff = Effect(tracking_fluent_exp, o_e, em.TRUE())
reset_tracker_eff = self._create_tracking_effect(
ef, has_changed_fluents, em
)
effs.append((time, reset_tracker_eff))

lower, upper = None, None
Expand Down Expand Up @@ -388,9 +382,9 @@ def _expand_action(
n_e = eff_instance.clone()
n_e.set_value(exp.substitute(subs))
new_effs.append((t, n_e))
f = eff_instance.fluent.fluent()
tracking_f = em.FluentExp(has_changed_fluents[f])
reset_tracker_eff = Effect(tracking_f, em.FALSE(), em.TRUE())
reset_tracker_eff = self._create_tracking_effect(
eff_instance, has_changed_fluents, em
)
new_effs.append((t, reset_tracker_eff))
elif case == ElementKind.CONDITION:
new_conds.append((t, exp.substitute(subs)))
Expand Down Expand Up @@ -461,6 +455,20 @@ def _default_value_given_type(self, t):
else:
raise NotImplementedError

def _create_tracking_effect(self, ef, has_changed_fluents, em):
# tracking fluent is set to has_changed if at least one
# of the fluents in value is tagged with has_changed
f = ef.fluent.fluent()
f_list = []
for v in self.free_vars_extractor.get(ef.value):
if v.fluent() in has_changed_fluents.keys():
f_list.append(v.fluent())

o_e = em.Or([em.FluentExp(has_changed_fluents[vf]) for vf in f_list])
tracking_fluent_exp = em.FluentExp(has_changed_fluents[f])
reset_tracker_eff = Effect(tracking_fluent_exp, o_e, em.TRUE())
return reset_tracker_eff

def _get_effects(self, a):
eff_list: list = []
time_list: list = []
Expand Down
1 change: 1 addition & 0 deletions unified_planning/engines/plan_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def _validate(
None,
FailedValidationReason.UNSATISFIED_GOALS,
trace=trace,
calculated_interpreted_functions=simulator.get_interpreted_functions_values(),
)


Expand Down

0 comments on commit 58ad206

Please sign in to comment.