66# ############################################################################
77
88type ActiveCutsContainer
9- ncuts :: Int
9+ numCuts :: Int
1010 territories:: Array{Array} # set of states where cut k is active
1111 nstates:: Int
1212 states:: Array{Float64, 2} # set of states where cuts are tested
@@ -59,15 +59,15 @@ function prune_cuts!(model::SPModel,
5959 param:: SDDPparameters ,
6060 V:: Vector{PolyhedralFunction} ,
6161 trajectories:: Array{Float64, 3} ,
62- territory:: Union{Void, Array{ActiveCutsContainer}} ,
62+ territory:: Union{Array{ Void} , Array{ActiveCutsContainer}} ,
6363 it:: Int64 ,
6464 verbose:: Int64 )
6565 # Basic pruning: remove redundant cuts
6666 remove_redundant_cuts! (V)
6767
6868 # If pruning is performed with territory heuristic, update territory
6969 # at given iteration:
70- if param. pruning[:type ] ∈ [ " level1 " , " exact+ " ]
70+ if isa ( param. pruning[:type ], Union{Type{Territory}, Type{LevelOne}})
7171 for t in 1 : model. stageNumber- 1
7272 states = reshape (trajectories[t, :, :], param. forwardPassNumber, model. dimStates)
7373 find_level1_cuts! (territory[t], V[t], states)
@@ -81,16 +81,7 @@ function prune_cuts!(model::SPModel,
8181 (verbose > 0 ) && print (" Prune cuts ..." )
8282
8383 for i in 1 : length (V)- 1
84- if param. pruning[:type ] == " exact"
85- # apply exact cuts pruning:
86- V[i] = exact_cuts_pruning (model, param, V[i])
87- elseif param. pruning[:type ] == " level1"
88- # apply heuristic to prune cuts:
89- V[i] = level1_cuts_pruning! (territory[i], V[i])
90- elseif param. pruning[:type ] == " exact+"
91- # apply heuristicly accelerated exact pruning:
92- V[i] = exact_cuts_pruning_accelerated! (model, territory[i], V[i], param. SOLVER)
93- end
84+ V[i] = pcuts! (param. pruning[:type ], model, param, V[i], territory[i])
9485 end
9586
9687 # final number of cuts:
@@ -100,6 +91,10 @@ function prune_cuts!(model::SPModel,
10091 end
10192end
10293
94+ pcuts! (:: Type{LevelOne} , model, param, V, territory) = level1_cuts_pruning! (model, param, V, territory)
95+ pcuts! (:: Type{ExactPruning} , model, param, V, territory) = exact_cuts_pruning (model, param, V, territory)
96+ pcuts! (:: Type{Territory} , model, param, V, territory) = exact_cuts_pruning_accelerated! (model, param, V, territory)
97+
10398
10499"""
105100Remove useless cuts in PolyhedralFunction.
@@ -113,7 +108,7 @@ Remove useless cuts in PolyhedralFunction.
113108# Return
114109* `PolyhedralFunction`: pruned polyhedral function
115110"""
116- function exact_cuts_pruning (model:: SPModel , param:: SDDPparameters , V:: PolyhedralFunction )
111+ function exact_cuts_pruning (model:: SPModel , param:: SDDPparameters , V:: PolyhedralFunction , territory )
117112 ncuts = V. numCuts
118113 # Find all active cuts:
119114 if ncuts > 1
@@ -175,7 +170,7 @@ ActiveCutsContainer(ndim) = ActiveCutsContainer(0, [], 0, Array{Float64}(0, ndim
175170# Arguments
176171* `cutscontainer::ActiveCutsContainer`:
177172* `Vt::PolyhedralFunction`:
178- Object storing all cuts
173+ Object storing all cuts
179174* `states`:
180175 Object storing all visited states
181176"""
206201# Arguments
207202* `cutscontainer::ActiveCutsContainer`:
208203* `V::PolyhedralFunction`:
209- Object storing all cuts
210- * `indcut::Int64`:
204+ Object storing all cuts
205+ * `indcut::Int64`:
211206 new cut index
212207"""
213208function update_territory! (cutscontainer:: ActiveCutsContainer , V:: PolyhedralFunction , indcut:: Int64 )
@@ -256,12 +251,13 @@ end
256251# Arguments
257252* `cutscontainer::ActiveCutsContainer`:
258253* `V::PolyhedralFunction`:
259- Object storing all cuts
254+ Object storing all cuts
260255# Return
261256* `V::PolyhedralFunction`
262257 the new PolyhedralFunction
263258"""
264- function level1_cuts_pruning! (cutscontainer:: ActiveCutsContainer , V:: PolyhedralFunction )
259+ function level1_cuts_pruning! (model:: SPModel , param:: SDDPparameters ,
260+ V:: PolyhedralFunction , cutscontainer:: ActiveCutsContainer )
265261 assert (cutscontainer. numCuts == V. numCuts)
266262
267263 nstates = [length (terr) for terr in cutscontainer. territories]
@@ -284,16 +280,18 @@ then test remaining cuts.
284280* `model::SPModel`:
285281* `cutscontainer::ActiveCutsContainer`:
286282* `V::PolyhedralFunction`:
287- Object storing all cuts
288-
283+ Object storing all cuts
284+
289285# Return
290286* `V::PolyhedralFunction`
291287 the new PolyhedralFunction
292288"""
293- function exact_cuts_pruning_accelerated! (model:: SPModel ,
294- cutscontainer:: ActiveCutsContainer ,
295- V:: PolyhedralFunction , solver)
289+ function exact_cuts_pruning_accelerated! (model:: SPModel , param:: SDDPparameters ,
290+ V:: PolyhedralFunction ,
291+ cutscontainer:: ActiveCutsContainer )
292+
296293 assert (cutscontainer. numCuts == V. numCuts)
294+ solver = param. SOLVER
297295
298296 nstates = [length (terr) for terr in cutscontainer. territories]
299297 # Set of inactive cuts:
326324# Arguments
327325* `xf::Vector{Float64}`:
328326* `V::PolyhedralFunction`:
329- Object storing all cuts
330-
327+ Object storing all cuts
328+
331329# Return
332330`bestcost::Float64`
333331 Value of maximal cut at point `xf`
0 commit comments