Skip to content

Commit 812dce6

Browse files
committed
Fixed a bug when initial capacity specified
1 parent 0c84eb4 commit 812dce6

4 files changed

Lines changed: 65 additions & 3 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release notes
22

3+
## Version 0.9.1 (2026-04-16)
4+
5+
### Bug fix
6+
7+
* Fixed a bug introduced in pull request #49 in cases where an initial capacity was specified.
8+
39
## Version 0.9.0 (2026-04-08)
410

511
### Breaking changes

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "EnergyModelsInvestments"
22
uuid = "fca3f8eb-b383-437d-8e7b-aac76bb2004f"
33
authors = ["Lars Hellemo <Lars.Hellemo@sintef.no>, Dimitri Pinel <Dimitri.Pinel@sintef.no>"]
4-
version = "0.9.0"
4+
version = "0.9.1"
55

66
[deps]
77
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"

src/model.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ function add_investment_constraints(
7272
)
7373
@constraint(m,
7474
var_current[t_inv]
75-
val_start_cap[t_inv] - val_start_cap[t_inv_prev] +
76-
sum(var_add[sp] for sp life_dict[t_inv])
75+
val_start_cap[t_inv] + sum(var_add[sp] for sp life_dict[t_inv])
7776
)
7877
end
7978
end

test/test_lifetime.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,60 @@ end
547547
@test all(value.(m[:cap_capex])[n, t_inv] capex[t_inv] for t_inv 𝒯ᴵⁿᵛ)
548548
end
549549
end
550+
551+
@testset "RollingLife - Longer lifetime, StartInvData" begin
552+
# Creation and solving of the model
553+
inv_data = StartInvData(
554+
FixedProfile(1000),
555+
FixedProfile(40),
556+
StrategicProfile([15, 10, 5, 0]),
557+
ContinuousInvestment(FixedProfile(0), FixedProfile(15)),
558+
RollingLife(FixedProfile(20))
559+
)
560+
demand = StrategicProfile([5,10,15,15])
561+
m, para = simple_model(;inv_data, demand)
562+
563+
# Extraction of required data
564+
n = para[:node]
565+
𝒯 = para[:T]
566+
𝒯ᴵⁿᵛ = strat_periods(𝒯)
567+
inv_data = para[:inv_data]
568+
disc_rate = 1/(1+para[:disc_rate])^10
569+
invest = StrategicProfile([0, 0, 10, 5])
570+
571+
# Retirements are at the end of the strategic period following the investment period
572+
# This is only the last strategic period
573+
removal = StrategicProfile([0, 0, 0, 10])
574+
575+
# Explicit calculation of CAPEX
576+
# 1. Investments do not require reinvestments.
577+
# 2. The investment in strategic period 4 has a final value, equal to discounted 10/20 %
578+
# of the intial value
579+
capex = StrategicProfile([0, 0, 10, 5*(1-0.5*disc_rate)]) * 1e3
580+
581+
# Explicit calculation of the current capacity
582+
cap_initial = StrategicProfile([15, 10, 5, 0])
583+
cap_current = cap_initial + invest + removal
584+
585+
# Tests of the lifetime calculation
586+
# - set_capacity_cost(m, element, inv_data, prefix, 𝒯ᴵⁿᵛ, disc_rate, ::RollingLife)
587+
@testset "Lifetime calculations" begin
588+
# Test that `:cap_current` follows the initial capacity
589+
@test all(value.(m[:cap_current][n, t_inv]) == cap_current[t_inv] for t_inv 𝒯ᴵⁿᵛ)
590+
591+
# Test that `:cap_rem` follows the lifetime
592+
@test all(value.(m[:cap_rem][n, t_inv]) == removal[t_inv] for t_inv 𝒯ᴵⁿᵛ)
593+
594+
# Test that `:cap_add` follows the lifetime
595+
@test all(value.(m[:cap_add][n, t_inv]) == invest[t_inv] for t_inv 𝒯ᴵⁿᵛ)
596+
597+
# Test that the CAPEX is correctly calculated
598+
# - set_capex_discounter(years, lifetime, disc_rate)
599+
@test all(
600+
value.(m[:cap_capex])[n, t_inv]
601+
value.(m[:cap_add])[n, t_inv] * EMI.capex(inv_data, t_inv) *
602+
StrategicProfile([1, 1, 1, 1*(1-0.5*disc_rate)])[t_inv]
603+
for t_inv 𝒯ᴵⁿᵛ)
604+
@test all(value.(m[:cap_capex])[n, t_inv] capex[t_inv] for t_inv 𝒯ᴵⁿᵛ)
605+
end
606+
end

0 commit comments

Comments
 (0)