Skip to content

Commit

Permalink
Merge pull request #261 from JuliaReach/schillic/260
Browse files Browse the repository at this point in the history
#260 - AssertionError in Iterative refinement
  • Loading branch information
schillic authored Feb 28, 2018
2 parents d35bec1 + 2913635 commit 10ce03d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Approximations/iterative_refinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ PolygonalOverapproximation{N}(S::LazySet) where {N<:Real} =
PolygonalOverapproximation(S::LazySet, LocalApproximation{N}[])

"""
new_approx(S::LazySet, p1::Vector{N}, d1::Vector{N}, p2::Vector{N}, d2::Vector{N}) where {N<:Real}
new_approx(S::LazySet, p1::Vector{N}, d1::Vector{N}, p2::Vector{N},
d2::Vector{N}) where {N<:Real}
### Input
Expand All @@ -61,15 +62,17 @@ PolygonalOverapproximation{N}(S::LazySet) where {N<:Real} =
A local approximation of `S` in the given directions.
"""
function new_approx(S::LazySet, p1::Vector{N}, d1::Vector{N}, p2::Vector{N}, d2::Vector{N}) where {N<:Real}
function new_approx(S::LazySet, p1::Vector{N}, d1::Vector{N}, p2::Vector{N},
d2::Vector{N}) where {N<:Real}
if norm(p1-p2, 2) < TOL(N)
# this approximation cannot be refined and we set q = p1 by convention
ap = LocalApproximation{N}(p1, d1, p2, d2, p1, false, zero(N))
else
ndir = normalize([p2[2]-p1[2], p1[1]-p2[1]])
q = intersection(Line(d1, dot(d1, p1)), Line(d2, dot(d2, p2)))
approx_error = min(norm(q - σ(ndir, S)), dot(ndir, q - p1))
refinable = (approx_error > TOL(N)) && !(norm(p1-q, 2) < TOL(N) || norm(q-p2, 2) < TOL(N))
refinable = (approx_error > TOL(N)) &&
!(norm(p1-q, 2) < TOL(N) || norm(q-p2, 2) < TOL(N))
ap = LocalApproximation{N}(p1, d1, p2, d2, q, refinable, approx_error)
end
return ap
Expand All @@ -93,7 +96,8 @@ The list of local approximations in `Ω` of the set `Ω.S` is updated in-place a
the new approximation is returned by this function.
"""
function addapproximation!::PolygonalOverapproximation,
p1::Vector{N}, d1::Vector{N}, p2::Vector{N}, d2::Vector{N})::LocalApproximation{N} where {N<:Real}
p1::Vector{N}, d1::Vector{N}, p2::Vector{N},
d2::Vector{N})::LocalApproximation{N} where {N<:Real}

approx = new_approx.S, p1, d1, p2, d2)
push!.approx_list, approx)
Expand Down Expand Up @@ -182,7 +186,8 @@ function approximate(S::LazySet{N},

i = 1
while i <= length.approx_list)
if Ω.approx_list[i].err <= ɛ
approx = Ω.approx_list[i]
if !approx.refinable || approx.err <= ɛ
# if this approximation doesn't need to be refined, consider the next
# one in the queue (counter-clockwise order wrt d1)
# if the approximation is not refinable => continue
Expand All @@ -194,14 +199,15 @@ function approximate(S::LazySet{N},

Ω.approx_list[i] = la1

redundant = inext > length.approx_list) ? false : (norm(la2.p1-Ω.approx_list[inext].p1) < TOL(N)) && (norm(la2.q-Ω.approx_list[inext].q) < TOL(N))
redundant = inext > length.approx_list) ? false :
(norm(la2.p1-Ω.approx_list[inext].p1) < TOL(N)) &&
(norm(la2.q-Ω.approx_list[inext].q) < TOL(N))
if redundant
# if it is redundant, keep the refined approximation
Ω.approx_list[inext] = la2
else
insert!.approx_list, inext, la2)
end

end
end
return Ω
Expand Down

0 comments on commit 10ce03d

Please sign in to comment.