Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
femtocleaner[bot] committed Aug 14, 2017
1 parent 4321d69 commit 05d620e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
12 changes: 6 additions & 6 deletions src/comp.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#const threshold = 1e-8

_isapproxzero{T<:Real}(x::T, ztol) = x == zero(T)
_isapproxzero{T<:AbstractFloat}(x::T, ztol) = -ztol < x < ztol
_isapproxzero{T<:Real}(x::Vector{T}, ztol) = _isapproxzero(sum(abs, x), ztol)
_isapproxzero(x::T, ztol) where {T<:Real} = x == zero(T)
_isapproxzero(x::T, ztol) where {T<:AbstractFloat} = -ztol < x < ztol
_isapproxzero(x::Vector{T}, ztol) where {T<:Real} = _isapproxzero(sum(abs, x), ztol)

_isapprox(x::Real, y::Real, ztol) = x == y
# I check with zero because isapprox(0, 1e-100) is false...
# but isapprox(1e-100, 2e-100) should be false
_isapprox(x::AbstractFloat, y::AbstractFloat, ztol) = (_isapproxzero(x, ztol) ? _isapproxzero(y, ztol) : (_isapproxzero(y, ztol) ? false : isapprox(x, y)))
_isapprox{S<:AbstractFloat, T<:AbstractFloat}(x::Vector{S}, y::Vector{T}, ztol) = (x == zero(x) ? _isapproxzero(y, ztol) : (y == zero(y) ? _isapproxzero(x, ztol) : isapprox(x, y)))
_isapprox(x::Vector{S}, y::Vector{T}, ztol) where {S<:AbstractFloat, T<:AbstractFloat} = (x == zero(x) ? _isapproxzero(y, ztol) : (y == zero(y) ? _isapproxzero(x, ztol) : isapprox(x, y)))

_lt{T<:Real}(x::T, y::T, ztol) = x < y
_lt{S<:Real,T<:Real}(x::S, y::T, ztol) = _lt(promote(x, y)..., ztol)
_lt(x::T, y::T, ztol) where {T<:Real} = x < y
_lt(x::S, y::T, ztol) where {S<:Real,T<:Real} = _lt(promote(x, y)..., ztol)
_lt(x::AbstractFloat, y::AbstractFloat, ztol) = x < y && !_isapprox(x, y, ztol)
# _gt{S<:Real, T<:Real}(x::S, y::T) = _lt(y, x)
# _leq{T<:Real}(x::T, y::T) = x <= y
Expand Down
14 changes: 7 additions & 7 deletions src/cutstore.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function _veccat{S}(b::AbstractVector{S}, β::S, force=false)
function _veccat(b::AbstractVector{S}, β::S, force=false) where S
push!(b, β)
b
end
function _veccat{S}(b::AbstractSparseVector{S}, β::S, force=false)
function _veccat(b::AbstractSparseVector{S}, β::S, force=false) where S
if force || β == zero(S)
# If only homogeneous cuts, b stays sparse
[b; sparsevec([β])]
Expand All @@ -13,10 +13,10 @@ function _veccat{S}(b::AbstractSparseVector{S}, β::S, force=false)
end

# see https://github.com/JuliaLang/julia/issues/16661
function _matcat{S}(A::AbstractMatrix{S}, a::AbstractVector{S})
function _matcat(A::AbstractMatrix{S}, a::AbstractVector{S}) where S
[A; a']
end
function _matcat{S}(A::AbstractSparseMatrix{S}, a::AbstractSparseVector{S})
function _matcat(A::AbstractSparseMatrix{S}, a::AbstractSparseVector{S}) where S
[A; sparse(a')]
end

Expand Down Expand Up @@ -47,14 +47,14 @@ function checksparseness(a::AbstractVector)
end
end

function addcut{S}(store::CutStore{S}, a::AbstractVector{S}, β::S, author)
function addcut(store::CutStore{S}, a::AbstractVector{S}, β::S, author) where S
a = checksparseness(a)
store.Anew = _matcat(store.Anew, a)
store.bnew = _veccat(store.bnew, β)
push!(store.authorsnew, author)
end

function apply!{S}(store::CutStore{S})
function apply!(store::CutStore{S}) where S
if !isempty(store.bnew)
if store.storecuts == :Yes || (store.storecuts != :No && reduce(|, false, store.needstored))
store.A = [store.A; store.Anew]
Expand All @@ -80,7 +80,7 @@ end
function needstored!(store::CutStore, nlds)
store.needstored[findfirst(f->f[1] === nlds, store.followers)] = true
end
function noneedstored!{S}(store::CutStore{S}, nlds)
function noneedstored!(store::CutStore{S}, nlds) where S
store.needstored[findfirst(f->f[1] === nlds, store.followers)] = false
if store.storecuts == :IfNeededElseDelete && !reduce(|, false, store.needstored)
store.A = spzeros(S, 0, size(store.A, 2))
Expand Down
32 changes: 16 additions & 16 deletions src/nlds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mutable struct NLDS{S}
FCpruner::AbstractCutPruner
OCpruners::Vector

function (::Type{NLDS{S}}){S}(W::AbstractMatrix{S}, h::AbstractVector{S}, T::AbstractMatrix{S}, K, C, c::AbstractVector{S}, solver, pruningalgo::AbstractCutPruningAlgo, newcut::Symbol=:AddImmediately)
function NLDS{S}(W::AbstractMatrix{S}, h::AbstractVector{S}, T::AbstractMatrix{S}, K, C, c::AbstractVector{S}, solver, pruningalgo::AbstractCutPruningAlgo, newcut::Symbol=:AddImmediately) where S
nx = size(W, 2)
= 0
= length(h)
Expand All @@ -125,11 +125,11 @@ mutable struct NLDS{S}
end
end

function (::Type{NLDS{S}}){S}(W::AbstractMatrix, h::AbstractVector, T::AbstractMatrix, K, C, c::AbstractVector, solver, pruningalgo::AbstractCutPruningAlgo, newcut::Symbol=:AddImmediately)
function NLDS{S}(W::AbstractMatrix, h::AbstractVector, T::AbstractMatrix, K, C, c::AbstractVector, solver, pruningalgo::AbstractCutPruningAlgo, newcut::Symbol=:AddImmediately) where S
NLDS{S}(AbstractMatrix{S}(W), AbstractVector{S}(h), AbstractMatrix{S}(T), K, C, AbstractVector{S}(c), solver, pruningalgo, newcut)
end

function setchildren!{S}(nlds::NLDS{S}, childFC, childOC, proba, cutgen::AbstractOptimalityCutGenerator, childT)
function setchildren!(nlds::NLDS{S}, childFC, childOC, proba, cutgen::AbstractOptimalityCutGenerator, childT) where S
nlds.cutgen = cutgen
@assert length(childFC) == length(childOC) == length(proba)
nlds.proba = proba
Expand Down Expand Up @@ -195,7 +195,7 @@ function setθlb!(nlds::NLDS, θlb)
end
end

function appendchildren!{S}(nlds::NLDS{S}, childFC, childOC, proba, childT)
function appendchildren!(nlds::NLDS{S}, childFC, childOC, proba, childT) where S
@assert length(childFC) == length(childOC)
@assert length(proba) == length(nlds.childOC) + length(childOC) == length(nlds.childFC) + length(childFC)
oldnθ = nlds.
Expand Down Expand Up @@ -240,7 +240,7 @@ function veceqeqeq(v::Vector, x)
map(el->el === x, v)
end

function padfcut{S}(nlds::NLDS, D::AbstractMatrix{S})
function padfcut(nlds::NLDS, D::AbstractMatrix{S}) where S
if nlds.> 0
[D spzeros(size(D, 1), nlds.nθ)]
else
Expand All @@ -263,29 +263,29 @@ function getfeasibilitycuts(nlds::NLDS)
end

# see https://github.com/JuliaLang/julia/issues/16661
function padmultiocutaux{S}(nlds::NLDS, E::AbstractMatrix{S}, i, onesvec)
function padmultiocutaux(nlds::NLDS, E::AbstractMatrix{S}, i, onesvec) where S
nrows = size(E, 1)
[E spzeros(S, nrows, i-1) onesvec spzeros(S, nrows, nlds.-i)]
end
function padmultiocut{S}(nlds::NLDS, E::AbstractMatrix{S}, i)
function padmultiocut(nlds::NLDS, E::AbstractMatrix{S}, i) where S
nrows = size(E, 1)
padmultiocutaux(nlds, E, i, ones(S, nrows, 1))
end
function padmultiocut{S}(nlds::NLDS, E::AbstractSparseMatrix{S}, i)
function padmultiocut(nlds::NLDS, E::AbstractSparseMatrix{S}, i) where S
nrows = size(E, 1)
padmultiocutaux(nlds, E, i, sparse(ones(S, nrows, 1)))
end

function padavgocut{S}(nlds::NLDS, E::AbstractMatrix{S})
function padavgocut(nlds::NLDS, E::AbstractMatrix{S}) where S
nrows = size(E, 1)
[E ones(S, nrows)]
end
function padavgocut{S}(nlds::NLDS, E::AbstractSparseMatrix{S})
function padavgocut(nlds::NLDS, E::AbstractSparseMatrix{S}) where S
nrows = size(E, 1)
[E sparse(ones(S, nrows))]
end

function getoptimalitycuts{S}(nlds::NLDS{S})
function getoptimalitycuts(nlds::NLDS{S}) where S
function f(i)
E = nlds.childOC[i].A
if !isnull(nlds.childT)
Expand All @@ -307,7 +307,7 @@ function getoptimalitycuts{S}(nlds::NLDS{S})
end


function notifynewcuts{S}(nlds::NLDS{S}, A::AbstractMatrix{S}, b::AbstractVector{S}, attrs, authors::Vector{NLDS{S}})
function notifynewcuts(nlds::NLDS{S}, A::AbstractMatrix{S}, b::AbstractVector{S}, attrs, authors::Vector{NLDS{S}}) where S
@assert attrs[1] in [:Feasibility, :Optimality]
isfc = attrs[1] == :Feasibility
nnewcuts = size(A, 1)
Expand Down Expand Up @@ -377,7 +377,7 @@ function checkconsistency(nlds)
@assert sort([nlds.πs; nlds.+ nlds.σs; nlds.+ ρs]) == collect(1:(nlds.+ nlds.+ sum(nlds.nρ)))
end

function getrhs{S}(nlds::NLDS{S})
function getrhs(nlds::NLDS{S}) where S
checkconsistency(nlds)
bs = [nlds.h - nlds.T * nlds.x_a]
Ks = [nlds.K]
Expand Down Expand Up @@ -451,7 +451,7 @@ function computecuts!(nlds::NLDS)
end
end

function getcutsDE{S}(nlds::NLDS{S})
function getcutsDE(nlds::NLDS{S}) where S
checkconsistency(nlds)
nc = nlds.+ sum(nlds.nρ)
A = spzeros(S, nc, nlds.nx + nlds.nθ)
Expand All @@ -467,7 +467,7 @@ function getcutsDE{S}(nlds::NLDS{S})
A
end

function load!{S}(nlds::NLDS{S})
function load!(nlds::NLDS{S}) where S
if !nlds.loaded
bigA = nlds.W
if nlds.> 0
Expand Down Expand Up @@ -527,7 +527,7 @@ function Eθlb(nlds::NLDS)
end
end

function solve!{S}(nlds::NLDS{S})
function solve!(nlds::NLDS{S}) where S
load!(nlds)
if !nlds.solved
MathProgBase.optimize!(nlds.model)
Expand Down
4 changes: 2 additions & 2 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mutable struct SDDPNode{S}
# Optimality cuts
ocuts::CutStore{S}

function (::Type{SDDPNode{S}}){S}(nlds::NLDS{S}, parent)
function SDDPNode{S}(nlds::NLDS{S}, parent) where S
nvars = size(nlds.W, 2)
root = parent === nothing
nvars_a = root ? 0 : parent.nvars
Expand All @@ -28,7 +28,7 @@ mutable struct SDDPNode{S}

end

SDDPNode{S}(nlds::NLDS{S}, parent) = SDDPNode{S}(nlds, parent)
SDDPNode(nlds::NLDS{S}, parent) where {S} = SDDPNode{S}(nlds, parent)

function Base.show(io::IO, node::SDDPNode)
if node.root
Expand Down
10 changes: 5 additions & 5 deletions src/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function merge!(p::SDDPPath, q::SDDPPath)
append!(p.K, q.K)
end

type SDDPJob{NodeT}
mutable struct SDDPJob{NodeT}
sol::Nullable{NLDSSolution}
proba::Vector{Float64}
K::Vector{Int}
Expand All @@ -58,15 +58,15 @@ function Base.isapprox(p::SDDPPath, q::SDDPPath)
Base.isapprox(p.sol.x, q.sol.x)
end

function addjob!{NodeT}(jobsd::Dict{NodeT, Vector{SDDPJob{NodeT}}}, node::NodeT, job::SDDPJob{NodeT})
function addjob!(jobsd::Dict{NodeT, Vector{SDDPJob{NodeT}}}, node::NodeT, job::SDDPJob{NodeT}) where NodeT
if node in keys(jobsd)
push!(jobsd[node], job)
else
jobsd[node] = [job]
end
end

function mergesamepaths{NodeT}(pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, stats, ztol)
function mergesamepaths(pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, stats, ztol) where NodeT
before = sum([sum([sum(path.K) for path in paths]) for (node, paths) in pathsd])
newpathsd = Tuple{NodeT, Vector{SDDPPath}}[]
stats.mergetime += @_time for (node, paths) in pathsd
Expand All @@ -91,7 +91,7 @@ function mergesamepaths{NodeT}(pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, s
newpathsd
end

function childjobs{NodeT}(g::AbstractSDDPGraph, pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, pathsampler, t, num_stages)
function childjobs(g::AbstractSDDPGraph, pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, pathsampler, t, num_stages) where NodeT
jobsd = Dict{NodeT, Vector{SDDPJob{NodeT}}}()
for (node, paths) in pathsd
if haschildren(g, node)
Expand All @@ -112,7 +112,7 @@ function childjobs{NodeT}(g::AbstractSDDPGraph, pathsd::Vector{Tuple{NodeT, Vect
jobsd
end

function jobstopaths{NodeT}(jobsd::Dict{NodeT, Vector{SDDPJob{NodeT}}}, g::AbstractSDDPGraph)
function jobstopaths(jobsd::Dict{NodeT, Vector{SDDPJob{NodeT}}}, g::AbstractSDDPGraph) where NodeT
pathsd = Tuple{NodeT, Vector{SDDPPath}}[]
for (node, jobs) in jobsd
K = [find(job.K .!= 0) for job in jobs]
Expand Down
2 changes: 1 addition & 1 deletion src/sddp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The paths will be selected according to `pathsampler` and equivalent paths might
The parameter `ztol` is also used to check whether a new cut is useful.
When a scenario is infeasible and `stopatinf` is true then no other scenario with the same ancestor is run. Note that since the order in which the different scenarios is run is not deterministic, this might introduce nondeterminism even if the sampling is deterministic.
"""
function iteration{S}(g::AbstractSDDPGraph{S}, Ktot::Int, num_stages, verbose, pathsampler; ztol=1e-6, stopatinf=false, mergepaths=true, forwardcuts=false, backwardcuts=true)
function iteration(g::AbstractSDDPGraph{S}, Ktot::Int, num_stages, verbose, pathsampler; ztol=1e-6, stopatinf=false, mergepaths=true, forwardcuts=false, backwardcuts=true) where S
stats = SDDPStats()

master, initialnode = getmaster(g)
Expand Down
2 changes: 1 addition & 1 deletion src/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export AbstractSDDPStats

abstract type AbstractSDDPStats end

type SDDPStats <: AbstractSDDPStats
mutable struct SDDPStats <: AbstractSDDPStats
# number of calls to solver
nsolved::Int
# total time passed inside solver
Expand Down
12 changes: 6 additions & 6 deletions src/stopcrit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $(TYPEDEF)
Stops if `lhs` *or* `rhs` want to stop.
"""
type OrStoppingCriterion <: AbstractStoppingCriterion
mutable struct OrStoppingCriterion <: AbstractStoppingCriterion
lhs::AbstractStoppingCriterion
rhs::AbstractStoppingCriterion
end
Expand All @@ -38,7 +38,7 @@ $(TYPEDEF)
Stops if `lhs` *and* `rhs` want to stop.
"""
type AndStoppingCriterion <: AbstractStoppingCriterion
mutable struct AndStoppingCriterion <: AbstractStoppingCriterion
lhs::AbstractStoppingCriterion
rhs::AbstractStoppingCriterion
end
Expand All @@ -56,7 +56,7 @@ $(TYPEDEF)
Stops if `iter` ≧ `limit`.
"""
type IterLimit <: AbstractStoppingCriterion
mutable struct IterLimit <: AbstractStoppingCriterion
limit::Int
end

Expand All @@ -70,7 +70,7 @@ $(TYPEDEF)
Stops if there was less than or equal to `limit` cuts added in the iteration.
For instance, `CutLimit(0)` stops when there are no cuts added.
"""
type CutLimit <: AbstractStoppingCriterion
mutable struct CutLimit <: AbstractStoppingCriterion
limit::Int
end

Expand All @@ -85,7 +85,7 @@ $(TYPEDEF)
Stops if total time of execution is greater than the time limit specified.
For instance, `TimeLimit(100)` stops after 100s.
"""
type TimeLimit <: AbstractStoppingCriterion
mutable struct TimeLimit <: AbstractStoppingCriterion
timelimit::Float64
end

Expand All @@ -99,7 +99,7 @@ $(TYPEDEF)
Stops if `z_UB - α * σ/√K - tol < z_LB < z_UB + α * σ/√K + tol` and `σ / √K > β * max(1, |z_LB|))`
"""
type Pereira <: AbstractStoppingCriterion
mutable struct Pereira <: AbstractStoppingCriterion
α::Float64
β::Float64
tol::Float64
Expand Down
2 changes: 1 addition & 1 deletion src/waitandsee.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export waitandsee

type WSPath
mutable struct WSPath
node::SDDPNode
nlds::Vector{NLDS}
z::Float64
Expand Down
2 changes: 1 addition & 1 deletion test/stopcrit.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type InvalidStoppingCriterion <: AbstractStoppingCriterion
mutable struct InvalidStoppingCriterion <: AbstractStoppingCriterion
end

@testset "Stopping Criterion" begin
Expand Down

0 comments on commit 05d620e

Please sign in to comment.