Skip to content

Commit 02c6c9c

Browse files
committed
je sais pas
1 parent 8c4feb2 commit 02c6c9c

2 files changed

Lines changed: 57 additions & 15 deletions

File tree

jupyddl/automated_planner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
logging.getLogger("julia").setLevel(logging.WARNING)
1515

16-
1716
class AutomatedPlanner:
1817
def __init__(self, domain_path, problem_path, log_level="DEBUG"):
1918
# Planning Tool
2019
self.pddl = PDDL
20+
self.domain_path = domain_path
21+
self.problem_path = problem_path
2122
self.domain = self.pddl.load_domain(domain_path)
2223
self.problem = self.pddl.load_problem(problem_path)
2324
self.initial_state = self.pddl.initialize(self.problem)
@@ -41,7 +42,6 @@ def __run_julia_once(self):
4142
actions = self.available_actions(self.initial_state)
4243
self.transition(self.initial_state, actions[0])
4344

44-
def __rela
4545

4646
def __init_logger(self, log_level):
4747
import os

jupyddl/heuristics.py

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ def __goal_count_heuristic(self, state):
2929

3030
class DeleteRelaxationHeuristic:
3131
def __init__(self, automated_planner, heuristic_key):
32+
class DRHCache:
33+
def __init__(self, domain=None, axioms=None, preconds=None, additions=None):
34+
self.domain = domain
35+
self.axioms = axioms
36+
self.preconds = preconds
37+
self.additions = additions
38+
3239
self.automated_planner = automated_planner
40+
self.cache = DRHCache()
3341
self.heuristic_keys = {
3442
"delete_relaxation/h_add": self.__h_add,
3543
"delete_relaxation/h_max": self.__h_max
@@ -39,22 +47,56 @@ def __init__(self, automated_planner, heuristic_key):
3947
heuristic_key = "delete_relaxation/h_add"
4048

4149
self.current_h = heuristic_key
50+
self.has_been_precomputed = False
51+
self.__pre_compute()
52+
# return self.heuristic_keys[self.current_h](state)
4253

43-
def compute(self, state):
44-
return self.heuristic_keys[self.current_h](state)
54+
def compute(self, state, goals):
55+
if not self.has_been_precomputed:
56+
self.__pre_compute()
57+
domain = self.cache.domain
58+
goals = self.automated_planner.goals
59+
types = state.types
60+
facts = state.facts
61+
62+
fact_costs = dict([(f, 0) for f in facts])
63+
while not(len(fact_costs) == len(facts) and self.__facts_eq(fact_costs, facts)):
64+
facts_set = self.automated_planner.pddl.Set(self.automated_planner.pddl.keys(fact_costs))
65+
state = self.automated_planner.pddl.create_state(types, facts_set)
66+
if self.automated_planner.satisfies(goals, state):
67+
costs = [fact_costs[g] for g in goals]
68+
costs.insert(0, 0)
69+
return self.heuristic_keys[self.current_h](costs)
70+
71+
for ax in self.cache.axioms:
72+
pass
4573

4674
def __pre_compute(self):
47-
logging.fatal("Delete relaxation h_add is not yet implemented")
48-
exit()
75+
if self.has_been_precomputed:
76+
return
77+
domain = self.automated_planner.domain
78+
domain, axioms = self.automated_planner.pddl.compute_hsp_axioms(domain)
79+
preconditions = dict()
80+
additions = dict()
81+
for name, definition in domain.actions.items():
82+
precond = self.automated_planner.pddl.filter_negative_preconds(definition)
83+
preconditions[name] = precond
84+
additions[name] = self.automated_planner.pddl.effect_diff(definition.effect).add
85+
self.cache.additions = additions
86+
self.cache.preconds = preconditions
87+
self.cache.domain = domain
88+
self.cache.axioms = axioms
89+
90+
91+
def __h_add(self, costs):
92+
return sum(costs)
4993

50-
def __cache(self):
51-
logging.fatal("Delete relaxation h_add is not yet implemented")
52-
exit()
94+
def __h_max(self, costs):
95+
return max(costs)
5396

54-
def __h_add(self, state):
55-
logging.fatal("Delete relaxation h_add is not yet implemented")
56-
exit()
97+
def __facts_eq(self, facts_dict, facts_set):
98+
for f in facts_set:
99+
if not(f in facts_dict.keys()):
100+
return False
101+
return True
57102

58-
def __h_max(self, state):
59-
logging.fatal("Delete relaxation h_max is not yet implemented")
60-
exit()

0 commit comments

Comments
 (0)