add test for moving on 0 robustness

This commit is contained in:
Marcell Vazquez-Chanlatte 2016-10-10 00:04:10 -07:00
parent 5970c77cb9
commit 47967b462b
2 changed files with 8 additions and 8 deletions

View file

@ -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