Skip to content

Commit a4d46ec

Browse files
committed
[FIX] Fix bugs in cuts concatenation
Problem occured when final cost was quadratic
1 parent 65d3d36 commit a4d46ec

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/SDDPoptimize.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ function initialize_value_functions(model::SPModel,
318318
V[end] = model.finalCost
319319
build_terminal_cost!(model, solverProblems[end], V[end])
320320
elseif isa(model.finalCost, Function)
321+
# In this case, define a trivial value functions for final cost to avoid problem:
322+
V[end] = PolyhedralFunction(zeros(1), zeros(1, model.dimStates), 1)
321323
model.finalCost(model, solverProblems[end])
322324
end
323325

src/utils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ end
9090
function catcutsarray(polyfunarray::Vector{StochDynamicProgramming.PolyhedralFunction}...)
9191
assert(length(polyfunarray) > 0)
9292
ntimes = length(polyfunarray[1])
93-
return StochDynamicProgramming.PolyhedralFunction[catcuts([V[t] for V in polyfunarray]...) for t in 1:ntimes]
93+
# Concatenate cuts in polyfunarray, and discard final time as we do not add cuts at final time:
94+
concatcuts = StochDynamicProgramming.PolyhedralFunction[catcuts([V[t] for V in polyfunarray]...) for t in 1:ntimes-1]
95+
return vcat(concatcuts, polyfunarray[1][end])
9496
end
9597

9698

0 commit comments

Comments
 (0)