Skip to content

Commit

Permalink
Merge pull request #205 from JuliaPolyhedra/bl/detectvlin
Browse files Browse the repository at this point in the history
Fix detectvlinearity
  • Loading branch information
blegat committed May 25, 2020
2 parents 234cc55 + d28ac63 commit bf7d295
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 79 deletions.
1 change: 1 addition & 0 deletions docs/src/redundancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ support_function
```@docs
detecthlinearity!
detectvlinearity!
detect_new_lines
dim
```

Expand Down
32 changes: 23 additions & 9 deletions examples/Computing controlled invariant sets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"include(Pkg.dir(\"HybridSystems\", \"examples\", \"cruise_control.jl\"));"
Expand Down Expand Up @@ -40,7 +42,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"macro _time(x)\n",
Expand All @@ -62,13 +66,15 @@
"outputs": [],
"source": [
"using Gurobi\n",
"lpsolver = optimizer_with_attributes(Gurobi.Optimizer, "OutputFlag" => 0);"
"lpsolver = optimizer_with_attributes(Gurobi.Optimizer, \"OutputFlag\" => 0);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"function liftu(S, sys::HybridSystems.DiscreteLinearControlSystem)\n",
Expand Down Expand Up @@ -114,7 +120,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Mmax = 1\n",
Expand All @@ -137,7 +145,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Mmax = size(t, 1)\n",
Expand All @@ -155,7 +165,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import Plots\n",
Expand All @@ -165,7 +177,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"D = [1, 2]\n",
Expand Down Expand Up @@ -207,7 +221,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.0",
"display_name": "Julia 0.6.4",
"language": "julia",
"name": "julia-0.6"
},
Expand Down
10 changes: 5 additions & 5 deletions src/aff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ conetype(::Type{LinesHull{T, AT, D}}) where {T, AT, D} = RaysHull{T, AT, D}
vreptype(::Type{LinesHull{T, AT, D}}) where {T, AT, D} = Hull{T, AT, D}

# Returns a LinesHull representing the following set (TODO does it have a name?, does someone has a reference talking about it ?)
# {x | ⟨a, x⟩ = 0 ∀ a such that (α, β) is a valid hyperplane for p}
# {x | y in p => x + y in p}
function linespace(v::VRep, current=false)
if !current
detectvlinearity!(v)
Expand All @@ -172,11 +172,11 @@ function Base.in(v::VRepElement, L::LinesHull)
end

function removeduplicates(L::LinesHull{T, AT}) where {T, AT}
V = LinesHull{T, AT}()
V = LinesHull{T, AT}(FullDim(L))
for l in lines(L)
if !(l in H)
convexhull!(H, h)
if !(l in V)
convexhull!(V, l)
end
end
H
V
end
2 changes: 1 addition & 1 deletion src/center.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using JuMP
Return a tuple with the center and radius of the largest euclidean ball contained in the polyhedron `p`.
Throws an error if the polyhedron is empty or if the radius is infinite.
"""
function hchebyshevcenter(p::HRep, solver=Polyhedra.default_solver(p; T=Float64)) # Need Float64 for `norm(a, 2)`
function hchebyshevcenter(p::HRep, solver=default_solver(p; T=Float64)) # Need Float64 for `norm(a, 2)`
model = JuMP.Model(solver)
c = JuMP.@variable(model, [1:fulldim(p)])
for hp in hyperplanes(p)
Expand Down
2 changes: 1 addition & 1 deletion src/doubledescription.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function intersect_and_remove_redundancy(v, hs, h; verbose=0)
end
# removeduplicates is cheaper than removevredundancy since the latter
# needs to go through all the hrep element
v_dup = removeduplicates(v_int)
v_dup = removeduplicates(v_int, OppositeRaysMockOptimizer)
if verbose >= 3
print("Removing redundancy: ")
print_v_summary(v_dup)
Expand Down
3 changes: 2 additions & 1 deletion src/elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ Base.:-(h::ElemT) where {ElemT<:Union{HyperPlane, HalfSpace}} = ElemT(-h.a, -h.
Base.:-(elem::ElemT) where ElemT<:VStruct = ElemT(-coord(elem))
# Used in remproj
Base.:-(p::AbstractVector, l::Line) = p - coord(l)
# Ray - Line is done in remproj
# `Ray - Line` and `Line - Line` are done in `remproj`
Base.:-(r::Ray, s::Union{Ray, Line}) = Ray(r.a - s.a)
Base.:-(r::Line, s::Line) = Line(r.a - s.a)
Base.:+(r::Ray, s::Ray) = Ray(r.a + s.a)
Base.:+(p::AbstractVector, r::Ray) = p + coord(r)

Expand Down
9 changes: 9 additions & 0 deletions src/opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,17 @@ end

coefficient_type(::MOI.ModelLike) = Float64

no_solver_help() = """
To provide a solver to a polyhedron, first select a solver from https://www.juliaopt.org/JuMP.jl/v0.21.1/installation/#Getting-Solvers-1.
If you choose for instance `GLPK`, do `using GLPK; solver = GLPK.Optimizer`.
Then provide the solver to the library. For instance, with the default library, do `lib = DefaultLibrary{Float64}(solver)`
or if you use an external library, say `QHull`, do `lib = QHull.Library(solver)`.
Then when you create the polyhedron, say from a representation `rep`, do `polyhedron(rep, lib)`.
"""

# Inspired by `JuMP.set_optimizer`
function layered_optimizer(solver)
solver === nothing && error("No solver specified.\n", no_solver_help())
optimizer = solver()
T = coefficient_type(optimizer)
if !MOIU.supports_default_copy_to(optimizer, false)
Expand Down
Loading

0 comments on commit bf7d295

Please sign in to comment.