Skip to content

Commit 11fac29

Browse files
committed
[DEV] Improve initialization of SDDP
1 parent 68dacfa commit 11fac29

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/SDDPoptimize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ function initialize_value_functions(model::SPModel,
306306
param::SDDPparameters)
307307

308308
solverProblems = build_models(model, param)
309-
solverProblems_null = build_models(model, param)
310309

311310
V = Array{PolyhedralFunction}(model.stageNumber)
312311

@@ -323,10 +322,11 @@ function initialize_value_functions(model::SPModel,
323322

324323
stockTrajectories = forward_simulations(model,
325324
param,
326-
solverProblems_null,
325+
solverProblems,
327326
aleas,
328327
true)[2]
329328

329+
330330
backward_pass!(model,
331331
param,
332332
V,

src/forwardBackwardIterations.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,28 @@ function forward_simulations(model::SPModel,
7373
state_t = extract_vector_from_3Dmatrix(stocks, t, k)
7474
alea_t = extract_vector_from_3Dmatrix(xi, t, k)
7575

76-
status, nextstep = solve_one_step_one_alea(
76+
if ~init
77+
status, nextstep = solve_one_step_one_alea(
7778
model,
7879
param,
7980
solverProblems[t],
8081
t,
8182
state_t,
82-
alea_t,
83-
init)
84-
85-
if status
86-
stocks[t+1, k, :] = nextstep.next_state
87-
opt_control = nextstep.optimal_control
88-
controls[t, k, :] = opt_control
89-
costs[k] += nextstep.cost - nextstep.cost_to_go
90-
if t==T-1
91-
costs[k] += nextstep.cost_to_go
83+
alea_t)
84+
if status
85+
stocks[t+1, k, :] = nextstep.next_state
86+
opt_control = nextstep.optimal_control
87+
controls[t, k, :] = opt_control
88+
costs[k] += nextstep.cost - nextstep.cost_to_go
89+
if t==T-1
90+
costs[k] += nextstep.cost_to_go
91+
end
92+
else
93+
stocks[t+1, k, :] = state_t
9294
end
9395
else
94-
stocks[t+1, k, :] = state_t
96+
stocks[t+1, k, :] = [model.xlim[i][1] + rand()*(model.xlim[i][2] - model.xlim[i][1]) for i in 1:model.dimStates]
9597
end
96-
9798
end
9899
end
99100
return costs, stocks, controls

0 commit comments

Comments
 (0)