Skip to content

Commit d5e04a9

Browse files
committed
[FIX] Fix some tests and examples
1 parent 48cdb3d commit d5e04a9

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

examples/risk-example.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using StochDynamicProgramming, Clp
1515
println("library loaded")
1616

1717
run_expectation = true # false if you don't want to test expectation
18-
run_CVaR = true # false if you don't want to test CVaR
18+
run_AVaR = true # false if you don't want to test AVaR
1919
run_WorstCase = true # false if you don't want to test WorstCase
2020

2121
######## Optimization parameters ########
@@ -87,13 +87,13 @@ if run_expectation
8787
toc(); println();
8888
end
8989

90-
######### Solving the problem via SDDP with CVaR
91-
if run_CVaR
90+
######### Solving the problem via SDDP with AVaR
91+
if run_AVaR
9292
tic()
93-
spmodel = LinearSPModel(N_STAGES,u_bounds,[S0],cost_t,dynamic,xi_laws, CVaR(0.5))
93+
spmodel = LinearSPModel(N_STAGES,u_bounds,[S0],cost_t,dynamic,xi_laws, riskMeasure = AVaR(0.5))
9494
set_state_bounds(spmodel, s_bounds) # adding the bounds to the model
95-
println("CVaR's model set up")
96-
println("Starting resolution with CVaR")
95+
println("AVaR's model set up")
96+
println("Starting resolution with AVaR")
9797
# 10 forward pass, stop at MAX_ITER
9898
paramSDDP = SDDPparameters(SOLVER,
9999
passnumber=10,

src/objects.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ type LinearSPModel <: SPModel
116116
x0, # initial state
117117
cost, # cost function
118118
dynamic, # dynamic
119-
aleas, # modelling of noises
119+
aleas; # modelling of noises
120120
Vfinal=nothing, # final cost
121121
eqconstr=nothing, # equality constraints
122122
ineqconstr=nothing, # inequality constraints
123123
info=:HD, # information structure
124124
control_cat=nothing, # category of controls
125-
riskMeasure = Expectation();
125+
riskMeasure = Expectation()
126126
)
127127

128128
# infer the problem's dimension

src/risk.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Return a dirac on the worst cost as a probability distribution.
8080
"""
8181
function argsup_proba_risk(prob,riskMeasure::WorstCase,costs)
8282
proba = zeros(length(prob))
83-
proba[indmax(prob)] = 1
83+
proba[indmax(costs)] = 1
8484
return proba
8585
end
8686

test/changeprob.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end
3232
@testset "Equality Expectation AVaR(1)" begin
3333
n = 100
3434
prob = 1/n*ones(n)
35-
@test sum(abs.(argsup_proba_risk(prob,AVaR(0),1:n)-argsup_proba_risk(prob,Expectation(),1:n)) .<= EPSILON*ones(n)) == n
35+
@test sum(abs.(argsup_proba_risk(prob,AVaR(1),1:n)-argsup_proba_risk(prob,Expectation(),1:n)) .<= EPSILON*ones(n)) == n
3636
end
3737

3838
@testset "Equality Expectation ConvexCombi(beta,1)" begin
@@ -54,7 +54,7 @@ end
5454
betamin = rand()/2+0.5
5555
n = 100
5656
prob = 1/n*ones(n)
57-
@test argsup_proba_risk(prob, AVaR(betamax), 1:n)'*(n:-1:1) - argsup_proba_risk(prob, AVaR(betamin), 1:n)'*(n:-1:1) >= 0
57+
@test argsup_proba_risk(prob, AVaR(betamin), 1:n)'*(n:-1:1) - argsup_proba_risk(prob, AVaR(betamax), 1:n)'*(n:-1:1) >= 0
5858
end
5959
end
6060

@@ -77,7 +77,7 @@ end
7777

7878
status = solve(m)
7979

80-
probaAVaR = argsup_proba_risk(prob, AVaR(beta), sortperm(X, rev = true))
80+
probaAVaR = argsup_proba_risk(prob, AVaR(beta), X)
8181

8282
@test abs(probaAVaR'*X - getobjectivevalue(m)) <= EPSILON
8383
end

test/sddp.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ using Base.Test
189189
u_bounds, x0,
190190
cost,
191191
dynamic, laws,
192-
Expectation(),
193192
control_cat=controlCat)
194193
set_state_bounds(model2, x_bounds)
195194
@test_throws ErrorException solve_SDDP(model2, param, 0)

0 commit comments

Comments
 (0)