Skip to content

Commit df4fc73

Browse files
committed
Attempt at fixing issue #113
1 parent 5c04dee commit df4fc73

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

python/parser/asp/parser/grounder.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,14 @@ def ground(self):
423423
cond_args = tokens[2].split(",")
424424
else:
425425
cond_args = []
426-
cond_args = [self.asp_objects[arg].name for arg in cond_args]
427-
self.problem.code_conds[cond_name].groundings.append(tuple(cond_args))
426+
condition = self.problem.code_conds[cond_name]
427+
428+
grounding = tuple(self.asp_objects[arg].name for arg in cond_args)
429+
condition.groundings.append(grounding)
430+
431+
if hasattr(condition, "variables"):
432+
binding = dict(zip(condition.relevant_vars, grounding))
433+
condition.bindings.append(tuple(binding.get(var, var) for var in condition.variables))
428434

429435
elif tokens[0] == "reachable_a":
430436
pred_name = tokens[1]
@@ -433,9 +439,11 @@ def ground(self):
433439
else:
434440
pred_args = []
435441

436-
pred_args = [self.asp_objects[arg].name for arg in pred_args]
437-
# if ("clean" in pred_name): print(pred_name)
438-
self.asp_actions[pred_name].groundings.append(tuple(pred_args))
442+
action = self.asp_actions[pred_name]
443+
grounding = tuple(self.asp_objects[arg].name for arg in pred_args)
444+
binding = dict(zip(action.param_names, grounding))
445+
action.groundings.append(grounding)
446+
action.bindings.append(tuple(binding.get(var) for var in action.param_names))
439447

440448
elif tokens[0] == "reachable_f":
441449
pred_name = tokens[1]

python/parser/asp/problem.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import itertools
1515

16+
from ..asp import strips_problem
1617
from ..exceptions import UnimplementedFeature
1718
from ..asp.utilities import ProblemException, default_type_name, cond_prefix,\
1819
inequality_prefix, grounding_error_code, lower_var_alphabet, NOT_CONDITION,\
@@ -75,6 +76,8 @@ def __str__(self):
7576
"""
7677
return self.name
7778

79+
__repr__ = __str__
80+
7881
def add_object(self, obj):
7982
""" Add the object to the type and to all of its ancestors.
8083
(Type, str) -> None
@@ -143,9 +146,9 @@ def __str__(self):
143146
""" Return a short string representation of the predicate
144147
(Predicate) -> str
145148
"""
146-
return "( " + self.name + " " + " ".join([x + " - " + str(y)\
147-
for x, y in zip(self.variables, self.types)]) + " )"
149+
return "( " + self.name + " " + " ".join(x + " - " + str(y) for x, y in zip(self.variables, self.types)) + " )"
148150

151+
__repr__ = __str__
149152

150153
class Condition(object):
151154
""" A formula used as a precondition or head of an axiom or conditional effect. """
@@ -155,6 +158,7 @@ def __init__(self):
155158
(Condition) -> None
156159
"""
157160
self.groundings = []
161+
self.bindings = []
158162
self.desc = None
159163

160164
def substitute_derived_predicates(self, derived_predicates, seen_preds):
@@ -298,12 +302,9 @@ def detect_statics(self, candidates, neg_candidates):
298302
""" Remove entries from candidates which are deleted somewhere in this effect.
299303
(PredicateCondition, set([(Predicate, [str])], set([(Predicate, [str])) -> None
300304
"""
301-
if self.sign:
302-
for grounding in self.groundings:
303-
neg_candidates.discard((self.pred, grounding))
304-
else:
305-
for grounding in self.groundings:
306-
candidates.discard((self.pred, grounding))
305+
cand_list = candidates if not self.sign else neg_candidates
306+
for binding in self.bindings:
307+
cand_list.discard((self.pred, binding))
307308

308309
def link_groundings(self, static_preds, neg_static_preds):
309310
""" Link the groundings in this condition to the groundings in its
@@ -1484,6 +1485,7 @@ def __init__(self, name, parameters, types, precondition, effect, is_derived):
14841485
self.is_noop = False
14851486

14861487
self.groundings = []
1488+
self.bindings = [] # Same as groundings, but maps variable name to actual value
14871489
self.ground_preconditions = {}
14881490
self.ground_effects = {}
14891491

0 commit comments

Comments
 (0)