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

Fix #7 #11

Merged
merged 1 commit into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ FixedSizeArrays
GeometryTypes
DataStructures
MathProgBase 0.5.10 0.7
JuMP
JuMP 0.15.1
10 changes: 6 additions & 4 deletions src/elements.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Base.getindex, Base.vec, Base.dot, Base.cross, Base.-, Base.+
export HalfSpace, HyperPlane
export SymPoint, Ray, Line
export HRepElement, HalfSpace, HyperPlane
export VRepElement, AbstractPoint, SymPoint, AbstractRay, Ray, Line
export islin, isray, ispoint, ispoint, coord, lift

typealias MyPoint{N,T} Union{Point{N,T},AbstractArray{T}}
Expand Down Expand Up @@ -142,8 +142,10 @@ Base.convert{N,T}(::Type{SymPoint{N,T}}, v::SymPoint{N,T}) = v
Base.convert{N,T}(::Type{Ray{N,T}}, v::Ray{N,T}) = v
Base.convert{N,T}(::Type{Line{N,T}}, v::Line{N,T}) = v

typealias FixedVRepElement{N,T} Union{Point{N,T},Vec{N,T},Ray{N,T},Line{N,T},SymPoint{N,T}}
typealias VRepElement{N,T} Union{FixedVRepElement{N,T},AbstractVector{T}}
typealias AbstractPoint{N, T} Union{Point{N, T}, AbstractVector{T}, SymPoint{N, T}}
typealias AbstractRay{N, T} Union{Vec{N, T}, Ray{N, T}, Line{N, T}}
typealias FixedVRepElement{N,T} Union{Point{N,T}, Vec{N,T}, Ray{N,T}, Line{N,T}, SymPoint{N,T}}
typealias VRepElement{N,T} Union{FixedVRepElement{N,T}, AbstractVector{T}}
typealias RepElement{N,T} Union{HRepElement{N,T}, VRepElement{N,T}}
typealias FixedRepElement{N,T} Union{HRepElement{N,T}, FixedVRepElement{N,T}}

Expand Down
3 changes: 2 additions & 1 deletion src/jump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ using JuMP
function LPHRepresentation(model::JuMP.Model)
# Inspired from Joey Huchette's code in ConvexHull.jl
A = JuMP.prepConstrMatrix(model)
c, lb, ub = JuMP.prepProblemBounds(model)
c = JuMP.prepAffObjective(model)
lb, ub = JuMP.prepConstrBounds(model)
l, u = model.colLower, model.colUpper

m, n = size(A)
Expand Down
13 changes: 9 additions & 4 deletions src/representation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Base.round, Base.eltype
# TODO affinehull and sparse

export Representation, HRepresentation, VRepresentation, fulldim
export HRepIterator, EqIterator, IneqIterator, VRepIterator, RayIterator, PointIterator
export AbstractRepIterator, AbstractHRepIterator, HRepIterator, EqIterator, IneqIterator, AbstractVRepIterator, VRepIterator, RayIterator, PointIterator
export Rep
export changeeltype, changefulldim, changeboth

Expand Down Expand Up @@ -63,7 +63,11 @@ function checknext(it, i, state, donep, startp)
end

# convention: ax <= β
for (rep, HorVRep, low) in [(true, :VRep, "vrep"), (false, :VRep, "point"), (false, :VRep, "ray"), (true, :HRep, "hrep"), (false, :HRep, "ineq"), (false, :HRep, "eq")]
abstract AbstractRepIterator{N, T}
abstract AbstractHRepIterator{N, T} <: AbstractRepIterator{N, T}
abstract AbstractVRepIterator{N, T} <: AbstractRepIterator{N, T}

for (rep, HorVRep, elt, low) in [(true, :VRep, :VRepElement, "vrep"), (false, :VRep, :AbstractPoint, "point"), (false, :VRep, :AbstractRay, "ray"), (true, :HRep, :HRepElement, "hrep"), (false, :HRep, :HalfSpace, "ineq"), (false, :HRep, :HyperPlane, "eq")]
if rep
up = uppercase(low[1:2]) * low[3:end]
else
Expand All @@ -77,6 +81,7 @@ for (rep, HorVRep, low) in [(true, :VRep, "vrep"), (false, :VRep, "point"), (fal
shortcut = Symbol(shortcuts)
lenp = Symbol("n" * shortcuts)
isemp = Symbol("has" * shortcuts)
abstractit = Symbol("Abstract" * string(HorVRep) * "Iterator")

@eval begin
export $shortcut, $lenp, $startp, $donep, $nextp, $isemp
Expand All @@ -87,7 +92,7 @@ for (rep, HorVRep, low) in [(true, :VRep, "vrep"), (false, :VRep, "point"), (fal
$nextp(p::$HorVRep) = error("$($nextp) not implemented for $(typeof(p))")
end

type $typename{Nout, Tout, Nin, Tin}
type $typename{Nout, Tout, Nin, Tin} <: $abstractit{Nout, Tout}
ps::Vector
f::Nullable{Function}
function $typename{RepT<:$HorVRep}(ps::Vector{RepT}, f)
Expand All @@ -100,7 +105,7 @@ for (rep, HorVRep, low) in [(true, :VRep, "vrep"), (false, :VRep, "point"), (fal
Base.length(it::$typename) = sum([$lenp(p) for p in it.ps])
Base.isempty(it::$typename) = reduce(&, true, [$isemp(p) for p in it.ps])
fulldim{N}(it::$typename{N}) = N
Base.eltype{N,T}(it::$typename{N,T}) = T
Base.eltype{N, T}(it::$typename{N, T}) = $elt{N, T}

Base.start(it::$typename) = checknext(it, 0, nothing, $donep, $startp)
Base.done(it::$typename, state) = state[1] > length(it.ps)
Expand Down
2 changes: 1 addition & 1 deletion test/libraries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function try_import(name::Symbol)
end
end

cdd = try_import(:CDDLib)
cdd = false # try_import(:CDDLib)
lrs = try_import(:LRSLib)

# Create library lists
Expand Down
17 changes: 17 additions & 0 deletions test/rep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
@test eltype(ext) == Int
end

@testset "eltype for some iterators is incorrect #7" begin
function collecttest(it, exp_type)
@test eltype(it) == exp_type
a = collect(it)
@test typeof(a) = Vector{exp_type}
end
hr = SimpleHRepresentation([1 2 3; 4 5 6], [7., 8], IntSet([1]))
@test eltype(hr) == Float64
@test eltype(hreps(hr)) == HRepElement{3, Float64}
@test eltype(ineqs(hr)) == HalfSpace{3, Float64}
@test eltype(eqs(hr)) == HyperPlane{3, Float64}
vr = SimpleVRepresentation([1 2; 3 4])
@test eltype(vreps(vr)) == VRepElement{2, Int}
@test eltype(points(vr)) == AbstractPoint{2, Int}
@test eltype(rays(vr)) == AbstractRay{2, Int}
end

@testset "Iterating over ineqs of a SimpleHRepresentation broken #9" begin
A = [1 2; 3 4; 5 6]
b = [1, 2, 3]
Expand Down