From 47967b462bb5ea0f7af7f5447f3169e71de94219 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Mon, 10 Oct 2016 00:04:10 -0700 Subject: [PATCH] add test for moving on 0 robustness --- synth.py | 12 +++++------- test_synth.py | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/synth.py b/synth.py index fa0dad1..6bf54bd 100644 --- a/synth.py +++ b/synth.py @@ -1,3 +1,5 @@ +import operator as op + from stl.utils import set_params, param_lens from stl.robustness import pointwise_robustness @@ -11,16 +13,12 @@ def binsearch(stleval, *, tol=1e-3, lo, hi, polarity): elif not polarity and stleval(hi) > 0: return hi + test = op.le if polarity else op.gt while hi - lo > tol: mid = lo + (hi - lo) / 2 r = stleval(mid) - if not polarity: # swap direction - r *= -1 - if r < 0: - lo, hi = mid, hi - else: - lo, hi = lo, mid - + lo, hi = (mid, hi) if test(r, 0) else (lo, mid) + # Want satisifiable formula return hi if polarity else lo diff --git a/test_synth.py b/test_synth.py index 02444a2..8fefc86 100644 --- a/test_synth.py +++ b/test_synth.py @@ -17,13 +17,15 @@ ex4 = ("G[0, b?](A < 0)", ("b?",), {"b?": (0.1, 5)}, {"b?": False}, {"b?": 0.1}) ex5 = ("F[0, b?](A > 0)", ("b?",), {"b?": (0.1, 5)}, {"b?": True}, {"b?": 0.1}) +ex6 = ("(A > a?) or (A > b?)", ("a?", "b?",), {"a?": (0, 2), "b?": (0, 2)}, + {"a?": False, "b?": False}, {"a?": 2, "b?": 1}) x = pd.DataFrame([[1,2], [1,4], [4,2]], index=[0,0.1,0.2], columns=["A", "B"]) class TestSTLRobustness(unittest.TestCase): - @params(ex1, ex2, ex3, ex4, ex5) + @params(ex1, ex2, ex3, ex4, ex5, ex6) def test_lex_synth(self, phi_str, order, ranges, polarity, val): phi = stl.parse(phi_str) val2 = stl.synth.lex_param_project(