Skip to content
This repository has been archived by the owner on Apr 19, 2020. It is now read-only.

Commit

Permalink
Merge 4436a16 into 6c88e0e
Browse files Browse the repository at this point in the history
  • Loading branch information
Gord Stephen committed Feb 29, 2020
2 parents 6c88e0e + 4436a16 commit 7d40da0
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/simulations/classic/Classic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ function assess(

# TODO: Deduplicate identical available capacity distributions?
lolp, eul = assess(CapacityDistribution(system, t))
eue = powertoenergy(eul, P, L, T, E)
update!(acc, t, lolp, eue)
update!(acc, t, lolp, eul)

end

Expand Down
13 changes: 7 additions & 6 deletions src/simulations/classic/result_minimal.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mutable struct ClassicMinimalAccumulator{N,L,T,E} <: ResultAccumulator{Minimal}

lole::Float64
eue::Float64
eul::Float64

end

Expand All @@ -13,11 +13,11 @@ accumulator(::Classic, ::Minimal, ::SystemModel{N,L,T,P,E}) where {N,L,T,P,E} =

function update!(
acc::ClassicMinimalAccumulator,
t::Int, lolp::Float64, eue::Float64
t::Int, lolp::Float64, eul::Float64
)

acc.lole += lolp
acc.eue += eue
acc.eul += eul
return

end
Expand All @@ -28,20 +28,21 @@ function finalize(
accsremaining::Int
) where {N,L,T,P,E}

lole = eue = 0.
lole = eul = 0.
p2e = powertoenergy(P, L, T, E)

while accsremaining > 0
acc = take!(results)
lole += acc.lole
eue += acc.eue
eul += acc.eul
accsremaining -= 1
end

close(results)

return MinimalResult(
LOLE{N,L,T}(lole, 0.),
EUE{N,L,T,E}(eue, 0.),
EUE{N,L,T,E}(eul * p2e, 0.),
Classic())

end
22 changes: 12 additions & 10 deletions src/simulations/classic/result_temporal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mutable struct ClassicTemporalAccumulator{N,L,T,E} <: ResultAccumulator{Temporal
lole::Float64
lolps::Vector{Float64}

eue::Float64
eues::Vector{Float64}
eul::Float64
euls::Vector{Float64}

end

Expand All @@ -16,14 +16,14 @@ accumulator(::Classic, ::Temporal, ::SystemModel{N,L,T,P,E}) where {N,L,T,P,E} =

function update!(
acc::ClassicTemporalAccumulator,
t::Int, lolp::Float64, eue::Float64
t::Int, lolp::Float64, eul::Float64
)

acc.lole += lolp
acc.lolps[t] = lolp

acc.eue += eue
acc.eues[t] = eue
acc.eul += eul
acc.euls[t] = eul

return

Expand All @@ -35,9 +35,9 @@ function finalize(
accsremaining::Int
) where {N,L,T,P,E}

lole = eue = 0.
lole = eul = 0.
lolps = zeros(N)
eues = zeros(N)
euls = zeros(N)

while accsremaining > 0

Expand All @@ -46,19 +46,21 @@ function finalize(
lole += acc.lole
lolps .+= acc.lolps

eue += acc.eue
eues .+= acc.eues
eul += acc.eul
euls .+= acc.euls

accsremaining -= 1

end

close(results)

p2e = powertoenergy(P,L,T,E)

return TemporalResult(
system.timestamps,
LOLE{N,L,T}(lole, 0.), LOLP{L,T}.(lolps, 0.),
EUE{N,L,T,E}(eue, 0.), EUE{1,L,T,E}.(eues, 0.),
EUE{N,L,T,E}(p2e * eul, 0.), EUE{1,L,T,E}.(p2e .* euls, 0.),
Classic())

end
19 changes: 10 additions & 9 deletions src/simulations/modern/result_minimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ mutable struct ModernMinimalAccumulator{N,L,T,P,E} <: ResultAccumulator{Minimal}
periodsdropped_total::MeanVariance # Cross-simulation total LOL mean and variance
periodsdropped_total_currentsim::Int # LOL count for current simulation

unservedenergy_total::MeanVariance # Cross-simulation total UE mean and variance
unservedenergy_total_currentsim::Int # UE sum for current simulation
# Note: Unserved load (not energy) does not consider time units
unservedload_total::MeanVariance # Cross-simulation total UL mean and variance
unservedload_total_currentsim::Int # UL sum for current simulation

end

Expand All @@ -27,8 +28,7 @@ function record!(

if isunservedload
acc.periodsdropped_total_currentsim += 1
acc.unservedenergy_total_currentsim +=
powertoenergy(unservedload, P, L, T, E)
acc.unservedload_total_currentsim += unservedload
end

return
Expand All @@ -39,11 +39,11 @@ function reset!(acc::ModernMinimalAccumulator, sampleid::Int)

# Store totals for current simulation
fit!(acc.periodsdropped_total, acc.periodsdropped_total_currentsim)
fit!(acc.unservedenergy_total, acc.unservedenergy_total_currentsim)
fit!(acc.unservedload_total, acc.unservedload_total_currentsim)

# Reset for new simulation
acc.periodsdropped_total_currentsim = 0
acc.unservedenergy_total_currentsim = 0
acc.unservedload_total_currentsim = 0

return

Expand All @@ -57,23 +57,24 @@ function finalize(
) where {N,L,T,P,E}

periodsdropped = Series(Mean(), Variance())
unservedenergy = Series(Mean(), Variance())
unservedload = Series(Mean(), Variance())

while accsremaining > 0

acc = take!(results)

merge!(periodsdropped, acc.periodsdropped_total)
merge!(unservedenergy, acc.unservedenergy_total)
merge!(unservedload, acc.unservedload_total)

accsremaining -= 1

end

close(results)

p2e = powertoenergy(P,L,T,E)
lole = makemetric(LOLE{N,L,T}, periodsdropped)
eue = makemetric(EUE{N,L,T,E}, unservedenergy)
eue = makemetric_scale(EUE{N,L,T,E}, p2e, unservedload)

return MinimalResult(lole, eue, simspec)

Expand Down
28 changes: 14 additions & 14 deletions src/simulations/modern/result_temporal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ mutable struct ModernTemporalAccumulator{N,L,T,P,E} <: ResultAccumulator{Tempora
periodsdropped_total::MeanVariance # Cross-simulation total LOL mean and variance
periodsdropped_total_currentsim::Int # LOL count for current simulation

unservedenergy_period::Vector{MeanVariance} # Cross-simulation period UE mean and variance
unservedenergy_total::MeanVariance # Cross-simulation total UE mean and variance
unservedenergy_total_currentsim::Int # UE sum for current simulation
unservedload_period::Vector{MeanVariance} # Cross-simulation period UE mean and variance
unservedload_total::MeanVariance # Cross-simulation total UE mean and variance
unservedload_total_currentsim::Int # UE sum for current simulation

end

Expand All @@ -26,14 +26,13 @@ function record!(
) where {N,L,T,P,E}

isunservedload, unservedload = droppedload(problem)
unservedenergy = powertoenergy(unservedload, P, L, T, E)

fit!(acc.periodsdropped_period[t], isunservedload)
fit!(acc.unservedenergy_period[t], unservedenergy)
fit!(acc.unservedload_period[t], unservedload)

if isunservedload
acc.periodsdropped_total_currentsim += 1
acc.unservedenergy_total_currentsim += unservedenergy
acc.unservedload_total_currentsim += unservedload
end

return
Expand All @@ -44,11 +43,11 @@ function reset!(acc::ModernTemporalAccumulator, sampleid::Int)

# Store totals for current simulation
fit!(acc.periodsdropped_total, acc.periodsdropped_total_currentsim)
fit!(acc.unservedenergy_total, acc.unservedenergy_total_currentsim)
fit!(acc.unservedload_total, acc.unservedload_total_currentsim)

# Reset for new simulation
acc.periodsdropped_total_currentsim = 0
acc.unservedenergy_total_currentsim = 0
acc.unservedload_total_currentsim = 0

return

Expand All @@ -64,19 +63,19 @@ function finalize(
periodsdropped_total = Series(Mean(), Variance())
periodsdropped_period = [Series(Mean(), Variance()) for _ in 1:N]

unservedenergy_total = Series(Mean(), Variance())
unservedenergy_period = [Series(Mean(), Variance()) for _ in 1:N]
unservedload_total = Series(Mean(), Variance())
unservedload_period = [Series(Mean(), Variance()) for _ in 1:N]

while accsremaining > 0

acc = take!(results)

merge!(periodsdropped_total, acc.periodsdropped_total)
merge!(unservedenergy_total, acc.unservedenergy_total)
merge!(unservedload_total, acc.unservedload_total)

for t in 1:N
merge!(periodsdropped_period[t], acc.periodsdropped_period[t])
merge!(unservedenergy_period[t], acc.unservedenergy_period[t])
merge!(unservedload_period[t], acc.unservedload_period[t])
end

accsremaining -= 1
Expand All @@ -88,8 +87,9 @@ function finalize(
lole = makemetric(LOLE{N,L,T}, periodsdropped_total)
lolps = makemetric.(LOLP{L,T}, periodsdropped_period)

eue = makemetric(EUE{N,L,T,E}, unservedenergy_total)
eues = makemetric.(EUE{1,L,T,E}, unservedenergy_period)
p2e = powertoenergy(P,L,T,E)
eue = makemetric_scale(EUE{N,L,T,E}, p2e, unservedload_total)
eues = makemetric_scale.(EUE{1,L,T,E}, p2e, unservedload_period)

return TemporalResult(system.timestamps, lole, lolps, eue, eues, simspec)

Expand Down
14 changes: 14 additions & 0 deletions test/simulation/classic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
@test LOLE(result_1ab) LOLE{4,1,Hour}(0.355, 0.)
@test EUE(result_1ab) EUE{4,1,Hour,MWh}(1.59, 0.)

# Overall result - singlenode_a_5min
result_1a5 = assess(simspec, Minimal(), singlenode_a_5min)
@test LOLE(result_1a5) LOLE{4,5,Minute}(singlenode_a_lole, 0.)
@test EUE(result_1a5) EUE{4,5,Minute,MWh}(singlenode_a_eue/12, 0.)

# Overall result - singlenode_b
result_1bb = assess(simspec, Minimal(), singlenode_b)
@test LOLE(result_1bb) LOLE{6,1,Hour}(0.96, 0.)
Expand All @@ -32,6 +37,15 @@
@test all(EUE.(result_1ab, singlenode_a.timestamps) .≈
EUE{1,1,Hour,MWh}.([0.29, 0.832, 0.29, 0.178], zeros(4)))

# Hourly result - singlenode_a_5min
result_1a5 = assess(simspec, Temporal(), singlenode_a_5min)
@test LOLE(result_1a5) LOLE{4,5,Minute}(singlenode_a_lole, 0.)
@test all(LOLP.(result_1a5, singlenode_a_5min.timestamps) .≈
LOLP{5,Minute}.(singlenode_a_lolps, zeros(4)))
@test EUE(result_1a5) EUE{4,5,Minute,MWh}(singlenode_a_eue/12, 0.)
@test all(EUE.(result_1a5, singlenode_a_5min.timestamps) .≈
EUE{1,5,Minute,MWh}.(singlenode_a_eues ./ 12, zeros(4)))

# Hourly result - singlenode_b
result_1bb = assess(simspec, Temporal(), singlenode_b)
@test LOLE(result_1bb) LOLE{6,1,Hour}(0.96, 0.)
Expand Down
48 changes: 48 additions & 0 deletions test/simulation/modern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
simspec = Modern(samples=100_000)

timestampcol_a = collect(singlenode_a.timestamps)
timestampcol_a5 = collect(singlenode_a_5min.timestamps)
timestampcol_b = collect(singlenode_b.timestamps)
timestampcol_3 = collect(threenode.timestamps)
regionsrow = reshape(threenode.regions.names, 1, :)
Expand All @@ -23,6 +24,11 @@
@test withinrange(LOLE(result_1a), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a), singlenode_a_eue, nstderr_tol)

# Single-region system A - 5 min version
result_1a5 = assess(simspec, Minimal(), singlenode_a_5min)
@test withinrange(LOLE(result_1a5), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a5), singlenode_a_eue/12, nstderr_tol)

# Single-region system B
result_1b = assess(simspec, Minimal(), singlenode_b)
@test withinrange(LOLE(result_1b), singlenode_b_lole, nstderr_tol)
Expand All @@ -47,6 +53,16 @@
@test all(withinrange.(EUE.(result_1a, timestampcol_a),
singlenode_a_eues, nstderr_tol))

# Single-region system A - 5 min version
result_1a5 = assess(simspec, Temporal(), singlenode_a_5min)
@test withinrange(LOLE(result_1a5), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a5), singlenode_a_eue/12, nstderr_tol)

@test all(withinrange.(LOLP.(result_1a5, timestampcol_a5),
singlenode_a_lolps, nstderr_tol))
@test all(withinrange.(EUE.(result_1a5, timestampcol_a5),
singlenode_a_eues ./ 12, nstderr_tol))

# Single-region system B
result_1b = assess(simspec, Temporal(), singlenode_b)
@test withinrange(LOLE(result_1b), singlenode_b_lole, nstderr_tol)
Expand Down Expand Up @@ -84,6 +100,21 @@
@test all(withinrange.(EUE.(result_1a, "Region", timestampcol_a),
singlenode_a_eues, nstderr_tol))

# Single-region system A - 5 min version
result_1a5 = assess(simspec, SpatioTemporal(), singlenode_a_5min)
@test withinrange(LOLE(result_1a5), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a5), singlenode_a_eue/12, nstderr_tol)
@test withinrange(LOLE(result_1a5, "Region"), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a5, "Region"), singlenode_a_eue/12, nstderr_tol)
@test all(withinrange.(LOLP.(result_1a5, timestampcol_a5),
singlenode_a_lolps, nstderr_tol))
@test all(withinrange.(EUE.(result_1a5, timestampcol_a5),
singlenode_a_eues ./ 12, nstderr_tol))
@test all(withinrange.(LOLP.(result_1a5, "Region", timestampcol_a5),
singlenode_a_lolps, nstderr_tol))
@test all(withinrange.(EUE.(result_1a5, "Region", timestampcol_a5),
singlenode_a_eues ./ 12, nstderr_tol))

# Single-region system B
result_1b = assess(simspec, SpatioTemporal(), singlenode_b)
@test withinrange(LOLE(result_1b), singlenode_b_lole, nstderr_tol)
Expand Down Expand Up @@ -149,6 +180,23 @@
@test length(result_1a.flows) == 0
@test length(result_1a.utilizations) == 0

# Single-region system A
result_1a5 = assess(simspec, Network(), singlenode_a_5min)
@test withinrange(LOLE(result_1a5), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a5), singlenode_a_eue/12, nstderr_tol)
@test withinrange(LOLE(result_1a5, "Region"), singlenode_a_lole, nstderr_tol)
@test withinrange(EUE(result_1a5, "Region"), singlenode_a_eue/12, nstderr_tol)
@test all(withinrange.(LOLP.(result_1a5, timestampcol_a5),
singlenode_a_lolps, nstderr_tol))
@test all(withinrange.(EUE.(result_1a5, timestampcol_a5),
singlenode_a_eues ./ 12, nstderr_tol))
@test all(withinrange.(LOLP.(result_1a5, "Region", timestampcol_a5),
singlenode_a_lolps, nstderr_tol))
@test all(withinrange.(EUE.(result_1a5, "Region", timestampcol_a5),
singlenode_a_eues ./ 12, nstderr_tol))
@test length(result_1a5.flows) == 0
@test length(result_1a5.utilizations) == 0

# Single-region system B
result_1b = assess(simspec, Network(), singlenode_b)
@test withinrange(LOLE(result_1b), singlenode_b_lole, nstderr_tol)
Expand Down

0 comments on commit 7d40da0

Please sign in to comment.