Skip to content

Commit

Permalink
Fix bound calculation with multiple Markov states in first stage (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 21, 2018
1 parent 0d15d4a commit 2d8fdac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/SDDP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,27 @@ function backwardpass!(m::SDDPModel, settings::Settings)
end
end
end
return compute_initial_bound(m)
end

"""
compute_initial_bound(m)
Calculate the expected cost of the first stage.
"""
function compute_initial_bound(m)
# TODO(odow): should this return the risk-adjusted expectation? This implies
# that we need a risk measure at the root node.
reset!(m.storage)
for sp in subproblems(m, 1)
solvesubproblem!(BackwardPass, m, sp)
end
return dot(m.storage.objective, m.storage.probability)
transition_matrix = getstage(m, 1).transitionprobabilities
for (i, markov_state) in enumerate(m.storage.markov)
m.storage.probability[i] *= transition_matrix[1, markov_state]
end
@assert sum(m.storage.probability) 1.0
dot(m.storage.objective, m.storage.probability)
end

function iteration!(m::SDDPModel, settings::Settings)
Expand Down
11 changes: 11 additions & 0 deletions test/sddpmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,14 @@ using Clp
end
end
end

@testset "Markov Issue #120" begin
m = SDDPModel(stages=2, sense=:Min, objective_bound=0.0, solver=ClpSolver(),
markov_transition = [ [0.5 0.5], [0.5 0.5; 0.5 0.5] ]) do sp, t, i
@state(sp, x>=0, x0==2)
@rhsnoise(sp, w=[-1, 1], x == x0 + w)
@stageobjective(sp, (t + i) * x)
end
solve(m, iteration_limit=20, print_level=0)
@test getbound(m) 12.0
end

0 comments on commit 2d8fdac

Please sign in to comment.