Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#583 - Concrete intersection of two HPolygons #651

Merged
merged 3 commits into from
Sep 24, 2018
Merged

Conversation

schillic
Copy link
Member

Closes #583.

@mforets
Copy link
Member

mforets commented Sep 22, 2018

I was expecting that addconstraint! takes care of adding the constraints properly. And it provides different methods such as linear and binary search (and eventually can use a specialized addconstraint! based on a specific concrete AbstractHPolygon, but i don't have an example right now).

This is:

function intersection(...)
    P = HPolygon{N}()
    addconstraint!.(P, constraints_list(P1))
    addconstraint!.(P, constraints_list(P2))
    return P
end

But the repeated halfspaces is something to be fixed in addconstraint!. Or we add a method to remove the redundant constraints. For example:

julia> h = convert(HPolygon, BallInf(ones(2), 1.0));

julia> constraints_list(h)
4-element Array{LazySets.HalfSpace{Float64},1}:
 LazySets.HalfSpace{Float64}([1.0, 0.0], 2.0)   
 LazySets.HalfSpace{Float64}([0.0, 1.0], 2.0)   
 LazySets.HalfSpace{Float64}([-1.0, -0.0], -0.0)
 LazySets.HalfSpace{Float64}([-0.0, -1.0], -0.0)

julia> P = HPolygon{Float64}()
LazySets.HPolygon{Float64}(LazySets.HalfSpace{Float64}[])

julia> addconstraint!.(P, [constraints_list(h); constraints_list(h)]);

julia> constraints_list(P)
8-element Array{LazySets.HalfSpace{Float64},1}:
 LazySets.HalfSpace{Float64}([1.0, 0.0], 2.0)   
 LazySets.HalfSpace{Float64}([1.0, 0.0], 2.0)   
 LazySets.HalfSpace{Float64}([0.0, 1.0], 2.0)   
 LazySets.HalfSpace{Float64}([0.0, 1.0], 2.0)   
 LazySets.HalfSpace{Float64}([-1.0, -0.0], -0.0)
 LazySets.HalfSpace{Float64}([-1.0, -0.0], -0.0)
 LazySets.HalfSpace{Float64}([-0.0, -1.0], -0.0)
 LazySets.HalfSpace{Float64}([-0.0, -1.0], -0.0)

@schillic
Copy link
Member Author

The thing is that adding constraints all at once gives a worst-case quadratic algorithm. Interleaved insertion is worst-case linear.


### Algorithm

We just combine the constraints of both polygons.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extend a bit: "The thing is that adding constraints all at once gives a worst-case quadratic algorithm. Interleaved insertion is worst-case linear."

@schillic schillic merged commit f482a63 into master Sep 24, 2018
@schillic schillic deleted the schillic/583 branch September 24, 2018 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants