Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pddl/grounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def prepare_symbol_tables(self, domain : Domain, problem):
self.type_symbol_tables["object"] = SymbolTable()
for type in domain.type_tree.keys():
self.type_symbol_tables[type] = SymbolTable()
if domain.type_tree[type].parent not in domain.type_tree:
self.type_symbol_tables[domain.type_tree[type].parent] = SymbolTable()
for type in domain.type_tree.keys():
if type in problem.type_objects_map:
for obj in problem.type_objects_map[type]:
Expand All @@ -119,13 +121,19 @@ def prepare_symbol_tables(self, domain : Domain, problem):

def update_type_symbol_table(self, obj_name : str, obj_type : str):
self.type_symbol_tables[obj_type].add_symbol(obj_name)
if obj_type in self.domain.type_tree:
if obj_type in self.domain.type_tree and self.domain.type_tree[obj_type].parent != obj_type:
# The second part of the if prevents an infinite recursion, for instance when there's a type "object" in the PDDL
self.update_type_symbol_table(obj_name, self.domain.type_tree[obj_type].parent)

def ground_object_list(self, problem):
self.type_counts["object"] = len(problem.objects_type_map) + len(self.domain.constants_type_map)
for type in self.domain.type_tree.keys():
self.type_counts[type] = len(self.type_symbol_tables[type].symbol_list)
if self.domain.type_tree[type].parent not in self.domain.type_tree:
if self.domain.type_tree[type].parent not in self.type_counts:
self.type_counts[self.domain.type_tree[type].parent] = len(self.type_symbol_tables[type].symbol_list) # Initialise
else:
self.type_counts[self.domain.type_tree[type].parent] += len(self.type_symbol_tables[type].symbol_list)

def ground_symbol_list(self, symbol_table : SymbolTable, formulae : dict[str, AtomicFormula], heads : dict[str, int]):
head = 0
Expand Down
42 changes: 24 additions & 18 deletions plan_graphs/relaxed_plan_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pddl.grounding import Grounding
from pddl.problem import Problem
from pddl.state import State
from pddl.time_spec import TimeSpec

class RelaxedPlanGraph:

Expand Down Expand Up @@ -46,17 +47,21 @@ def _cache_actions(self) -> None:
"""
self.actions_cached = True
for action_id in range(self.grounding.action_count):
pos, _ = self.grounding.get_simple_action_condition_from_id(action_id)
adds, _ = self.grounding.get_simple_action_effect_from_id(action_id)
self.action_add_effect_spikes[action_id] = adds
self.action_positive_condition_spikes[action_id] = pos
self.action_precondition_counts[action_id] = np.count_nonzero(pos)

# cache precondition mapping
for prop in np.nonzero(pos)[0]:
if prop not in self.proposition_condition_map:
self.proposition_condition_map[prop] = []
self.proposition_condition_map[prop].append(action_id)
for time_spec in [TimeSpec.AT_START, TimeSpec.OVER_ALL, TimeSpec.AT_END]:
pos, _ = self.grounding.get_simple_action_condition_from_id(action_id, time_spec)
adds, _ = self.grounding.get_simple_action_effect_from_id(action_id, time_spec)
self.action_add_effect_spikes[action_id] = adds
self.action_positive_condition_spikes[action_id] = pos
if action_id in self.action_precondition_counts:
self.action_precondition_counts[action_id] += np.count_nonzero(pos)
else:
self.action_precondition_counts[action_id] = np.count_nonzero(pos)

# cache precondition mapping
for prop in np.nonzero(pos)[0]:
if prop not in self.proposition_condition_map:
self.proposition_condition_map[prop] = []
self.proposition_condition_map[prop].append(action_id)

def build_graph(self, state : State = None, stop_at_goal = True) -> int:
"""
Expand Down Expand Up @@ -120,13 +125,14 @@ def build_graph(self, state : State = None, stop_at_goal = True) -> int:
self.fix_point_reached = False

# increment counters on action conditions
for a in self.proposition_condition_map[prop_id]:
self.action_counters[a] += 1
if self.action_counters[a] == self.action_precondition_counts[a] and self.action_membership[a] == 0:
# new action achievable
self.action_membership[a] = self.last_layer + 1
self.action_layers[self.last_layer+1].add(a)
next_actions.append(a)
if prop_id in self.proposition_condition_map:
for a in self.proposition_condition_map[prop_id]:
self.action_counters[a] += 1
if self.action_counters[a] == self.action_precondition_counts[a] and self.action_membership[a] == 0:
# new action achievable
self.action_membership[a] = self.last_layer + 1
self.action_layers[self.last_layer+1].add(a)
next_actions.append(a)

current_actions = next_actions

Expand Down