@@ -504,3 +504,81 @@ function add_cuts_to_model!(model::SPModel, t::Int64, problem::JuMP.Model, V::Po
504504 end
505505end
506506
507+
508+ """
509+ Prune all polyhedral functions in input array.
510+
511+ Parameters:
512+ - model (SPModel)
513+ - params (SDDPparameters)
514+ - V Vector{PolyhedralFunction}
515+ Polyhedral functions where cuts will be removed
516+
517+ """
518+ function prune_cuts! (model:: SPModel , params:: SDDPparameters , V:: Vector{PolyhedralFunction} )
519+ for i in 1 : length (V)
520+ V[i] = prune_cuts (model, params, V[i])
521+ end
522+ end
523+
524+
525+ """
526+ Remove useless cuts in PolyhedralFunction.
527+
528+ Parameters:
529+ - model (SPModel)
530+ - params (SDDPparameters)
531+ - V (PolyhedralFunction)
532+ Polyhedral function where cuts will be removed
533+
534+ Return:
535+ - PolyhedralFunction: pruned polyhedral function
536+
537+ """
538+ function exact_prune_cuts (model:: SPModel , params:: SDDPparameters , V:: PolyhedralFunction )
539+ ncuts = V. numCuts
540+ # Find all active cuts:
541+ if ncuts > 1
542+ active_cuts = Bool[is_cut_active (model, i, V, params. solver) for i= 1 : ncuts]
543+ return PolyhedralFunction (V. betas[active_cuts], V. lambdas[active_cuts, :], sum (active_cuts))
544+ else
545+ return V
546+ end
547+ end
548+
549+
550+ """
551+ Test whether the cut number k is active in polyhedral function Vt.
552+
553+ Parameters:
554+ - model (SPModel)
555+ - k (Int)
556+ Position of cut to test in PolyhedralFunction object
557+ - Vt (PolyhedralFunction)
558+ Object storing all cuts
559+ - solver
560+ Solver to use to solve linear problem
561+
562+ Return:
563+ - Bool: true if the cut is active, false otherwise
564+
565+ """
566+ function is_cut_relevant (model:: SPModel , k:: Int , Vt:: PolyhedralFunction , solver)
567+
568+ m = Model (solver= solver)
569+ @defVar (m, alpha)
570+ @defVar (m, model. xlim[i][1 ] <= x[i= 1 : model. dimStates] <= model. xlim[i][2 ])
571+
572+ for i in 1 : Vt. numCuts
573+ if i!= k
574+ lambda = vec (Vt. lambdas[i, :])
575+ @addConstraint (m, Vt. betas[i] + dot (lambda, x) <= alpha)
576+ end
577+ end
578+
579+ λ_k = vec (Vt. lambdas[k, :])
580+ @setObjective (m, Min, alpha - dot (λ_k, x) - Vt. betas[k])
581+ solve (m)
582+ return getObjectiveValue (m) < 0.
583+ end
584+
0 commit comments