Skip to content

Commit 73a5d90

Browse files
authored
Merge pull request #118 from JuliaOpt/cuts-removal
Implement territory algorithm
2 parents 75bad6e + 221d51d commit 73a5d90

File tree

5 files changed

+402
-51
lines changed

5 files changed

+402
-51
lines changed

examples/damsvalley.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ end
8484
const FORWARD_PASS = 10.
8585
const EPSILON = .05
8686
# Maximum number of iterations
87-
const MAX_ITER = 50
87+
const MAX_ITER = 10
8888
##################################################
8989

9090
"""Build probability distribution at each timestep.
@@ -127,5 +127,5 @@ end
127127

128128
# Solve the problem:
129129
model, params = init_problem()
130-
V, pbs = solve_SDDP(model, params, 1)
130+
V, pbs = @time solve_SDDP(model, params, 1)
131131

src/SDDPoptimize.jl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ function run_SDDP!(model::SPModel,
109109
#Initialization of the counter
110110
stats = SDDPStat()
111111

112+
# Initialize cuts container for cuts pruning:
113+
if isa(param.pruning[:type], Union{Type{Territory}, Type{LevelOne}})
114+
activecuts = [ActiveCutsContainer(model.dimStates) for i in 1:model.stageNumber-1]
115+
else
116+
activecuts = [nothing for i in 1:model.stageNumber-1]
117+
end
118+
112119
(verbose > 0) && println("Initialize cuts")
113120

114121
# If computation of upper-bound is needed, a set of scenarios is built
@@ -134,26 +141,30 @@ function run_SDDP!(model::SPModel,
134141
# Backward pass : update polyhedral approximation of Bellman functions
135142
callsolver_backward = backward_pass!(model, param, V, problems, stockTrajectories, model.noises)
136143

144+
####################
145+
# Update stats
146+
lwb = get_bellman_value(model, param, 1, V[1], model.initialState)
147+
updateSDDPStat!(stats, callsolver_forward+callsolver_backward, lwb, upb, toq())
148+
print_current_stats(stats,verbose)
149+
137150
####################
138151
# cut pruning
139-
prune_cuts!(model,param,V,stats.niterations,verbose)
152+
if param.pruning[:pruning]
153+
prune_cuts!(model, param, V, stockTrajectories, activecuts, stats.niterations, verbose)
154+
if (stats.niterations%param.pruning[:period]==0)
155+
problems = hotstart_SDDP(model, param, V)
156+
end
157+
end
140158

141159
####################
142160
# In iteration upper bound estimation
143161
upb = in_iteration_upb_estimation(model, param, stats.niterations, verbose,
144162
upperbound_scenarios, upb, problems)
145163

146-
####################
147-
# Update stats
148-
lwb = get_bellman_value(model, param, 1, V[1], model.initialState)
149-
updateSDDPStat!(stats, callsolver_forward+callsolver_backward, lwb, upb, toq())
150-
151-
print_current_stats(stats,verbose)
152164

153165
####################
154166
# Stopping test
155167
stopping_test = test_stopping_criterion(param,stats)
156-
stats.niterations += 1
157168
end
158169

159170
##########
@@ -465,3 +476,4 @@ function add_cuts_to_model!(model::SPModel, t::Int64, problem::JuMP.Model, V::Po
465476
@constraint(problem, V.betas[i] + dot(lambda, xf) <= alpha)
466477
end
467478
end
479+

0 commit comments

Comments
 (0)