step towards actually testing boolean evaluation on random formulas
This commit is contained in:
parent
7d8cf78222
commit
75042d0dc4
5 changed files with 17 additions and 20 deletions
|
|
@ -140,7 +140,7 @@ class Var(namedtuple("Var", ["coeff", "id"])):
|
||||||
elif self.coeff == +1:
|
elif self.coeff == +1:
|
||||||
coeff_str = ""
|
coeff_str = ""
|
||||||
else:
|
else:
|
||||||
coeff_str = f"{self.coeff}*"
|
coeff_str = f"{self.coeff}"
|
||||||
return f"{coeff_str}{self.id}"
|
return f"{coeff_str}{self.id}"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ oo = float('inf')
|
||||||
|
|
||||||
|
|
||||||
def pointwise_sat(phi):
|
def pointwise_sat(phi):
|
||||||
ap_names = [z.id.name for z in stl.ast.AP_lens(phi).Each().collect()]
|
ap_names = [z.id for z in phi.atomic_predicates]
|
||||||
|
|
||||||
def _eval_stl(x, t):
|
def _eval_stl(x, t):
|
||||||
evaluated = stl.utils.eval_lineqs(phi, x)
|
evaluated = stl.utils.eval_lineqs(phi, x)
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@ import stl
|
||||||
|
|
||||||
GRAMMAR = {
|
GRAMMAR = {
|
||||||
'phi': (('Unary', '(', 'phi', ')'), ('(', 'phi', ')', 'Binary', '(', 'phi',
|
'phi': (('Unary', '(', 'phi', ')'), ('(', 'phi', ')', 'Binary', '(', 'phi',
|
||||||
')'), ('AP', )),
|
')'), ('AP', ), ('LINEQ', )),
|
||||||
'Unary': (('~', ), ('G', ), ('F', ), ('X', )),
|
'Unary': (('~', ), ('G', 'Interval'), ('F', 'Interval'), ('X', )),
|
||||||
|
'Interval': (('',), ('[1, 3]',)),
|
||||||
'Binary': ((' | ', ), (' & ', ), (' U ',)),
|
'Binary': ((' | ', ), (' & ', ), (' U ',)),
|
||||||
'AP': (('AP1', ), ('AP2', ), ('AP3', ), ('AP4', ), ('AP5', )),
|
'AP': (('AP1', ), ('AP2', ), ('AP3', ), ('AP4', ), ('AP5', )),
|
||||||
|
'LINEQ': (('x > 4', ), ('y < 2', ), ('y >= 3', ), ('x + y >= 2',)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,5 +21,5 @@ def to_stl(term):
|
||||||
SignalTemporalLogicStrategy = st.builds(to_stl,
|
SignalTemporalLogicStrategy = st.builds(to_stl,
|
||||||
ContextFreeGrammarStrategy(
|
ContextFreeGrammarStrategy(
|
||||||
GRAMMAR,
|
GRAMMAR,
|
||||||
max_length=25,
|
max_length=27,
|
||||||
start='phi'))
|
start='phi'))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
from functools import partialmethod
|
from functools import partialmethod
|
||||||
|
|
||||||
from lenses import lens
|
from lenses import bind
|
||||||
from parsimonious import Grammar, NodeVisitor
|
from parsimonious import Grammar, NodeVisitor
|
||||||
from stl import ast
|
from stl import ast
|
||||||
from stl.utils import alw, env, iff, implies, xor
|
from stl.utils import alw, env, iff, implies, xor
|
||||||
|
|
@ -77,10 +77,6 @@ class STLVisitor(NodeVisitor):
|
||||||
_, _, (left, ), _, _, _, (right, ), _, _ = children
|
_, _, (left, ), _, _, _, (right, ), _, _ = children
|
||||||
left = left if left != [] else float("inf")
|
left = left if left != [] else float("inf")
|
||||||
right = right if right != [] else float("inf")
|
right = right if right != [] else float("inf")
|
||||||
if isinstance(left, int):
|
|
||||||
left = float(left)
|
|
||||||
if isinstance(right, int):
|
|
||||||
left = float(right)
|
|
||||||
return ast.Interval(left, right)
|
return ast.Interval(left, right)
|
||||||
|
|
||||||
def get_text(self, node, _):
|
def get_text(self, node, _):
|
||||||
|
|
@ -136,7 +132,7 @@ class STLVisitor(NodeVisitor):
|
||||||
def visit_terms(self, _, children):
|
def visit_terms(self, _, children):
|
||||||
if isinstance(children[0], list):
|
if isinstance(children[0], list):
|
||||||
term, _1, sgn, _2, terms = children[0]
|
term, _1, sgn, _2, terms = children[0]
|
||||||
terms = lens(terms)[0].coeff * sgn
|
terms = bind(terms)[0].coeff * sgn
|
||||||
return [term] + terms
|
return [term] + terms
|
||||||
else:
|
else:
|
||||||
return children
|
return children
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,13 @@ TODO: Automatically generate input time series.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
x = {
|
x = {
|
||||||
"A": traces.TimeSeries([(0, 1), (0.1, 1), (0.2, 4)]),
|
"x": traces.TimeSeries([(0, 1), (0.1, 1), (0.2, 4)]),
|
||||||
"B": traces.TimeSeries([(0, 2), (0.1, 4), (0.2, 2)]),
|
"y": traces.TimeSeries([(0, 2), (0.1, 4), (0.2, 2)]),
|
||||||
"C": traces.TimeSeries([(0, True), (0.1, True), (0.2, False)]),
|
"AP1": traces.TimeSeries([(0, True), (0.1, True), (0.2, False)]),
|
||||||
'D': traces.TimeSeries({
|
"AP2": traces.TimeSeries([(0, False), (0.2, True), (0.5, False)]),
|
||||||
0.0: 2,
|
"AP3": traces.TimeSeries([(0, True), (0.1, True), (0.3, False)]),
|
||||||
13.8: 3,
|
"AP4": traces.TimeSeries([(0, False), (0.1, False), (0.3, False)]),
|
||||||
19.7: 2
|
"AP5": traces.TimeSeries([(0, False), (0.1, False), (0.1, True)]),
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue