Skip to content

Commit bbc6f40

Browse files
committed
[UPD] Rescope PR
- add error handling in get_control - fix some docstrings - improve naming
1 parent 0b2e1f6 commit bbc6f40

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

src/SDDPoptimize.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ Parameters:
161161
162162
163163
Return:
164-
Float64 (estimation of the upper bound)
164+
- upb (Float64)
165+
estimation of upper bound
166+
167+
- costs (Vector{Float64})
168+
Costs along different trajectories
165169
166170
"""
167171
function estimate_upper_bound(model::SPModel, param::SDDPparameters, V::Vector{PolyhedralFunction}, problem::Vector{JuMP.Model}, n_simulation=1000::Int)
@@ -179,7 +183,7 @@ end
179183

180184

181185

182-
"""Build a collection of cuts initialize at 0"""
186+
"""Build a collection of cuts initialized at 0"""
183187
function get_null_value_functions_array(model::SPModel)
184188

185189
V = Vector{PolyhedralFunction}(model.stageNumber)

src/SDPoptimize.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Returns :
189189
"""
190190
function solve_DP(model::SPModel,
191191
param::SDPparameters,
192-
display=true::Int64)
192+
display=0::Int64)
193193

194194
SDPmodel = build_sdpmodel_from_spmodel(model::SPModel)
195195

@@ -500,7 +500,7 @@ Returns :
500500
- costs (Vector{Float64})
501501
the cost of the optimal control over the scenario provided
502502
503-
- stocks (Array{Float64})
503+
- states (Array{Float64})
504504
the state of the controlled system at each time step
505505
506506
- controls (Array{Float64})
@@ -559,6 +559,9 @@ Returns :
559559
"""
560560
function get_control(model::SPModel,param::SDPparameters,V::Array{Float64}, t::Int64, x::Array)
561561

562+
if(param.infoStructure != "DH")
563+
error("Infostructure must be decision-hazard.")
564+
end
562565
SDPmodel = build_sdpmodel_from_spmodel(model)
563566

564567
product_controls = product([SDPmodel.ulim[i][1]:param.controlSteps[i]:SDPmodel.ulim[i][2] for i in 1:SDPmodel.dimControls]...)
@@ -636,11 +639,15 @@ Parameters:
636639
the alea realization
637640
638641
Returns :
639-
- V(x0) (Float64)
642+
- optimal control (tuple(Float64))
640643
641644
"""
642645
function get_control(model::SPModel,param::SDPparameters,V::Array{Float64}, t::Int64, x::Array, w::Array)
643646

647+
if(param.infoStructure != "HD")
648+
error("Infostructure must be hazard-decision.")
649+
end
650+
644651
SDPmodel = build_sdpmodel_from_spmodel(model)
645652

646653
product_controls = product([SDPmodel.ulim[i][1]:param.controlSteps[i]:SDPmodel.ulim[i][2] for i in 1:SDPmodel.dimControls]...)

src/forwardBackwardIterations.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ function forward_simulations(model::SPModel,
6262
returnCosts=true::Bool,
6363
init=false::Bool,
6464
display=false::Bool)
65-
65+
6666
T = model.stageNumber
67-
nb_forward = size(xi)[2]
68-
67+
nb_forward = size(xi)[2]
68+
6969
if ndims(xi)!=3
7070
if ndims(xi)==2
7171
warn("noise scenario are not given in the right shape. Assumed to be real valued noise.")
72-
xi = reshape(xi,(T,nb_forward,1))
72+
xi = reshape(xi,(T,nb_forward,1))
7373
else
7474
error("wrong dimension of noise scenarios")
7575
end
@@ -223,7 +223,7 @@ Add to polyhedral function a cut with shape Vt >= beta + <lambda,.>
223223
V::Vector{PolyhedralFunction},
224224
solverProblems::Vector{JuMP.Model},
225225
stockTrajectories::Array{Float64, 3},
226-
law,
226+
law,
227227
init=false::Bool)
228228

229229
T = model.stageNumber
@@ -258,7 +258,7 @@ Add to polyhedral function a cut with shape Vt >= beta + <lambda,.>
258258
costs[w] = nextstep.cost
259259
end
260260

261-
# Compute esperancy of subgradient:
261+
# Compute expectation of subgradient:
262262
subgradient = vec(sum(law[t].proba' .* subgradient_array, 2))
263263
# ... and esperancy of cost:
264264
costs_npass[k] = dot(law[t].proba, costs)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ facts("SDP algorithm") do
485485
state_ref[1] = stocks_sdp[2,1,1]
486486
state_ref[2] = stocks_sdp[2,1,2]
487487

488+
@fact_throws get_control(modelSDP,paramsSDP,V_sdp3, 1, x)
489+
paramsSDP.infoStructure = "DH"
488490
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x)[1] >= CONTROL_MIN) --> true
489491
@fact (get_control(modelSDP,paramsSDP,V_sdp3, 1, x)[1] >= CONTROL_MIN) --> true
490492

0 commit comments

Comments
 (0)