Skip to content

Commit

Permalink
f(interpreted functions): does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Oct 16, 2024
1 parent 873d6f2 commit ebc57d4
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 10 deletions.
144 changes: 141 additions & 3 deletions unified_planning/engines/compilers/interpreted_functions_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,137 @@ def _compile(

elif isinstance(a, DurativeAction):
no_IF_action = a.clone()
minduration: FNode | int = 1
maxduration: FNode | int = 1000000
IF_in_durations = list()
IFs_in_durations = list()
IF_in_conditions = list()
known_duration_actions_list = []
times_to_avoid_in_generic = []
duration_elaborated_actions = []

if not (
(
OperatorKind.INTERPRETED_FUNCTION_EXP
in self.operators_extractor.get(a.duration.lower)
)
or (
OperatorKind.INTERPRETED_FUNCTION_EXP
in self.operators_extractor.get(a.duration.upper)
)
):
# there is no if in durations, we just have to elaborate conditions
print("this action had no IF")
temp_action = a.clone()
duration_elaborated_actions.append(temp_action)
else:
aIFs = self.interpreted_functions_extractor.get(a.duration.lower)
if len(aIFs) != 0:
for f in aIFs:
if f not in IFs_in_durations:
IFs_in_durations.append(f)
aIFs = None
aIFs = self.interpreted_functions_extractor.get(a.duration.upper)
if len(aIFs) != 0:
for f in aIFs:
if f not in IFs_in_durations:
IFs_in_durations.append(f)
print("if in durations")
print(IFs_in_durations)
known_IFs_in_durations = list()
for IF_in_durations in IFs_in_durations:
print(IF_in_durations)
# for each found if
if (
IF_in_durations.interpreted_function()
in better_knowledge.keys()
):
if (
IF_in_durations.interpreted_function()
not in known_IFs_in_durations
):
known_IFs_in_durations.append(
IF_in_durations.interpreted_function()
)

print("known_IFs_in_durations")
print(known_IFs_in_durations)
if len(known_IFs_in_durations) == 0:
print(
"we know nothing, let's just make the 1 1000000 action and go to conditions"
)
minduration: FNode | int = 1
maxduration: FNode | int = 1000000
if not (
OperatorKind.INTERPRETED_FUNCTION_EXP
in self.operators_extractor.get(a.duration.lower)
):
minduration = a.duration.lower
if not (
OperatorKind.INTERPRETED_FUNCTION_EXP
in self.operators_extractor.get(a.duration.upper)
):
maxduration = a.duration.upper
temp_action = a.clone()
temp_action.set_closed_duration_interval(
minduration, maxduration
)
duration_elaborated_actions.append(temp_action)

else:
print("we have to elaborate durations stuff")
combinations_for_durations = self.knowledge_combinations(
better_knowledge, known_IFs_in_durations
)
print("combinations_for_durations")
print(combinations_for_durations)
for known_functions_combination in combinations_for_durations:
print("known_functions_combinations")
print(known_functions_combination)
temp_action = a.clone()
dict_if_to_duration = dict()
for known_function in known_functions_combination:
print("known_function")
print(known_function)
dict_if_to_duration[
known_function
] = self._interpreted_functions_values[known_function]

print("dict_if_to_duration")
print(dict_if_to_duration)
if len(dict_if_to_duration) == 0:
print(
"substitution dict is empty ;-;\nif you got here it means there is a bug in the code"
)

# now we have all the combinations
# for each combination, do the elaborating of durations

# for each known value in the durations split
# e.g. if we know values that impose duration = 14
# clone action, impose conditions at start time, substitute duration = 14
# save 5 in a list
# n=len(list)
# clone action n+1 times, impose duration limits (1, 13) and (15, 1000000) in this example
# remember to impose conditions at starttime for these
# continue to condition elaboration
print("================================================")
print("for the starting action")
print(a)
print("================================================")
print("these are the actions after duration elaboration")
print("================================================")
print(duration_elaborated_actions)
print("================================================")

# change of plans :'(
# temporary for the tests
# for f in duration_elaborated_actions:
# new_to_old[f] = a
# new_problem.add_action(f)

IFs = None

minduration: FNode | int = 1
maxduration: FNode | int = 1000000
if not (
OperatorKind.INTERPRETED_FUNCTION_EXP
in self.operators_extractor.get(a.duration.lower)
Expand Down Expand Up @@ -441,11 +567,17 @@ def _compile(
if ifid not in all_ifs_in_durative_action:
all_ifs_in_durative_action.append(ifid)
IFkeys_in_durations.append(ifid.interpreted_function())
print(better_knowledge)
if ifid.interpreted_function() in better_knowledge.keys():
for key in better_knowledge[ifid.interpreted_function()]:
times_to_avoid_in_generic.append(
better_knowledge[ifid.interpreted_function()][key]
)

for ific in IF_in_conditions:
if ific not in all_ifs_in_durative_action:
all_ifs_in_durative_action.append(ific)
IFkeys_in_conditions.append(ific.interpreted_function())

if len(all_ifs_in_durative_action) != 0:
ifs_as_keys_durative: list = list()
ifs_as_keys_durative.clear()
Expand Down Expand Up @@ -588,8 +720,14 @@ def _compile(
new_to_old[new_action] = a
new_problem.add_action(new_action)
no_IF_action.name = get_fresh_name(new_problem, a.name)

new_to_old[no_IF_action] = a
new_problem.add_action(no_IF_action)
print(no_IF_action)
print(
"this is the generic action, it should be changed to avoid the duration values"
)
print(times_to_avoid_in_generic)
else:
new_to_old[a] = a
new_problem.add_action(a)
Expand Down
14 changes: 7 additions & 7 deletions unified_planning/engines/interpreted_functions_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(self, *args, **kwargs):
MetaEngine.__init__(self, *args, **kwargs)
mixins.OneshotPlannerMixin.__init__(self)
self._knowledge = OrderedDict()
self._debug_print_final_problem = False

@property
def knowledge(self):
Expand Down Expand Up @@ -179,8 +178,14 @@ def _attempt_to_solve(
start = time.time()
if self._skip_checks:
self.engine._skip_checks = True
res = self.engine.solve(new_problem, heuristic, timeout, output_stream)
print("asking")
print(self.engine.name)
print("to solve the following problem")
print(new_problem)

res = self.engine.solve(new_problem, heuristic, timeout, output_stream)
print("planner result")
print(res)
if timeout is not None:
timeout -= min(timeout, time.time() - start)
if res.status in up.engines.results.POSITIVE_OUTCOMES:
Expand All @@ -193,9 +198,6 @@ def _attempt_to_solve(
validation_result = validator.validate(problem, mappedbackplan)
if validation_result.status == ValidationResultStatus.VALID:

if self._debug_print_final_problem:
print(new_problem)

retval = PlanGenerationResult(
status,
mappedbackplan,
Expand Down Expand Up @@ -226,8 +228,6 @@ def _attempt_to_solve(
PlanGenerationResultStatus.UNSOLVABLE_INCOMPLETELY,
]:

if self._debug_print_final_problem:
print(new_problem)
incomplete = True
if incomplete:
status = res.status
Expand Down

0 comments on commit ebc57d4

Please sign in to comment.