Skip to content

Commit 007f89a

Browse files
committed
[FIX] move computation of upperbound in solve_SDDP
1 parent d3ffbab commit 007f89a

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

examples/damsvalley.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ end
8484
const FORWARD_PASS = 10.
8585
const EPSILON = .05
8686
# Maximum number of iterations
87-
const MAX_ITER = 50
87+
const MAX_ITER = 10
8888
##################################################
8989

9090
"""Build probability distribution at each timestep.
@@ -121,11 +121,17 @@ function init_problem()
121121
params = SDDPparameters(solver,
122122
passnumber=FORWARD_PASS,
123123
gap=EPSILON,
124-
max_iterations=MAX_ITER)
124+
pruning_algo="exact",
125+
max_iterations=20,
126+
prune_cuts=10)
125127
return model, params
126128
end
127129

128130
# Solve the problem:
129131
model, params = init_problem()
130-
V, pbs = solve_SDDP(model, params, 1)
132+
V, pbs = @time solve_SDDP(model, params, 1)
133+
aleas = simulate_scenarios(model.noises, 100)
134+
c, x, u = forward_simulations(model, params, pbs, aleas);
131135

136+
xx = reshape(x[5, :, :], 100, 5)
137+
v = V[5]

src/SDDPoptimize.jl

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,32 +135,27 @@ function run_SDDP!(model::SPModel,
135135
callsolver_backward = backward_pass!(model, param, V, problems, stockTrajectories, model.noises)
136136

137137
####################
138-
# cut pruning
139-
prune_cuts!(model, param, V, stockTrajectories, territory, stats.niterations, verbose)
140-
####################
141-
# Cut pruning
142-
#= prune_cuts!(model, param, V, stockTrajectories, territory, iteration_count, verbose) =#
143-
#= if (param.pruning[:period] > 0) && (iteration_count%param.pruning[:period]==0) =#
144-
#= problems = hotstart_SDDP(model, param, V) =#
145-
#= end =#
146-
138+
# Update stats
139+
lwb = get_bellman_value(model, param, 1, V[1], model.initialState)
140+
updateSDDPStat!(stats, callsolver_forward+callsolver_backward, lwb, upb, toq())
141+
print_current_stats(stats,verbose)
147142

143+
####################
144+
# cut pruning
145+
(param.pruning[:pruning]) && prune_cuts!(model, param, V, stockTrajectories, territory, stats.niterations, verbose)
146+
if param.pruning[:pruning] && (stats.niterations%param.pruning[:period]==0)
147+
problems = hotstart_SDDP(model, param, V)
148+
end
148149

149150
####################
150151
# In iteration upper bound estimation
151152
upb = in_iteration_upb_estimation(model, param, stats.niterations, verbose,
152153
upperbound_scenarios, upb, problems)
153154

154-
####################
155-
# Update stats
156-
lwb = get_bellman_value(model, param, 1, V[1], model.initialState)
157-
updateSDDPStat!(stats, callsolver_forward+callsolver_backward, lwb, upb, toq())
158155

159-
print_current_stats(stats,verbose)
160156
####################
161157
# Stopping test
162158
stopping_test = test_stopping_criterion(param,stats)
163-
stats.niterations += 1
164159
end
165160

166161
##########

src/objects.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ Update the SDDPStat object with the results of current iterations.
278278
"""
279279
function updateSDDPStat!(stats::SDDPStat,callsolver_at_it::Int64,lwb::Float64,upb::Float64,time)
280280
stats.ncallsolver += callsolver_at_it
281+
stats.niterations += 1
281282
push!(stats.lower_bounds, lwb)
282283
push!(stats.upper_bounds, upb)
283284
push!(stats.exectime, time)

0 commit comments

Comments
 (0)