Easier formulae
This commit is contained in:
@@ -19,11 +19,11 @@ class BagDescription(object):
|
||||
if self.f_type == BagDesc_oper.true:
|
||||
return "TRUE"
|
||||
if self.f_type == BagDesc_oper.l_and:
|
||||
return "( " + repr(self.left_operand) + " & " + repr(self.right_operand) + " )"
|
||||
return "(" + repr(self.left_operand) + " & " + repr(self.right_operand) + ")"
|
||||
if self.f_type == BagDesc_oper.l_or:
|
||||
return "( " + repr(self.left_operand) + " | " + repr(self.right_operand) + " )"
|
||||
return "(" + repr(self.left_operand) + " | " + repr(self.right_operand) + ")"
|
||||
if self.f_type == BagDesc_oper.l_not:
|
||||
return "~" + repr(self.left_operand)
|
||||
return "~(" + repr(self.left_operand) + ")"
|
||||
if self.f_type == BagDesc_oper.lt:
|
||||
return repr(self.left_operand) + " < " + repr(self.right_operand)
|
||||
if self.f_type == BagDesc_oper.le:
|
||||
@@ -37,14 +37,14 @@ class BagDescription(object):
|
||||
|
||||
def sanity_check(self):
|
||||
"""Sanity checks"""
|
||||
|
||||
for operand in (self.left_operand, self.right_operand):
|
||||
if operand:
|
||||
if not(
|
||||
isinstance(operand, BagDescription)
|
||||
or isinstance(operand, int)):
|
||||
raise RuntimeError(
|
||||
"Unexpected operand type for a bag: " + str(operand))
|
||||
"Unexpected operand type for a bag: {:s} (type: {:s})".format(
|
||||
str(operand), str(type(operand))))
|
||||
|
||||
@classmethod
|
||||
def f_entity(cls, entity_name):
|
||||
@@ -54,6 +54,14 @@ class BagDescription(object):
|
||||
def f_TRUE(cls):
|
||||
return cls(BagDesc_oper.true)
|
||||
|
||||
@classmethod
|
||||
def f_And(cls, arg_L, arg_R):
|
||||
return cls(BagDesc_oper.l_and, L_oper=arg_L, R_oper=arg_R)
|
||||
|
||||
@classmethod
|
||||
def f_Not(cls, arg):
|
||||
return cls(BagDesc_oper.l_not, L_oper=arg)
|
||||
|
||||
def __lt__(self, other):
|
||||
return BagDescription(BagDesc_oper.lt, L_oper=self, R_oper=other)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class Formula_rsLTL(object):
|
||||
self.sub_operand = sub_oper
|
||||
self.bag_descr = bag
|
||||
|
||||
# it's silly, but it's a frequent mistake
|
||||
if callable(sub_oper):
|
||||
raise RuntimeError(
|
||||
"sub_oper should not be a function. Missing () for {0}?".format(sub_oper))
|
||||
@@ -26,34 +27,37 @@ class Formula_rsLTL(object):
|
||||
self.left_operand = Formula_rsLTL.f_bag(self.left_operand)
|
||||
if isinstance(self.right_operand, BagDescription):
|
||||
self.right_operand = Formula_rsLTL.f_bag(self.right_operand)
|
||||
|
||||
if self.sub_operand is True:
|
||||
self.sub_operand = BagDescription.f_TRUE()
|
||||
|
||||
def __repr__(self):
|
||||
if self.f_type == rsLTL_form_type.bag:
|
||||
return repr(self.bag_descr)
|
||||
if self.f_type == rsLTL_form_type.l_not:
|
||||
return "~( " + repr(self.left_operand) + " )"
|
||||
return "~(" + repr(self.left_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.t_globally:
|
||||
return "G[" + repr(self.sub_operand) + "]( " + repr(self.left_operand) + " )"
|
||||
return "G[" + repr(self.sub_operand) + "](" + repr(self.left_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.t_finally:
|
||||
return "F[" + repr(self.sub_operand) + "]( " + repr(self.left_operand) + " )"
|
||||
return "F[" + repr(self.sub_operand) + "](" + repr(self.left_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.t_next:
|
||||
return "X[" + repr(self.sub_operand) + "]( " + repr(self.left_operand) + " )"
|
||||
return "X[" + repr(self.sub_operand) + "](" + repr(self.left_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.l_and:
|
||||
return "( " + repr(self.left_operand) + " & " + repr(self.right_operand) + " )"
|
||||
return "(" + repr(self.left_operand) + " & " + repr(self.right_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.l_or:
|
||||
return "( " + repr(self.left_operand) + " | " + repr(self.right_operand) + " )"
|
||||
return "(" + repr(self.left_operand) + " | " + repr(self.right_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.l_implies:
|
||||
return "( " + repr(self.left_operand) + " => " + repr(self.right_operand) + " )"
|
||||
return "(" + repr(self.left_operand) + " => " + repr(self.right_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.t_until:
|
||||
return "( " + repr(
|
||||
return "(" + repr(
|
||||
self.left_operand) + " U[" + repr(
|
||||
self.sub_operand) + "] " + repr(
|
||||
self.right_operand) + " )"
|
||||
self.right_operand) + ")"
|
||||
if self.f_type == rsLTL_form_type.t_release:
|
||||
return "( " + repr(
|
||||
return "(" + repr(
|
||||
self.left_operand) + " R[" + repr(
|
||||
self.sub_operand) + "] " + repr(
|
||||
self.right_operand) + " )"
|
||||
self.right_operand) + ")"
|
||||
|
||||
@property
|
||||
def is_bag(self):
|
||||
@@ -63,6 +67,10 @@ class Formula_rsLTL(object):
|
||||
def f_bag(cls, bag_descr):
|
||||
return cls(rsLTL_form_type.bag, bag=bag_descr)
|
||||
|
||||
@classmethod
|
||||
def f_Not(cls, arg):
|
||||
return cls(rsLTL_form_type.l_not, L_oper=arg)
|
||||
|
||||
@classmethod
|
||||
def f_And(cls, arg_L, arg_R):
|
||||
return cls(rsLTL_form_type.l_and, L_oper=arg_L, R_oper=arg_R)
|
||||
|
||||
@@ -120,12 +120,18 @@ class rsLTL_Encoder(object):
|
||||
|
||||
if bag_formula.f_type == BagDesc_oper.gt:
|
||||
return self.encode_bag(bag_formula.left_operand, level, context) > int(bag_formula.right_operand)
|
||||
|
||||
assert False, "Unsupported case {:s}".format(bag_formula.f_type)
|
||||
|
||||
def encode_bag_state(self, bag_formula, level):
|
||||
return self.encode_bag(bag_formula, level)
|
||||
res = self.encode_bag(bag_formula, level)
|
||||
assert res is not None
|
||||
return res
|
||||
|
||||
def encode_bag_ctx(self, bag_formula, level):
|
||||
return self.encode_bag(bag_formula, level, context=True)
|
||||
res = self.encode_bag(bag_formula, level, context=True)
|
||||
assert res is not None
|
||||
return res
|
||||
|
||||
def encode(self, formula, level, bound):
|
||||
|
||||
@@ -167,7 +173,7 @@ class rsLTL_Encoder(object):
|
||||
|
||||
elif formula.f_type == rsLTL_form_type.l_implies:
|
||||
enc = Implies(
|
||||
self.encode(formula.left_operand, level, bound),
|
||||
self.encode(formula.left_operand, level, bound),
|
||||
self.encode(formula.right_operand, level, bound)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user