Skip to content

Commit 9b6eed2

Browse files
committed
SDDPTree -> SDDPGraph
1 parent 2c2dfbf commit 9b6eed2

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

src/graph.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
export AbstractSDDPTree, haschildren, nchidren, children, getchild, getproba, getprobas, cutgen, numberofpaths
2-
abstract type AbstractSDDPTree{S} end
1+
export AbstractSDDPGraph, haschildren, nchidren, children, getchild, getproba, getprobas, cutgen, numberofpaths
2+
abstract type AbstractSDDPGraph{S} end
33

4-
mutable struct GraphSDDPTree{S} <: AbstractSDDPTree{S}
4+
mutable struct SDDPGraph{S} <: AbstractSDDPGraph{S}
55
root::SDDPNode{S}
66
end
77

8-
getmaster(g::GraphSDDPTree) = g.root, g.root
8+
getmaster(g::SDDPGraph) = g.root, g.root
99

1010
# Get children scenarios
11-
haschildren(g::GraphSDDPTree, node::SDDPNode) = !isempty(node.children)
12-
nchildren(g::GraphSDDPTree, node::SDDPNode) = length(node.children)
13-
children(g::GraphSDDPTree, node::SDDPNode) = node.children
14-
getchild(g::GraphSDDPTree, node::SDDPNode, i) = node.children[i]
11+
haschildren(g::SDDPGraph, node::SDDPNode) = !isempty(node.children)
12+
nchildren(g::SDDPGraph, node::SDDPNode) = length(node.children)
13+
children(g::SDDPGraph, node::SDDPNode) = node.children
14+
getchild(g::SDDPGraph, node::SDDPNode, i) = node.children[i]
1515
# Get proba of children scenario
16-
getproba(g::GraphSDDPTree, node::SDDPNode, i) = node.proba[i]
17-
getprobas(g::GraphSDDPTree, node::SDDPNode) = node.proba
16+
getproba(g::SDDPGraph, node::SDDPNode, i) = node.proba[i]
17+
getprobas(g::SDDPGraph, node::SDDPNode) = node.proba
1818

1919
# Get number of paths
20-
numberofpaths(g::GraphSDDPTree, num_stages) = numberofpaths(g.root, 1, num_stages)
21-
numberofpaths(g::GraphSDDPTree, node::SDDPNode, t, num_stages) = numberofpaths(node, t, num_stages)
20+
numberofpaths(g::SDDPGraph, num_stages) = numberofpaths(g.root, 1, num_stages)
21+
numberofpaths(g::SDDPGraph, node::SDDPNode, t, num_stages) = numberofpaths(node, t, num_stages)
2222

23-
cutgen(g::GraphSDDPTree, node::SDDPNode) = node.nlds.cutgen
23+
cutgen(g::SDDPGraph, node::SDDPNode) = node.nlds.cutgen

src/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ If `cutgen` is `MultiCutGenerator`, one variable `θ_i` is created for each scen
4444
"""
4545
function model2lattice(m::Model, num_stages, solver, pruningalgo::AbstractCutPruningAlgo, cutgen::AbstractOptimalityCutGenerator=MultiCutGenerator, detectlb::Bool=true, newcut::Symbol=:InvalidateSolver)
4646
root = getSDDPNode(m, 1, num_stages, solver, nothing, pruningalgo, cutgen, detectlb, newcut)
47-
GraphSDDPTree(root)
47+
SDDPGraph(root)
4848
end
4949

5050
function SDDPclear(m::Model)

src/path.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function mergesamepaths{NodeT}(pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, s
9191
newpathsd
9292
end
9393

94-
function childjobs{NodeT}(g::AbstractSDDPTree, pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, pathsampler, t, num_stages)
94+
function childjobs{NodeT}(g::AbstractSDDPGraph, pathsd::Vector{Tuple{NodeT, Vector{SDDPPath}}}, pathsampler, t, num_stages)
9595
jobsd = Dict{NodeT, Vector{SDDPJob{NodeT}}}()
9696
for (node, paths) in pathsd
9797
if haschildren(g, node)
@@ -112,7 +112,7 @@ function childjobs{NodeT}(g::AbstractSDDPTree, pathsd::Vector{Tuple{NodeT, Vecto
112112
jobsd
113113
end
114114

115-
function jobstopaths{NodeT}(jobsd::Dict{NodeT, Vector{SDDPJob{NodeT}}}, g::AbstractSDDPTree)
115+
function jobstopaths{NodeT}(jobsd::Dict{NodeT, Vector{SDDPJob{NodeT}}}, g::AbstractSDDPGraph)
116116
pathsd = Tuple{NodeT, Vector{SDDPPath}}[]
117117
for (node, jobs) in jobsd
118118
K = [find(job.K .!= 0) for job in jobs]

src/sampler.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function _samplepaths(npaths, pmf, semirandom::Bool, canmodifypmf::Bool)
4949
end
5050
infpaths(g, node) = fill(-1, nchildren(g, node))
5151

52-
function samplepaths(pathsampler::AbstractPathSampler, g::GraphSDDPTree, node, npaths::Vector{Int}, t, num_stages)
52+
function samplepaths(pathsampler::AbstractPathSampler, g::AbstractSDDPGraph, node, npaths::Vector{Int}, t, num_stages)
5353
npathss = Vector{Int}[similar(npaths) for i in 1:nchildren(g, node)]
5454
for i in 1:length(npaths)
5555
_npaths = samplepaths(pathsampler, g, node, npaths[i], t, num_stages)
@@ -63,7 +63,7 @@ end
6363
struct ProbaPathSampler <: AbstractPathSampler
6464
semirandom::Bool
6565
end
66-
function samplepaths(pathsampler::ProbaPathSampler, g::GraphSDDPTree, node, npaths::Int, t, num_stages)
66+
function samplepaths(pathsampler::ProbaPathSampler, g::AbstractSDDPGraph, node, npaths::Int, t, num_stages)
6767
if npaths == -1
6868
infpaths(g, node)
6969
else
@@ -74,7 +74,7 @@ end
7474
struct NumPathsPathSampler <: AbstractPathSampler
7575
semirandom::Bool
7676
end
77-
function samplepaths(pathsampler::NumPathsPathSampler, g::GraphSDDPTree, node, npaths::Int, t, num_stages)
77+
function samplepaths(pathsampler::NumPathsPathSampler, g::AbstractSDDPGraph, node, npaths::Int, t, num_stages)
7878
if npaths == -1
7979
infpaths(g, node)
8080
else

src/sddp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The paths will be selected according to `pathsampler` and equivalent paths might
5050
The parameter `ztol` is also used to check whether a new cut is useful.
5151
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.
5252
"""
53-
function iteration{S}(g::AbstractSDDPTree{S}, Ktot::Int, num_stages, verbose, pathsampler; ztol=1e-6, stopatinf=false, mergepaths=true, forwardcuts=false, backwardcuts=true)
53+
function iteration{S}(g::AbstractSDDPGraph{S}, Ktot::Int, num_stages, verbose, pathsampler; ztol=1e-6, stopatinf=false, mergepaths=true, forwardcuts=false, backwardcuts=true)
5454
stats = SDDPStats()
5555

5656
master, initialnode = getmaster(g)
@@ -138,7 +138,7 @@ The parameter `ztol` is also used to check whether a new cut is useful.
138138
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.
139139
By default, the cuts are added backward. However, if `forwardcuts` is set to `true` and `backwardcuts` is set to `false` the cuts are added forward.
140140
"""
141-
function SDDP(g::AbstractSDDPTree, num_stages; K::Int=25, stopcrit::AbstractStoppingCriterion=Pereira(), verbose=0, pathsampler::AbstractPathSampler=ProbaPathSampler(true), ztol=1e-6, stopatinf=false, mergepaths=true, forwardcuts=false, backwardcuts=true)
141+
function SDDP(g::AbstractSDDPGraph, num_stages; K::Int=25, stopcrit::AbstractStoppingCriterion=Pereira(), verbose=0, pathsampler::AbstractPathSampler=ProbaPathSampler(true), ztol=1e-6, stopatinf=false, mergepaths=true, forwardcuts=false, backwardcuts=true)
142142
mastersol = nothing
143143
totalstats = SDDPStats()
144144
stats = SDDPStats()

src/waitandsee.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function meanstdpaths(paths::Vector{WSPath}, totalK)
1515
meanstdpaths(z, proba, npaths, totalK)
1616
end
1717

18-
function waitandsee(g::AbstractSDDPTree, num_stages, solver, totalK=25, verbose=0)
18+
function waitandsee(g::AbstractSDDPGraph, num_stages, solver, totalK=25, verbose=0)
1919
root = g.root
2020
paths = WSPath[WSPath(root, NLDS[root.nlds], .0, 1., totalK)]
2121
for t in 2:num_stages

0 commit comments

Comments
 (0)