Remove LinEq type
This commit is contained in:
parent
b9b10ac835
commit
d2cd678018
4 changed files with 7 additions and 50 deletions
|
|
@ -1,8 +1,7 @@
|
|||
# flake8: noqa
|
||||
from stl.ast import TOP, BOT
|
||||
from stl.ast import (LinEq, Interval, NaryOpSTL, Or, And, F, G, ModalOp, Neg,
|
||||
Var, AtomicPred, Until, Next)
|
||||
from stl.ast import (Interval, Or, And, F, G, Neg,
|
||||
AtomicPred, Until, Next)
|
||||
from stl.parser import parse
|
||||
from stl.fastboolean_eval import pointwise_sat
|
||||
from stl.types import STL
|
||||
from stl.utils import alw, env, andf, orf
|
||||
|
|
|
|||
29
stl/ast.py
29
stl/ast.py
|
|
@ -138,34 +138,6 @@ class AtomicPred(namedtuple("AP", ["id"]), AST):
|
|||
return tuple()
|
||||
|
||||
|
||||
class LinEq(namedtuple("LinEquality", ["terms", "op", "const"]), AST):
|
||||
__slots__ = ()
|
||||
|
||||
def __repr__(self):
|
||||
return " + ".join(map(str, self.terms)) + f" {self.op} {self.const}"
|
||||
|
||||
@property
|
||||
def children(self):
|
||||
return tuple()
|
||||
|
||||
def __hash__(self):
|
||||
# TODO: compute hash based on contents
|
||||
return hash(repr(self))
|
||||
|
||||
|
||||
class Var(namedtuple("Var", ["coeff", "id"])):
|
||||
__slots__ = ()
|
||||
|
||||
def __repr__(self):
|
||||
if self.coeff == -1:
|
||||
coeff_str = "-"
|
||||
elif self.coeff == +1:
|
||||
coeff_str = ""
|
||||
else:
|
||||
coeff_str = f"{self.coeff}"
|
||||
return f"{coeff_str}{self.id}"
|
||||
|
||||
|
||||
class Interval(namedtuple('I', ['lower', 'upper'])):
|
||||
__slots__ = ()
|
||||
|
||||
|
|
@ -304,5 +276,4 @@ def type_pred(*args):
|
|||
return lambda x: type(x) in ast_types
|
||||
|
||||
|
||||
lineq_lens = lens.Recur(LinEq)
|
||||
AP_lens = lens.Recur(AtomicPred)
|
||||
|
|
|
|||
12
stl/types.py
12
stl/types.py
|
|
@ -1,12 +0,0 @@
|
|||
import typing
|
||||
|
||||
import stl.ast as ast
|
||||
|
||||
ML = typing.Union[ast.AtomicPred, ast.NaryOpSTL, ast.Neg]
|
||||
SL = typing.Union[ast.LinEq, ML]
|
||||
|
||||
STL = typing.Union[SL, ast.ModalOp]
|
||||
MTL = typing.Union[ML, ast.ModalOp]
|
||||
|
||||
PSTL = typing.NewType("PSTL", STL)
|
||||
STL_Generator = typing.Generator[STL, None, STL]
|
||||
11
stl/utils.py
11
stl/utils.py
|
|
@ -7,15 +7,14 @@ import numpy as np
|
|||
from lenses import bind
|
||||
|
||||
import stl.ast
|
||||
from stl.ast import (And, F, G, Interval, LinEq, Neg, Or, Next, Until,
|
||||
from stl.ast import (And, F, G, Interval, Neg, Or, Next, Until,
|
||||
AtomicPred, _Top, _Bot)
|
||||
from stl.types import STL
|
||||
|
||||
oo = float('inf')
|
||||
|
||||
|
||||
def f_neg_or_canonical_form(phi: STL) -> STL:
|
||||
if isinstance(phi, (LinEq, AtomicPred, _Top, _Bot)):
|
||||
def f_neg_or_canonical_form(phi):
|
||||
if isinstance(phi, (AtomicPred, _Top, _Bot)):
|
||||
return phi
|
||||
|
||||
children = [f_neg_or_canonical_form(s) for s in phi.children]
|
||||
|
|
@ -120,7 +119,7 @@ def discretize(phi, dt, distribute=False, *, horizon=None):
|
|||
|
||||
|
||||
def _discretize(phi, dt, horizon):
|
||||
if isinstance(phi, (LinEq, AtomicPred, _Top, _Bot)):
|
||||
if isinstance(phi, (AtomicPred, _Top, _Bot)):
|
||||
return phi
|
||||
|
||||
if not isinstance(phi, (F, G, Until)):
|
||||
|
|
@ -153,7 +152,7 @@ def _interval_discretizable(itvl, dt):
|
|||
|
||||
|
||||
def _distribute_next(phi, i=0):
|
||||
if isinstance(phi, (LinEq, AtomicPred)):
|
||||
if isinstance(phi, AtomicPred):
|
||||
return stl.utils.next(phi, i=i)
|
||||
elif isinstance(phi, Next):
|
||||
return _distribute_next(phi.arg, i=i+1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue