Skip to content

Commit cec0e42

Browse files
committed
[UPD] Improve initialization of value functions
1 parent 8d8adda commit cec0e42

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/SDDPoptimize.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ function run_SDDP!(model::SPModel,
9898
V,
9999
problems,
100100
stockTrajectories,
101-
model.noises,
102-
false)
101+
model.noises)
103102

104103
#Update the number of call
105104
stats.ncallsolver += callsolver_forward + callsolver_backward
@@ -315,7 +314,8 @@ function initialize_value_functions(model::SPModel,
315314

316315
solverProblems = build_models(model, param)
317316

318-
V = Array{PolyhedralFunction}(model.stageNumber)
317+
V = PolyhedralFunction[
318+
PolyhedralFunction([], Array{Float64}(0, model.dimStates), 0) for i in 1:model.stageNumber]
319319

320320
# Build scenarios according to distribution laws:
321321
aleas = simulate_scenarios(model.noises, param.forwardPassNumber)
@@ -339,8 +339,7 @@ function initialize_value_functions(model::SPModel,
339339
V,
340340
solverProblems,
341341
stockTrajectories,
342-
model.noises,
343-
true)
342+
model.noises)
344343

345344
return V, solverProblems
346345
end

src/forwardBackwardIterations.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,13 @@ the current estimation of Vt.
169169
for scenario k and time t.
170170
* `law::Array{NoiseLaw}`:
171171
Conditionnal distributions of perturbation, for each timestep
172-
* `init::Bool`:
173-
If specified, then init PolyhedralFunction
174172
"""
175173
function backward_pass!(model::SPModel,
176174
param::SDDPparameters,
177175
V::Vector{PolyhedralFunction},
178176
solverProblems::Vector{JuMP.Model},
179177
stockTrajectories::Array{Float64, 3},
180-
law,
181-
init=false::Bool)
178+
law)
182179

183180
callsolver::Int = 0
184181

@@ -222,11 +219,7 @@ function backward_pass!(model::SPModel,
222219
beta = costs_npass - dot(subgradient, state_t)
223220

224221
# Add cut to polyhedral function and JuMP model:
225-
if init
226-
V[t] = PolyhedralFunction([beta], reshape(subgradient, 1, model.dimStates), 1)
227-
else
228-
add_cut!(model, t, V[t], beta, subgradient)
229-
end
222+
add_cut!(model, t, V[t], beta, subgradient)
230223
if t > 1
231224
add_cut_to_model!(model, solverProblems[t-1], t, beta, subgradient)
232225
end

test/sddp.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ facts("SDDP algorithm: 1D case") do
7575
@fact length(V) --> n_stages
7676

7777
# Test if the first subgradient has the same dimension as state:
78-
@fact length(V[1].lambdas[1, :]) --> model.dimStates
79-
@fact V[1].numCuts --> n_scenarios*max_iterations + 1
80-
@fact length(V[1].lambdas[:, 1]) --> n_scenarios*max_iterations + 1
78+
@fact size(V[1].lambdas, 2) --> model.dimStates
79+
@fact V[1].numCuts --> n_scenarios*max_iterations + n_scenarios
80+
@fact size(V[1].lambdas, 1) --> n_scenarios*max_iterations + n_scenarios
8181

8282
# Test upper bounds estimation with Monte-Carlo:
8383
n_simulations = 100

0 commit comments

Comments
 (0)