@@ -274,7 +274,7 @@ facts("SDDP algorithm: 2D case") do
274274end
275275
276276
277- facts (" Indexation and interpolation for SDP" ) do
277+ facts (" Indexation for SDP" ) do
278278
279279 bounds = [(0.1 ,10.0 ), (1.2 , 4.0 ), (0.5 , 2.0 )]
280280 steps = [0.1 , 0.05 , 0.01 ]
@@ -386,12 +386,10 @@ facts("SDP algorithm") do
386386 aleas_scen = zeros (2 , 1 , 1 )
387387 aleas_scen[:, 1 , 1 ] = alea_year;
388388
389- modelSDP = StochDynProgModel (TF, N_CONTROLS,
390- N_STATES, N_NOISES,
391- x_bounds, u_bounds,
392- x0, cost_t,
393- finalCostFunction, dynamic,
394- constraints, aleas);
389+ modelSDP = StochDynProgModel (TF, x_bounds, u_bounds,
390+ x0, cost_t,
391+ finalCostFunction, dynamic,
392+ constraints, aleas);
395393
396394 stateSteps = [1 ,1 ];
397395 controlSteps = [1 ,1 ];
@@ -400,8 +398,7 @@ facts("SDP algorithm") do
400398 paramsSDP = StochDynamicProgramming. SDPparameters (modelSDP, stateSteps,
401399 controlSteps,
402400 infoStruct,
403- " Exact" ,
404- monteCarloSize);
401+ " Exact" );
405402
406403 context (" Compare StochDynProgModel constructors" ) do
407404
@@ -416,6 +413,8 @@ facts("SDP algorithm") do
416413 cost_t,
417414 dynamic, aleas)
418415
416+ convertedSDPmodel = StochDynamicProgramming. SPmodel_to_SDPmodel (modelSDPPiecewise, paramsSDP)
417+
419418 set_state_bounds (modelSDPLinear, x_bounds)
420419
421420 test_costs = true
@@ -426,6 +425,7 @@ facts("SDP algorithm") do
426425 for t in 1 : TF- 1
427426 test_costs &= (modelSDPLinear. costFunctions (t,x,u,w)== modelSDP. costFunctions (t,x,u,w))
428427 test_costs &= (modelSDPPiecewise. costFunctions[1 ](t,x,u,w)== modelSDP. costFunctions (t,x,u,w))
428+ test_costs &= (modelSDPPiecewise. costFunctions[1 ](t,x,u,w)== convertedSDPmodel. costFunctions (t,x,u,w))
429429 end
430430
431431 @fact test_costs --> true
@@ -434,15 +434,47 @@ facts("SDP algorithm") do
434434
435435 context (" Solve and simulate using SDP" ) do
436436
437+ x = x0
437438 V_sdp = sdp_optimize (modelSDP, paramsSDP, false );
439+ V_sdp2 = StochDynamicProgramming. sdp_solve_HD (modelSDP, paramsSDP, false );
440+ V_sdp3 = StochDynamicProgramming. sdp_solve_DH (modelSDP, paramsSDP, false );
441+
442+ Vitp = StochDynamicProgramming. value_function_interpolation ( modelSDP, V_sdp, 1 )
443+ Vitp2 = StochDynamicProgramming. value_function_interpolation ( modelSDP, V_sdp2, 1 )
444+ Vitp3 = StochDynamicProgramming. value_function_interpolation ( modelSDP, V_sdp3, 1 )
445+
446+ v1 = Vitp[(1.1 ,1.1 ). .. ]
447+ v2 = Vitp2[(1.1 ,1.1 ). .. ]
448+ v3 = Vitp3[(1.1 ,1.1 ). .. ]
449+
450+ @fact v1 --> v2
451+ @fact (v1<= v3) --> true
452+
453+ a,b = StochDynamicProgramming. generate_grid (modelSDP, paramsSDP)
454+
455+ x_bounds = modelSDP. xlim
456+ x_steps = paramsSDP. stateSteps
457+
458+ u_bounds = modelSDP. ulim
459+ u_steps = paramsSDP. controlSteps
460+
461+ @fact length (collect (a)) --> (x_bounds[1 ][2 ]- x_bounds[1 ][1 ]+ x_steps[1 ])* (x_bounds[2 ][2 ]- x_bounds[2 ][1 ]+ x_steps[2 ])/ (x_steps[1 ]* x_steps[2 ])
462+ @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 ])
463+
464+ ind = StochDynamicProgramming. index_from_variable (x, x_bounds, x_steps)
465+ @fact get_value (modelSDP, paramsSDP, V_sdp2) --> V_sdp2[ind... ,1 ]
438466
439467 @fact size (V_sdp) --> (paramsSDP. stateVariablesSizes... , TF)
468+ @fact V_sdp2[1 ,1 ,1 ] <= V_sdp3[1 ,1 ,1 ] --> true
440469
441470 costs_sdp, stocks_sdp, controls_sdp = sdp_forward_simulation (modelSDP,
442471 paramsSDP,
443472 aleas_scen, x0,
444473 V_sdp, true )
445474
475+ @fact (get_control (modelSDP,paramsSDP,V_sdp3, 1 , x)[1 ] >= CONTROL_MIN) --> true
476+ @fact (get_control (modelSDP,paramsSDP,V_sdp3, 1 , x)[1 ] >= CONTROL_MIN) --> true
477+
446478 @fact size (stocks_sdp) --> (3 ,1 ,2 )
447479 @fact size (controls_sdp) --> (2 ,1 ,2 )
448480
0 commit comments