@@ -17,6 +17,7 @@ println("library loaded")
1717run_sddp = true # false if you don't want to run sddp
1818run_sdp = true # false if you don't want to run sdp
1919run_ef = true # false if you don't want to run extensive formulation
20+ test_simulation = true # false if you don't want to test your strategies
2021
2122# ####### Optimization parameters ########
2223# choose the LP solver used.
@@ -25,13 +26,13 @@ const SOLVER = ClpSolver() # require "using Clp"
2526
2627# convergence test
2728const MAX_ITER = 10 # number of iterations of SDDP
29+ const step = 0.1 # discretization step of SDP
2830
2931# ####### Stochastic Model Parameters ########
3032const N_STAGES = 6 # number of stages of the SP problem
3133const COSTS = [sin (3 * t)- 1 for t in 1 : N_STAGES]
3234# const COSTS = rand(N_STAGES) # randomly generating deterministic costs
3335
34-
3536const CONTROL_MAX = 0.5 # bounds on the control
3637const CONTROL_MIN = 0
3738
@@ -70,9 +71,8 @@ if run_sddp
7071 println (" Starting resolution by SDDP" )
7172 # 10 forward pass, stop at MAX_ITER
7273 paramSDDP = SDDPparameters (SOLVER,
73- passnumber= 10 ,
74- gap= 0 ,
75- max_iterations= MAX_ITER)
74+ passnumber= 10 ,
75+ max_iterations= MAX_ITER)
7676 V, pbs = solve_SDDP (spmodel, paramSDDP, 2 ) # display information every 2 iterations
7777 lb_sddp = StochDynamicProgramming. get_lower_bound (spmodel, paramSDDP, V)
7878 println (" Lower bound obtained by SDDP: " * string (round (lb_sddp,4 )))
8282# ######## Solving the problem via Dynamic Programming
8383if run_sdp
8484 tic ()
85- step = 0.01
8685 println (" Starting resolution by SDP" )
8786 stateSteps = [step] # discretization step of the state
8887 controlSteps = [step] # discretization step of the control
@@ -100,23 +99,18 @@ if run_ef
10099 println (" Starting resolution by Extensive Formulation" )
101100 value_ef = extensive_formulation (spmodel, paramSDDP)[1 ]
102101 println (" Value obtained by Extensive Formulation: " * string (round (value_ef,4 )))
103- println (" Relative error of SDP value: " * string (100 * round (value_sdp/ value_ef- 1 ,4 ))* " %" )
104- println (" Relative error of SDDP lower bound: " * string (100 * round (lb_sddp/ value_ef- 1 ,4 ))* " %" )
102+ println (" Relative error of SDP value: " * string (100 * round (abs ( value_sdp/ value_ef) - 1 ,4 ))* " %" )
103+ println (" Relative error of SDDP lower bound: " * string (100 * round (abs ( lb_sddp/ value_ef) - 1 ,4 ))* " %" )
105104 toc (); println ();
106105end
107106
108107# ######## Comparing the solutions on simulated scenarios.
109108
110109# srand(1234) # to fix the random seed accross runs
111- scenarios = StochDynamicProgramming . simulate_scenarios (xi_laws, 1000 )
112- if run_sddp
110+ if run_sddp && run_sdp && test_simulation
111+ scenarios = StochDynamicProgramming . simulate_scenarios (xi_laws, 1000 )
113112 costsddp, stocks = forward_simulations (spmodel, paramSDDP, pbs, scenarios)
114- end
115- if run_sdp
116- costsdp, states, controls = sdp_forward_simulation (spmodel,paramSDP,scenarios,Vs)
117- end
118-
119- if run_sddp && run_sdp
113+ costsdp, states, controls = sdp_forward_simulation (spmodel,paramSDP,scenarios,Vs)
120114 println (" Simulated relative gain of sddp over sdp: "
121115 * string (round (200 * mean (costsdp- costsddp)/ abs (mean (costsddp+ costsdp)),3 ))* " %" )
122116end
0 commit comments