Skip to content

Commit

Permalink
Merge 962fea8 into df8258c
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 6, 2017
2 parents df8258c + 962fea8 commit 728304d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ MathProgBase 0.5
JuMP 0.17
StructJuMP 0.0.1
DocStringExtensions 0.2
Compat 0.17
2 changes: 2 additions & 0 deletions src/StructDualDynProg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ __precompile__()

module StructDualDynProg

using Compat

using DocStringExtensions

using CutPruners
Expand Down
13 changes: 7 additions & 6 deletions src/cutstore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ 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)
# spzeros(S, 0) -> S[] : See julia#22225
new{S}(spzeros(S, 0, nvars), S[], NLDS{S}[], spzeros(S, 0, nvars), S[], NLDS{S}[], Vector{Tuple{NLDS{S},Tuple{Symbol,Int64}}}(0), Vector{Bool}(0), :IfNeededElseDelete)
end
end

function checksparseness(a::Vector)
function checksparseness(a::AbstractVector)
if true || countnz(a) * 2 < length(a)
sparse(a)
else
a
end
end

function addcut{S}(store::CutStore{S}, a::Vector{S}, β::S, author)
function addcut{S}(store::CutStore{S}, a::AbstractVector{S}, β::S, author)
a = checksparseness(a)
store.Anew = mymatcat(store.Anew, a)
store.bnew = myveccat(store.bnew, β)
Expand All @@ -66,7 +67,7 @@ function apply!{S}(store::CutStore{S})
end

store.Anew = spzeros(S, 0, size(store.A, 2))
store.bnew = spzeros(S, 0)
store.bnew = S[] # See julia#22225
store.authorsnew = NLDS{S}[]
end
end
Expand All @@ -83,7 +84,7 @@ function noneedstored!{S}(store::CutStore{S}, nlds)
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))
store.b = spzeros(S, 0)
store.b = S[] # See julia#22225
store.authors = NLDS{S}[]
end
end
10 changes: 5 additions & 5 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/nlds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
= 0
= length(h)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/paths.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export AbstractPathSampler
abstract AbstractPathSampler
@compat abstract type AbstractPathSampler end

function _samplepaths!(_npaths, npaths, pmf, semirandom::Bool, canmodifypmf::Bool)
if semirandom
Expand Down
2 changes: 1 addition & 1 deletion src/sddptree.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export AbstractSDDPTree
abstract AbstractSDDPTree{S}
@compat abstract type AbstractSDDPTree{S} end

type GraphSDDPTree{S} <: AbstractSDDPTree{S}
root::SDDPNode{S}
Expand Down
2 changes: 1 addition & 1 deletion src/stats.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export AbstractSDDPStats

abstract AbstractSDDPStats
@compat abstract type AbstractSDDPStats end

type SDDPStats <: AbstractSDDPStats
# number of calls to solver
Expand Down
2 changes: 1 addition & 1 deletion src/stopcrit.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Base.|, Base.&
export stop, AbstractStoppingCriterion, OrStoppingCriterion, AndStoppingCriterion, IterLimit, Pereira, CutLimit, TimeLimit

abstract AbstractStoppingCriterion
@compat abstract type AbstractStoppingCriterion end

"""
$(SIGNATURES)
Expand Down

0 comments on commit 728304d

Please sign in to comment.