Skip to content

Commit 30d80b5

Browse files
committed
revert changes
1 parent 02c6c9c commit 30d80b5

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

jupyddl/automated_planner.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .dfs import DepthFirstSearch
33
from .dijkstra import DijkstraBestFirstSearch
44
from .a_star import AStarBestFirstSearch
5-
from .heuristics import BasicHeuristic
5+
from .heuristics import BasicHeuristic, DeleteRelaxationHeuristic
66
import coloredlogs
77
import logging
88
import julia
@@ -25,7 +25,9 @@ def __init__(self, domain_path, problem_path, log_level="DEBUG"):
2525
self.goals = self.__flatten_goal()
2626
self.available_heuristics = [
2727
"basic/zero",
28-
"basic/goal_count"
28+
"basic/goal_count",
29+
"delete_relaxation/h_add",
30+
"delete_relaxation/h_max"
2931
]
3032

3133
# Logger
@@ -131,7 +133,9 @@ def dijktra_best_first_search(self):
131133
def astar_best_first_search(self, heuristic_key="basic/goal_count"):
132134
if "basic" in heuristic_key:
133135
heuristic = BasicHeuristic(self, heuristic_key)
134-
else:
136+
elif "delete_relaxation" in heuristic_key:
137+
heuristic = DeleteRelaxationHeuristic(self, heuristic_key)
138+
else:
135139
logging.fatal("Not yet implemented")
136140
exit()
137141
astar = AStarBestFirstSearch(self, heuristic.compute)

jupyddl/heuristics.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,33 @@ def __init__(self, domain=None, axioms=None, preconds=None, additions=None):
5151
self.__pre_compute()
5252
# return self.heuristic_keys[self.current_h](state)
5353

54-
def compute(self, state, goals):
54+
def compute(self, state):
5555
if not self.has_been_precomputed:
5656
self.__pre_compute()
5757
domain = self.cache.domain
5858
goals = self.automated_planner.goals
5959
types = state.types
6060
facts = state.facts
6161

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)
62+
fact_costs = self.automated_planner.pddl.init_facts_costs(facts)
63+
while not(len(fact_costs) == self.automated_planner.pddl.length(facts) and self.__facts_eq(fact_costs, facts)):
64+
facts, state = self.automated_planner.pddl.get_facts_and_state(fact_costs, types)
6665
if self.automated_planner.satisfies(goals, state):
6766
costs = [fact_costs[g] for g in goals]
6867
costs.insert(0, 0)
6968
return self.heuristic_keys[self.current_h](costs)
7069

7170
for ax in self.cache.axioms:
72-
pass
71+
fact_costs = self.automated_planner.pddl.compute_costs_one_step_derivatiion(
72+
facts, fact_costs, ax, self.current_h
73+
)
74+
75+
actions = self.automated_planner.available_actions(state)
76+
for act in actions:
77+
fact_costs = self.automated_planner.pddl.compute_cost_action_effect(
78+
fact_costs, act, domain, self.cache.preconds, self.cache.additions, self.current_h
79+
)
80+
return float("inf")
7381

7482
def __pre_compute(self):
7583
if self.has_been_precomputed:
@@ -86,6 +94,7 @@ def __pre_compute(self):
8694
self.cache.preconds = preconditions
8795
self.cache.domain = domain
8896
self.cache.axioms = axioms
97+
self.has_been_precomputed = True
8998

9099

91100
def __h_add(self, costs):

tests/test_heuristics.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ def test_zero_heuristic():
1818
apla = AutomatedPlanner(
1919
"pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl"
2020
)
21-
heuristic = hs.BasicHeuristic(apla, "zero")
21+
heuristic = hs.BasicHeuristic(apla, "basic/zero")
2222
h = heuristic.compute(apla.initial_state)
2323
assert h == 0
2424

2525

2626
def test_goal_count_heuristic():
2727
apla = AutomatedPlanner(
28-
"pddl-examples/flip/domain.pddl", "pddl-examples/flip/problem.pddl"
28+
"pddl-examples/dinner/domain.pddl", "pddl-examples/dinner/problem.pddl"
2929
)
30-
heuristic = hs.BasicHeuristic(apla, "goal_count")
30+
heuristic = hs.BasicHeuristic(apla, "basic/goal_count")
3131
h = heuristic.compute(apla.initial_state)
32-
assert h == 0
32+
assert h != 0
33+
34+
def test_delete_relaxation_add_heuristic():
35+
apla = AutomatedPlanner(
36+
"pddl-examples/tsp/domain.pddl", "pddl-examples/tsp/problem.pddl"
37+
)
38+
heuristic = hs.DeleteRelaxationHeuristic(apla, "delete_relaxation/h_max")
39+
h = heuristic.compute(apla.initial_state)
40+
assert h != 0

0 commit comments

Comments
 (0)