Skip to content

Commit bdbd9ff

Browse files
committed
Merge pull request #41 from leclere/cleaning-examples
[FIX] a few hotfixes
2 parents 71d33c5 + 6edf5ab commit bdbd9ff

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

examples/dam.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function cost_t(t, x, u, w)
5959
end
6060

6161

62-
"""Solve the problem with a solver, supposing the aleas are known
62+
"""Solve the problem assuming the aleas are known
6363
in advance."""
6464
function solve_determinist_problem()
6565
println(alea_year)

examples/damsvalley.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function cost_t(t, x, u, w)
5959
end
6060

6161

62-
"""Solve the problem with a solver, supposing the aleas are known
62+
"""Solve the problem assuming the aleas are known
6363
in advance."""
6464
function solve_determinist_problem()
6565
m = Model(solver=SOLVER)

examples/onedam.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
srand(2713)
2-
push!(LOAD_PATH, "../src")
3-
# include("../src/objects.jl")
4-
# include("../src/SDPoptimize.jl")
1+
# Copyright 2015, Vincent Leclere, Francois Pacaud and Henri Gerard
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
#############################################################################
6+
# Compare different ways of solving a stock problem
7+
#############################################################################
58

9+
push!(LOAD_PATH, "../src")
610
using StochDynamicProgramming, JuMP, Clp, Distributions
711

12+
######## Optimization parameters ########
13+
# choose the LP solver used.
814
const SOLVER = ClpSolver()
915
# const SOLVER = CplexSolver(CPX_PARAM_SIMDISPLAY=0)
16+
# const SOLVER = GurobiSolver()
1017

18+
# Stopping test parameters
1119
const EPSILON = .05
1220
const MAX_ITER = 20
1321

22+
23+
######## Stochastic problem parameters ########
24+
1425
# Define number of stages and scenarios:
1526
const N_STAGES = 3
1627
const N_SCENARIOS = 10
@@ -19,7 +30,7 @@ const N_SCENARIOS = 10
1930
const TF = N_STAGES-1
2031

2132
# Randomnly generate a cost scenario fixed for the whole problem:
22-
const COST = [-12, -200, -67]
33+
const COST = -rand(N_STAGES)
2334

2435
# Define bounds for states and controls:
2536
const VOLUME_MAX = 50
@@ -81,7 +92,7 @@ function constraints(t, x1, u, w)
8192
end
8293

8394

84-
"""Solve the problem with a solver, supposing the aleas are known
95+
"""Solve the optimization problem assuming the aleas are known
8596
in advance."""
8697
function solve_determinist_problem()
8798
m = Model(solver=SOLVER)

src/noises.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Returns :
169169
- scenarios Array(Float64,n,T)
170170
an Array of scenarios, scenarios[i,:] being the ith noise scenario
171171
"""
172-
function generate_scenarios(law::Vector{NoiseLaw}, n::Int64)
172+
function generate_scenarios(laws::Vector{NoiseLaw}, n::Int64)
173173
if n <= 0
174174
error("negative number of simulations")
175175
end
@@ -178,7 +178,7 @@ function generate_scenarios(law::Vector{NoiseLaw}, n::Int64)
178178
for i = 1:n#TODO can be parallelized
179179
scenario = []
180180
for t=1:Tf
181-
new_val = law[t].support[:, rand(Categorical(law[t].proba))]
181+
new_val = laws[t].support[:, rand(Categorical(law[t].proba))]
182182
push!(scenario, new_val)
183183
end
184184
scenarios[i,:]=scenario

src/objects.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,16 @@ type StochDynProgModel <: SPModel
142142
end
143143

144144
type SDDPparameters
145-
# Solver to solve
145+
# Solver used to solve LP
146146
solver
147-
# number of simulated scenario in the forward pass
147+
# number of scenarios in the forward pass
148148
forwardPassNumber::Int64
149149
# Admissible gap between the estimation of the upper-bound
150150
sensibility::Float64
151151
# Maximum iterations of the SDDP algorithms:
152152
maxItNumber::Int64
153153

154-
function SDDPparameters(solver, passnumber, sensibility=0.01, max_iterations=20)
154+
function SDDPparameters(solver, passnumber=10, sensibility=0., max_iterations=20)
155155
return new(solver, passnumber, sensibility, max_iterations)
156156
end
157157
end

0 commit comments

Comments
 (0)