Skip to content

Commit a3499d5

Browse files
committed
language: add support for ObservationVar on left of nonreach operator
1 parent c9e30e3 commit a3499d5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

bonesis/asp_encoding.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,28 @@ def encode_reach(self, cfg1, right, mutant=None,
535535
]
536536
return rules
537537

538-
def encode_nonreach(self, cfg1, right, mutant=None, bounded="auto"):
538+
def encode_nonreach(self, left, right, mutant=None, bounded="auto"):
539539
self.load_template_eval()
540540
Z = self.fresh_atom("nonreach")
541-
X = clingo_encode(cfg1.name)
541+
X = clingo_encode(left.name)
542542
Y = clingo_encode(right.name)
543543
if isinstance(right, ConfigurationVar):
544544
pred = "cfg"
545545
elif isinstance(right, ObservationVar):
546546
pred = "obs"
547547
else:
548548
raise NotImplementedError
549-
rules = [
549+
550+
rules = []
551+
552+
if isinstance(left, ObservationVar):
553+
satcfg = self.saturating_configuration(free=f"not obs({X},N,_)",
554+
fixed=f"obs({X},N,V)")
555+
condition = self.make_saturation_condition(satcfg)
556+
rules.append(f"{condition} :- nr_ok({Z})")
557+
X = satcfg
558+
559+
rules += [
550560
f"mcfg(({Z},1..K),N,V) :- reach_steps({Z},K), cfg({X},N,V)",
551561
f"ext(({Z},I),N,V) :- eval(({Z},I),N,V), not locked(({Z},I),N)",
552562

bonesis/language.py

+6
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def __hash__(self):
222222
return hash((self.__class__.__name__,self.name))
223223

224224
@allreach_operator
225+
@nonreach_operator
225226
class ObservationVar(BonesisVar):
226227
def __init__(self, arg):
227228
if isinstance(arg, dict):
@@ -477,6 +478,11 @@ def __init__(self, left, right):
477478
if isinstance(right, fixed):
478479
self.predicate_name = "final_nonreach"
479480
super().__init__(left, right)
481+
@classmethod
482+
def left_arg(celf, arg):
483+
if isinstance(arg, ObservationVar):
484+
return arg
485+
return super().left_arg(arg)
480486

481487
@language_api
482488
class final_nonreach(nonreach):

0 commit comments

Comments
 (0)