From 81cabeb33bd10f97dfa94c30070971103647dff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 5 Jun 2017 15:56:22 +0200 Subject: [PATCH] Add support for Julia v0.6 --- REQUIRE | 1 + src/StructDualDynProg.jl | 2 ++ src/cutstore.jl | 4 ++-- src/interface.jl | 10 +++++----- src/nlds.jl | 4 ++-- src/node.jl | 4 ++-- src/paths.jl | 2 +- src/sddptree.jl | 2 +- src/stats.jl | 2 +- src/stopcrit.jl | 2 +- 10 files changed, 18 insertions(+), 15 deletions(-) diff --git a/REQUIRE b/REQUIRE index f15c8be..92ea683 100644 --- a/REQUIRE +++ b/REQUIRE @@ -4,3 +4,4 @@ MathProgBase 0.5 JuMP 0.17 StructJuMP 0.0.1 DocStringExtensions 0.2 +Compat 0.17 diff --git a/src/StructDualDynProg.jl b/src/StructDualDynProg.jl index 52d9534..4277ec8 100644 --- a/src/StructDualDynProg.jl +++ b/src/StructDualDynProg.jl @@ -2,6 +2,8 @@ __precompile__() module StructDualDynProg +using Compat + using DocStringExtensions using CutPruners diff --git a/src/cutstore.jl b/src/cutstore.jl index 9453b76..15bbb9e 100644 --- a/src/cutstore.jl +++ b/src/cutstore.jl @@ -33,8 +33,8 @@ type CutStore{S} storecuts::Symbol - function CutStore(nvars) - new(spzeros(S, 0, nvars), spzeros(S, 0), NLDS{S}[], spzeros(S, 0, nvars), spzeros(S, 0), NLDS{S}[], Vector{Tuple{NLDS{S},Tuple{Symbol,Int64}}}(0), Vector{Bool}(0), :IfNeededElseDelete) + function (::Type{CutStore{S}}){S}(nvars) + new{S}(spzeros(S, 0, nvars), spzeros(S, 0), NLDS{S}[], spzeros(S, 0, nvars), spzeros(S, 0), NLDS{S}[], Vector{Tuple{NLDS{S},Tuple{Symbol,Int64}}}(0), Vector{Bool}(0), :IfNeededElseDelete) end end diff --git a/src/interface.jl b/src/interface.jl index eb8658c..f16c24d 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -17,14 +17,14 @@ function getSDDPNode(allnodes, m::Model, t, num_stages, solver, parent, pruninga newnode = SDDPNode(NLDS{Float64}(W,h,T,K,C,c,solver,pruningalgo, newcut), parent) nodes[t] = newnode push!(allnodes[t], newnode) - struct = getStructure(m) + struc = getStructure(m) if t < num_stages - num_scen = length(struct.children) + num_scen = length(struc.children) children = Vector{SDDPNode{Float64}}(num_scen) probability = Vector{Float64}(num_scen) - for (i, id) in enumerate(keys(struct.children)) - children[i] = getSDDPNode(allnodes, struct.children[id], t+1, num_stages, solver, newnode, pruningalgo, cutmode, detectlb, newcut) - probability[i] = struct.probability[id] + for (i, id) in enumerate(keys(struc.children)) + children[i] = getSDDPNode(allnodes, struc.children[id], t+1, num_stages, solver, newnode, pruningalgo, cutmode, detectlb, newcut) + probability[i] = struc.probability[id] end setchildren!(newnode, children, probability, cutmode) if detectlb diff --git a/src/nlds.jl b/src/nlds.jl index 35271d0..1bb4833 100644 --- a/src/nlds.jl +++ b/src/nlds.jl @@ -92,7 +92,7 @@ type NLDS{S} FCpruner::AbstractCutPruner OCpruners::Vector - function NLDS(W::AbstractMatrix{S}, h::AbstractVector{S}, T::AbstractMatrix{S}, K, C, c::AbstractVector{S}, solver, pruningalgo::AbstractCutPruningAlgo, newcut::Symbol=:AddImmediately) + 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) nx = size(W, 2) nθ = 0 nπ = length(h) @@ -105,7 +105,7 @@ type NLDS{S} else model = MathProgBase.LinearQuadraticModel(solver) end - nlds = new(W, h, T, K, C, c, S[], nothing, nothing, CutStore{S}[], CutStore{S}[], localFC, localOC, nothing, Float64[], [], nothing, :NoOptimalityCut, nx, nθ, nπ, 1:nπ, 0, Int[], Int[], Vector{Int}[], model, false, false, nothing, newcut, pruningalgo, FCpruner, OCpruners) + nlds = new{S}(W, h, T, K, C, c, S[], nothing, nothing, CutStore{S}[], CutStore{S}[], localFC, localOC, nothing, Float64[], [], nothing, :NoOptimalityCut, nx, nθ, nπ, 1:nπ, 0, Int[], Int[], Vector{Int}[], model, false, false, nothing, newcut, pruningalgo, FCpruner, OCpruners) addfollower(localFC, (nlds, (:Feasibility, 0))) addfollower(localOC, (nlds, (:Optimality, 1))) nlds diff --git a/src/node.jl b/src/node.jl index 0301d70..c828a80 100644 --- a/src/node.jl +++ b/src/node.jl @@ -19,11 +19,11 @@ type SDDPNode{S} # Optimality cuts ocuts::CutStore{S} - function SDDPNode(nlds::NLDS{S}, parent) + function (::Type{SDDPNode{S}}){S}(nlds::NLDS{S}, parent) nvars = size(nlds.W, 2) root = parent === nothing nvars_a = root ? 0 : parent.nvars - new(nlds, nvars, parent, SDDPNode[], Float64[], nothing, root, true, Dict{Tuple{Int,Int},Int}(), CutStore{S}(nvars_a), CutStore{S}(nvars_a)) + new{S}(nlds, nvars, parent, SDDPNode[], Float64[], nothing, root, true, Dict{Tuple{Int,Int},Int}(), CutStore{S}(nvars_a), CutStore{S}(nvars_a)) end end diff --git a/src/paths.jl b/src/paths.jl index daba631..aadd3c0 100644 --- a/src/paths.jl +++ b/src/paths.jl @@ -1,5 +1,5 @@ export AbstractPathSampler -abstract AbstractPathSampler +@compat abstract type AbstractPathSampler end function _samplepaths!(_npaths, npaths, pmf, semirandom::Bool, canmodifypmf::Bool) if semirandom diff --git a/src/sddptree.jl b/src/sddptree.jl index 0d4956d..11b8d6d 100644 --- a/src/sddptree.jl +++ b/src/sddptree.jl @@ -1,5 +1,5 @@ export AbstractSDDPTree -abstract AbstractSDDPTree{S} +@compat abstract type AbstractSDDPTree{S} end type GraphSDDPTree{S} <: AbstractSDDPTree{S} root::SDDPNode{S} diff --git a/src/stats.jl b/src/stats.jl index 8e17d9d..c77946d 100644 --- a/src/stats.jl +++ b/src/stats.jl @@ -1,6 +1,6 @@ export AbstractSDDPStats -abstract AbstractSDDPStats +@compat abstract type AbstractSDDPStats end type SDDPStats <: AbstractSDDPStats # number of calls to solver diff --git a/src/stopcrit.jl b/src/stopcrit.jl index dddd443..23bf16a 100644 --- a/src/stopcrit.jl +++ b/src/stopcrit.jl @@ -1,7 +1,7 @@ import Base.|, Base.& export stop, AbstractStoppingCriterion, OrStoppingCriterion, AndStoppingCriterion, IterLimit, Pereira, CutLimit, TimeLimit -abstract AbstractStoppingCriterion +@compat abstract type AbstractStoppingCriterion end """ $(SIGNATURES)