Skip to content

Commit 24d1a89

Browse files
author
Vincent Leclere
committed
[UPD] update stock-example
1 parent 237fc4c commit 24d1a89

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

examples/stock-example.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ push!(LOAD_PATH, "../src")
1414
using StochDynamicProgramming, JuMP, Clp, Distributions
1515
println("library loaded")
1616

17-
run_sddp = false
17+
run_sddp = true
1818
run_sdp = true
1919

2020
######## Optimization parameters ########
@@ -82,14 +82,13 @@ if run_sdp
8282
end
8383

8484
######### Comparing the solution
85-
scenarios = StochDynamicProgramming.simulate_scenarios(xi_laws,2)
85+
scenarios = StochDynamicProgramming.simulate_scenarios(xi_laws,1000)
8686
if run_sddp
87-
costs, stocks = forward_simulations(spmodel, paramSDDP, V, pbs, scenarios)
87+
costsddp, stocks = forward_simulations(spmodel, paramSDDP, V, pbs, scenarios)
8888
end
8989
if run_sdp
90-
costs, states, stocks =sdp_forward_simulation(spmodel,paramSDP,scenarios,Vs)
90+
costsdp, states, stocks =sdp_forward_simulation(spmodel,paramSDP,scenarios,Vs)
91+
end
92+
if run_sddp && run_sdp
93+
println(mean(costsddp-costsdp))
9194
end
92-
println(costs)
93-
94-
95-

src/SDPoptimize.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ Simulation of optimal trajectories given model and Bellman functions
463463
464464
Parameters:
465465
- model (SPmodel)
466-
the DPSPmodel of our problem
466+
the SPmodel of our problem
467467
468468
- param (SDPparameters)
469469
the parameters for the SDP algorithm
@@ -501,13 +501,16 @@ function sdp_forward_simulation(model::SPModel,
501501
nb_scenarios = size(scenarios)[2]
502502

503503
costs = zeros(nb_scenarios)
504-
controls = zeros(TF,nb_scenarios)
505-
states = zeros(TF-1,nb_scenarios)
504+
states = zeros(TF,nb_scenarios)
505+
controls = zeros(TF-1,nb_scenarios)
506+
506507

507508
for k = 1:nb_scenarios
508-
costs[k],states[:,k], controls[:,k]= sdp_forward_simulation(SDPmodel,
509+
#println(k)
510+
costs[k],states[:,k], controls[:,k] = sdp_forward_single_simulation(SDPmodel,
509511
param,scenarios[:,k],model.initialState,value,display)
510512
end
513+
511514
return costs, controls, states
512515
end
513516

@@ -546,7 +549,7 @@ Returns :
546549
the controls applied to the system at each time step
547550
548551
"""
549-
function sdp_forward_simulation(model::StochDynProgModel,
552+
function sdp_forward_single_simulation(model::StochDynProgModel,
550553
param::SDPparameters,
551554
scenario::Array,
552555
X0::Array,

0 commit comments

Comments
 (0)