Skip to content

Commit

Permalink
Removed unncessary last(collect()) (#31)
Browse files Browse the repository at this point in the history
- last for different TimeStructures was introduced in a later version of TimeStruct
- last(collect()) hence no longer required.
  • Loading branch information
JulStraus authored May 24, 2024
1 parent 045aec7 commit 3704c80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function previous_level(
)
# Return the previous storage level based on cyclic constraints within the representative
# period
return @expression(m, m[:stor_level][n, last(collect(current_per(cyclic_pers)))])
return @expression(m, m[:stor_level][n, last(current_per(cyclic_pers))])
end
"""
previous_level_sp(
Expand All @@ -252,7 +252,7 @@ function previous_level_sp(
modeltype::EnergyModel
)
# Return the previous storage level based on cyclic constraints
last_op = last(collect(current_per(cyclic_pers)))
last_op = last(current_per(cyclic_pers))
return @expression(m, m[:stor_level][n, last_op])
end
"""
Expand Down Expand Up @@ -308,7 +308,7 @@ function previous_level_sp(
)
# Extract the last operational period in the representative period from the type
# `CyclicPeriods`
last_op = last(collect(current_per(cyclic_pers)))
last_op = last(current_per(cyclic_pers))

# Return the previous storage level based on cyclic constraints within the representative
# period
Expand Down
10 changes: 5 additions & 5 deletions test/test_nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ end

# Test that the level balance is correct in the first period (2 times)
@test sum(sum(value.(m[:stor_level][stor, t])
value.(m[:stor_level][stor, last(collect(t_inv))]) +
value.(m[:stor_level][stor, last(t_inv)]) +
value.(m[:stor_level_Δ_op][stor, t]) * duration(t)
for (t_prev, t) withprev(t_inv) if isnothing(t_prev))
for t_inv 𝒯ᴵⁿᵛ, atol=TEST_ATOL)
Expand Down Expand Up @@ -1072,7 +1072,7 @@ end

# Test that the level balance is correct in the first period (2 times)
@test sum(sum(value.(m[:stor_level][stor, t])
value.(m[:stor_level][stor, last(collect(t_inv))]) +
value.(m[:stor_level][stor, last(t_inv)]) +
value.(m[:stor_level_Δ_op][stor, t]) * duration(t)
for (t_prev, t) withprev(t_inv) if isnothing(t_prev))
for t_inv 𝒯ᴵⁿᵛ, atol=TEST_ATOL)
Expand Down Expand Up @@ -1133,7 +1133,7 @@ end
if isnothing(t_prev)
# Test for the linking between the first and the last operational period
@test value.(m[:stor_level][stor, t])
value.(m[:stor_level][stor, last(collect(t_rp))]) +
value.(m[:stor_level][stor, last(t_rp)]) +
value.(m[:stor_level_Δ_op][stor, t]) * duration(t) atol=TEST_ATOL
end
end
Expand Down Expand Up @@ -1212,7 +1212,7 @@ end
if isnothing(t_prev)
# Test for the linking between the first and the last operational period
@test value.(m[:stor_level][stor, t])
value.(m[:stor_level][stor, last(collect(t_rp))]) +
value.(m[:stor_level][stor, last(t_rp)]) +
value.(m[:stor_level_Δ_op][stor, t]) * duration(t) atol=TEST_ATOL
end
end
Expand Down Expand Up @@ -1295,7 +1295,7 @@ end
if isnothing(t_prev)
# Test for the linking between the first and the last operational period
@test value.(m[:stor_level][stor, t])
value.(m[:stor_level][stor, last(collect(t_rp))]) +
value.(m[:stor_level][stor, last(t_rp)]) +
value.(m[:stor_level_Δ_op][stor, t]) * duration(t) atol=TEST_ATOL
end
end
Expand Down

0 comments on commit 3704c80

Please sign in to comment.