Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TimeStruct"
uuid = "f9ed5ce0-9f41-4eaa-96da-f38ab8df101c"
authors = ["Lars Hellemo <Lars.Hellemo@sintef.no>, Truls.Flatberg <Truls.Flatberg@sintef.no>"]
version = "0.9.7"
version = "0.9.8"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
8 changes: 8 additions & 0 deletions src/profiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,11 @@ end
function /(a::RepresentativeProfile{T}, b::Number) where {T}
return RepresentativeProfile(a.vals ./ b)
end

-(a::FixedProfile{T}) where {T} = FixedProfile(-a.val)
-(a::OperationalProfile{T}) where {T} = OperationalProfile(-a.vals)
-(a::StrategicProfile{T}) where {T} = StrategicProfile(-a.vals)
-(a::ScenarioProfile{T}) where {T} = ScenarioProfile(-a.vals)
-(a::RepresentativeProfile{T}) where {T} = RepresentativeProfile(-a.vals)

+(a::TimeProfile{T}) where {T} = a
52 changes: 52 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,58 @@ end
@test typeof(v) == Vector{OperationalProfile{Float64}}
end

@testitem "Profile and unary operators" begin
# FixedProfile
profile = +FixedProfile(10)
@test profile.val == 10

profile = -FixedProfile(10)
@test profile.val == -10

# OperationalProfile
profile = +OperationalProfile([1, 2, 3])
@test profile.vals == [1, 2, 3]

profile = -OperationalProfile([1, 2, 3])
@test profile.vals == [-1, -2, -3]

# StrategicProfile
simple = SimpleTimes(10, 1)
ts = TwoLevel(3, 5, simple)

profile = +StrategicProfile([1, 2, 3])
vals = collect(profile[sp] for sp in strat_periods(ts))
@test vals == [1, 2, 3]

profile = -StrategicProfile([1, 2, 3])
vals = collect(profile[sp] for sp in strat_periods(ts))
@test vals == [-1, -2, -3]

# ScenarioProfile
oscen = OperationalScenarios([SimpleTimes(5, 1), SimpleTimes(5, 1)])
repr = RepresentativePeriods(2, 5, [0.6, 0.4], [oscen, oscen])
ts = TwoLevel(3, 5, repr)
profile = +ScenarioProfile([1, 2, 3])
vals = collect(profile[sc] for sc in opscenarios(ts))
@test vals == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]

profile = -ScenarioProfile([1, 2, 3])
vals = collect(profile[sc] for sc in opscenarios(ts))
@test vals == [-1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2]

# RepresentativeProfile
repr = RepresentativePeriods(2, 5, [0.6, 0.4], [SimpleTimes(5, 1), SimpleTimes(5, 1)])
ts = TwoLevel(3, 5, repr)

profile = +RepresentativeProfile([1, 2, 3])
vals = collect(profile[rp] for rp in repr_periods(ts))
@test vals == [1, 2, 1, 2, 1, 2]

profile = -RepresentativeProfile([1, 2, 3])
vals = collect(profile[rp] for rp in repr_periods(ts))
@test vals == [-1, -2, -1, -2, -1, -2]
end

@testitem "Iteration utilities" begin
uniform_day = SimpleTimes(24, 1)
uniform_week = TwoLevel(7, 24, uniform_day)
Expand Down