Skip to content

Commit c41c613

Browse files
committed
[UPD] Fix naming between SDDP and DP algorithms
1 parent 10e630c commit c41c613

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

examples/benchmark.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ function benchmark_sdp()
328328
timing = zeros(n_benchmark)
329329
for n in 1:n_benchmark
330330
tic()
331-
V_sdp = sdp_optimize(modelSDP, paramsSDP,false);
331+
V_sdp = solve_DP(modelSDP, paramsSDP,1);
332332
timing[n] = toq()
333333
end
334334
@show timing

src/SDPoptimize.jl

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Parameters:
177177
- param (SDPparameters)
178178
the parameters for the SDP algorithm
179179
180-
- display (Bool)
180+
- display (Int)
181181
the output display or verbosity parameter
182182
183183
@@ -187,9 +187,9 @@ Returns :
187187
of the system at each time step
188188
189189
"""
190-
function sdp_optimize(model::SPModel,
190+
function solve_DP(model::SPModel,
191191
param::SDPparameters,
192-
display=true::Bool)
192+
display=true::Int64)
193193

194194
SDPmodel = build_sdpmodel_from_spmodel(model::SPModel)
195195

@@ -217,7 +217,7 @@ Parameters:
217217
- param (SDPparameters)
218218
the parameters for the SDP algorithm
219219
220-
- display (Bool)
220+
- display (Int)
221221
the output display or verbosity parameter
222222
223223
@@ -229,7 +229,7 @@ Returns :
229229
"""
230230
function sdp_solve_DH(model::StochDynProgModel,
231231
param::SDPparameters,
232-
display=true::Bool)
232+
display=0::Int64)
233233

234234
TF = model.stageNumber
235235
next_state = zeros(Float64, model.dimStates)
@@ -253,23 +253,19 @@ function sdp_solve_DH(model::StochDynProgModel,
253253
end
254254

255255
#Construct a progress meter
256-
if display
256+
if display > 0
257257
p = Progress((TF-1)*param.totalStateSpaceSize, 1)
258-
end
259-
260-
#Display start of the algorithm in DH and HD cases
261-
if display
262258
println("Starting stochastic dynamic programming decision hazard computation")
263259
end
264260

265-
#Loop over time
261+
# Loop over time:
266262
for t = (TF-1):-1:1
267263
Vitp = value_function_interpolation(model, V, t+1)
268264

269265
#Loop over states
270266
for x in product_states
271267

272-
if display
268+
if display > 0
273269
next!(p)
274270
end
275271

@@ -342,7 +338,7 @@ Parameters:
342338
- param (SDPparameters)
343339
the parameters for the SDP algorithm
344340
345-
- display (Bool)
341+
- display (Int)
346342
the output display or verbosity parameter
347343
348344
@@ -354,7 +350,7 @@ Returns :
354350
"""
355351
function sdp_solve_HD(model::StochDynProgModel,
356352
param::SDPparameters,
357-
display=true::Bool)
353+
display=0::Int64)
358354

359355
TF = model.stageNumber
360356
next_state = zeros(Float64, model.dimStates)
@@ -378,11 +374,8 @@ function sdp_solve_HD(model::StochDynProgModel,
378374
end
379375

380376
#Construct a progress meter
381-
if display
377+
if display > 0
382378
p = Progress((TF-1)*param.totalStateSpaceSize, 1)
383-
end
384-
385-
if display
386379
println("Starting stochastic dynamic programming hazard decision computation")
387380
end
388381

@@ -393,7 +386,7 @@ function sdp_solve_HD(model::StochDynProgModel,
393386
#Loop over states
394387
for x in product_states
395388

396-
if display
389+
if display > 0
397390
next!(p)
398391
end
399392

@@ -474,7 +467,7 @@ Returns :
474467
- V(x0) (Float64)
475468
476469
"""
477-
function get_value(model::SPModel,param::SDPparameters,V::Array{Float64})
470+
function get_bellman_value(model::SPModel, param::SDPparameters, V::Array{Float64})
478471
ind_x0 = real_index_from_variable(model.initialState, model.xlim, param.stateSteps)
479472
Vi = value_function_interpolation(model, V, 1)
480473
return Vi[ind_x0...,1]
@@ -495,7 +488,7 @@ Parameters:
495488
the scenarios of uncertainties realizations we want to simulate on
496489
scenarios[t,k,:] is the alea at time t for scenario k
497490
498-
- value_functions (Array)
491+
- V (Array)
499492
the vector representing the value functions as functions of the state
500493
of the system at each time step
501494
@@ -517,8 +510,8 @@ Returns :
517510
function sdp_forward_simulation(model::SPModel,
518511
param::SDPparameters,
519512
scenarios::Array{Float64,3},
520-
value::Array,
521-
display=true::Bool)
513+
V::Array,
514+
display=false::Bool)
522515

523516
SDPmodel = build_sdpmodel_from_spmodel(model)
524517
TF = SDPmodel.stageNumber
@@ -530,7 +523,6 @@ function sdp_forward_simulation(model::SPModel,
530523

531524

532525
for k = 1:nb_scenarios
533-
#println(k)
534526
costs[k], states[:,k], controls[:,k] = sdp_forward_single_simulation(SDPmodel,
535527
param,scenarios[:,k],model.initialState,value,display)
536528
end
@@ -701,7 +693,7 @@ Parameters:
701693
- X0 (SDPparameters)
702694
the initial state of the system
703695
704-
- value_functions (Array)
696+
- V (Array)
705697
the vector representing the value functions as functions of the state
706698
of the system at each time step
707699
@@ -724,7 +716,7 @@ function sdp_forward_single_simulation(model::StochDynProgModel,
724716
param::SDPparameters,
725717
scenario::Array,
726718
X0::Array,
727-
value::Array,
719+
V::Array,
728720
display=true::Bool)
729721

730722
TF = model.stageNumber
@@ -757,7 +749,7 @@ function sdp_forward_single_simulation(model::StochDynProgModel,
757749
x = states[t,1,:]
758750

759751
best_V = Inf
760-
Vitp = value_function_interpolation(model, value, t+1)
752+
Vitp = value_function_interpolation(model, V, t+1)
761753

762754
for u in product_controls
763755

@@ -816,7 +808,7 @@ function sdp_forward_single_simulation(model::StochDynProgModel,
816808

817809
x = states[t,1,:]
818810

819-
Vitp = value_function_interpolation(model, value, t+1)
811+
Vitp = value_function_interpolation(model, V, t+1)
820812

821813
best_V = Inf
822814

src/StochDynamicProgramming.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export solve_SDDP, NoiseLaw, simulate_scenarios,
1616
SDDPparameters, LinearDynamicLinearCostSPmodel, set_state_bounds,
1717
PiecewiseLinearCostSPmodel,
1818
PolyhedralFunction, NextStep, forward_simulations,
19-
StochDynProgModel, SDPparameters, sdp_optimize,
20-
sdp_forward_simulation, sampling, get_control, get_value
19+
StochDynProgModel, SDPparameters, solve_DP,
20+
sdp_forward_simulation, sampling, get_control, get_bellman_value
2121

2222
include("objects.jl")
2323
include("utils.jl")

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ facts("SDP algorithm") do
436436

437437
context("Solve and simulate using SDP") do
438438

439-
V_sdp = sdp_optimize(modelSDP, paramsSDP, false);
439+
V_sdp = solve_DP(modelSDP, paramsSDP, false);
440440

441441
@fact size(V_sdp) --> (paramsSDP.stateVariablesSizes..., TF)
442442

@@ -446,7 +446,7 @@ facts("SDP algorithm") do
446446
V_sdp, true )
447447

448448
x = x0
449-
V_sdp = sdp_optimize(modelSDP, paramsSDP, false);
449+
V_sdp = solve_DP(modelSDP, paramsSDP, false);
450450
V_sdp2 = StochDynamicProgramming.sdp_solve_HD(modelSDP, paramsSDP, false);
451451
V_sdp3 = StochDynamicProgramming.sdp_solve_DH(modelSDP, paramsSDP, false);
452452

@@ -473,7 +473,7 @@ facts("SDP algorithm") do
473473
@fact length(collect(b)) --> (u_bounds[1][2]-u_bounds[1][1]+u_steps[1])*(u_bounds[2][2]-u_bounds[2][1]+u_steps[2])/(u_steps[1]*u_steps[2])
474474

475475
ind = StochDynamicProgramming.index_from_variable(x, x_bounds, x_steps)
476-
@fact get_value(modelSDP, paramsSDP, V_sdp2) --> V_sdp2[ind...,1]
476+
@fact get_bellman_value(modelSDP, paramsSDP, V_sdp2) --> V_sdp2[ind...,1]
477477

478478
@fact size(V_sdp) --> (paramsSDP.stateVariablesSizes..., TF)
479479
@fact V_sdp2[1,1,1] <= V_sdp3[1,1,1] --> true

0 commit comments

Comments
 (0)