Skip to content

Commit

Permalink
Improve error for lagged state variables in MSPFormat (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 18, 2024
1 parent 87a387c commit 631a263
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/MSPFormat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,14 @@ function _build_lhs(stage::Integer, sp::JuMP.Model, terms::Vector{Any})
@assert x isa SDDP.State
if term["stage"] == stage
x = x.out
else
@assert term["stage"] == stage - 1
elseif term["stage"] == stage - 1
x = x.in
else
error(
"SDDP.jl does not support this MSPFormat file because it " *
"contains state variables from stages other than `t` or " *
"`t-1`. Got `t-$(stage - term["stage"])`",
)
end
end
coef = _get_constant(term["coefficient"])
Expand Down
16 changes: 16 additions & 0 deletions test/MSPFormat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ function test_electric()
return
end

function test_stage_lead_time()
sp = Model()
sp[:x] = SDDP.State(@variable(sp), @variable(sp))
terms = Any[
Dict("name" => "x", "stage" => 2, "coefficient" => [1.0]),
Dict("name" => "x", "stage" => 0, "coefficient" => [-1.0]),
]
@test_throws(
ErrorException(
"SDDP.jl does not support this MSPFormat file because it contains state variables from stages other than `t` or `t-1`. Got `t-2`",
),
MSPFormat._build_lhs(2, sp, terms),
)
return
end

end # module

TestMSPFormat.runtests()

0 comments on commit 631a263

Please sign in to comment.