Skip to content

Commit 0e0205d

Browse files
committed
[UPD] Add unit tests for sdp
1 parent 96c42a6 commit 0e0205d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/SDPoptimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function build_sdpmodel_from_spmodel(model::SPModel)
144144
if isa(model,PiecewiseLinearCostSPmodel)||isa(model,LinearDynamicLinearCostSPmodel)
145145
function cons_fun(t,x,u,w)
146146
for i in 1:model.dimStates
147-
if (x[i]<=model.xlim[i][1]) || (x[i]>=model.xlim[i][2])
147+
if (x[i]<model.xlim[i][1]) || (x[i]>model.xlim[i][2])
148148
return false
149149
end
150150
end

test/runtests.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ facts("SDP algorithm") do
432432

433433
@fact test_costs --> true
434434

435+
@fact convertedSDPmodel.constraints(1,x,u,w) --> true
436+
435437
end
436438

437439
context("Solve and simulate using SDP") do
@@ -445,8 +447,6 @@ facts("SDP algorithm") do
445447
aleas_scen, x0,
446448
V_sdp, true )
447449

448-
println(size(stocks_sdp))
449-
println(size(controls_sdp))
450450

451451
costs_sdp2, stocks_sdp2, controls_sdp2 = StochDynamicProgramming.sdp_forward_simulation(modelSDP,
452452
paramsSDP,
@@ -471,6 +471,15 @@ facts("SDP algorithm") do
471471
@fact v1 --> v2
472472
@fact (v1<=v3) --> true
473473

474+
paramsSDP.infoStructure = "DH"
475+
costs_sdp3, stocks_sdp3, controls_sdp3 = StochDynamicProgramming.sdp_forward_simulation(modelSDP,
476+
paramsSDP,
477+
aleas_scen,
478+
V_sdp3, true )
479+
paramsSDP.infoStructure = "HD"
480+
481+
@fact costs_sdp3[1]>=costs_sdp2[1] --> true
482+
474483
a,b = StochDynamicProgramming.generate_grid(modelSDP, paramsSDP)
475484

476485
x_bounds = modelSDP.xlim
@@ -494,11 +503,15 @@ facts("SDP algorithm") do
494503
state_ref = zeros(2)
495504
state_ref[1] = stocks_sdp[2,1,1]
496505
state_ref[2] = stocks_sdp[2,1,2]
506+
w = [4]
497507

498508
@fact_throws get_control(modelSDP,paramsSDP,V_sdp3, 1, x)
509+
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x, w)[1] >= CONTROL_MIN) --> true
510+
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x, w)[1] <= CONTROL_MAX) --> true
511+
499512
paramsSDP.infoStructure = "DH"
500513
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x)[1] >= CONTROL_MIN) --> true
501-
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x)[1] >= CONTROL_MIN) --> true
514+
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x)[1] <= CONTROL_MAX) --> true
502515

503516
@fact size(stocks_sdp) --> (3,1,2)
504517
@fact size(controls_sdp) --> (2,1,2)

0 commit comments

Comments
 (0)