Skip to content

Commit 7b6ff51

Browse files
author
Vincent Leclere
committed
[UPD] update stock-example and SDDPoptimize to have a simple SDDP working
1 parent 085a521 commit 7b6ff51

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

examples/stock-example.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ paramSDDP = SDDPparameters(SOLVER, 10, 0, MAX_ITER) # 10 forward path, stop at M
7272

7373
######### Solving the problem via SDDP
7474
#V, pbs = solve_SDDP(spmodel, paramSDDP, 10) # display information every 10 iterations
75-
#lb = StochDynamicProgramming.get_lower_bound(spmodel, params, V)
75+
#lb = StochDynamicProgramming.get_lower_bound(spmodel, paramSDDP, V)
7676
#println("Lower bound obtained by SDDP: "*string(lb))
7777

7878
######### Solving the problem via Dynamic Programming
7979

8080
stateSteps = [0.1]
8181
controlSteps = [0.1]
8282
infoStruct = "HD" # noise at time t is known before taking the decision at time t
83-
monteCarloSize = 1000
84-
paramSDP = SDPparameters(spmodel, stateSteps, controlSteps, monteCarloSize, infoStruct)
83+
84+
paramSDP = SDPparameters(spmodel, stateSteps, controlSteps, infoStruct)
8585
V = sdp_optimize(spmodel,paramSDP)
8686

8787

src/SDDPoptimize.jl

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ function run_SDDP(model::SPModel,
123123

124124
if (display > 0) && (iteration_count%display==0)
125125
println("Pass number ", iteration_count,
126-
"\tEstimation of upper-bound: ", upper_bound(costs),
127-
"\tLower-bound: ", get_bellman_value(model, param, 1, V[1], model.initialState),
128-
"\tTime: ", toq())
126+
"\tLower-bound: ", round(get_bellman_value(model, param, 1, V[1], model.initialState),4),
127+
"\tTime: ", round(toq(),2))
129128
end
130129

131130
end
@@ -137,11 +136,11 @@ function run_SDDP(model::SPModel,
137136

138137
println("Estimate upper-bound with Monte-Carlo ...")
139138
upb, costs = estimate_upper_bound(model, param, V, problems)
140-
println("Estimation of upper-bound: ", upb,
141-
"\tExact lower bound: ", V0,
142-
"\t Gap (\%) < ", (V0-upb)/V0 , " with prob. > 97.5 \%")
139+
println("Estimation of upper-bound: ", round(upb,4),
140+
"\tExact lower bound: ", round(V0,4),
141+
"\t Gap < ", round(100*(upb-V0)/V0) , "\% with prob. > 97.5 \%")
143142
println("Estimation of cost of the solution (fiability 95\%):",
144-
mean(costs), " +/- ", 1.96*std(costs)/sqrt(length(costs)))
143+
round(mean(costs),4), " +/- ", round(1.96*std(costs)/sqrt(length(costs)),4))
145144
end
146145

147146
return V, problems
@@ -432,6 +431,28 @@ function get_bellman_value(model::SPModel, param::SDDPparameters,
432431
end
433432

434433

434+
"""
435+
Compute value of Bellman function at point xt. Return V_t(xt)
436+
437+
Parameters:
438+
- model (SPModel)
439+
Parametrization of the problem
440+
441+
- param (SDDPparameters)
442+
Parameters of SDDP
443+
444+
- V (Vector{Polyhedral function})
445+
Estimation of bellman function as Polyhedral function
446+
447+
Return:
448+
current lower bound of the problem (Float64)
449+
"""
450+
function get_lower_bound(model::SPModel, param::SDDPparameters,
451+
V::Vector{PolyhedralFunction})
452+
return get_bellman_value(model, param, 1, V[1], model.initialState)
453+
end
454+
455+
435456
"""
436457
Add several cuts to JuMP.Model from a PolyhedralFunction
437458

src/SDPoptimize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ function sdp_solve_HD(model::SPModel,
288288
end
289289

290290
if display
291-
println("Starting stochastic dynamic programming hazard decision computation")
292-
end
291+
println("Starting stochastic dynamic programming hazard decision computation")
292+
end
293293

294294
#Loop over time
295295
for t = (TF-1):-1:1

src/objects.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type LinearDynamicLinearCostSPmodel <: SPModel
3737
for i = 1:dimStates
3838
push!(xbounds, (-Inf, Inf))
3939
end
40+
4041
return new(nstage, dimControls, dimStates, dimNoises, xbounds, ubounds, x0, cost, dynamic, aleas)
4142
end
4243
end
@@ -109,7 +110,6 @@ type StochDynProgModel <: SPModel
109110
end
110111

111112
function StochDynProgModel(model::PiecewiseLinearCostSPmodel, final, cons)
112-
113113
function cost(t,x,u,w)
114114
saved_cost = -Inf
115115
current_cost = 0

0 commit comments

Comments
 (0)