Skip to content

Commit

Permalink
Remove function resolution matrix (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawin committed Dec 13, 2023
1 parent b975ece commit dc8e169
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 85 deletions.
54 changes: 1 addition & 53 deletions src/time-resolution.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export resolution_matrix, compute_rp_partition, compute_constraints_partitions
export compute_rp_partition, compute_constraints_partitions

using SparseArrays

Expand Down Expand Up @@ -41,58 +41,6 @@ function compute_constraints_partitions(graph, representative_periods)
return constraints_partitions
end

"""
M = resolution_matrix(rp_partition, time_blocks; rp_resolution = 1.0)
Computes the resolution balance matrix using the array of `rp_partition` and the array of `time_blocks`.
The `time_blocks` will normally be from an asset or flow, but there is nothing constraining it to that.
The elements in these arrays must be ranges.
The resulting matrix will be multiplied by `rp_resolution`.
## Examples
The following two examples are for two flows/assets with resolutions of 3h and 4h, so that the representative period has 4h periods.
```jldoctest
rp_partition = [1:4, 5:8, 9:12]
time_blocks = [1:4, 5:8, 9:12]
resolution_matrix(rp_partition, time_blocks)
# output
3×3 SparseArrays.SparseMatrixCSC{Float64, Int64} with 3 stored entries:
1.0 ⋅ ⋅
⋅ 1.0 ⋅
⋅ ⋅ 1.0
```
```jldoctest
rp_partition = [1:4, 5:8, 9:12]
time_blocks = [1:3, 4:6, 7:9, 10:12]
resolution_matrix(rp_partition, time_blocks; rp_resolution = 1.5)
# output
3×4 SparseArrays.SparseMatrixCSC{Float64, Int64} with 6 stored entries:
1.5 0.5 ⋅ ⋅
⋅ 1.0 1.0 ⋅
⋅ ⋅ 0.5 1.5
```
"""
function resolution_matrix(
rp_partition::AbstractVector{<:UnitRange{<:Integer}},
time_blocks::AbstractVector{<:UnitRange{<:Integer}};
rp_resolution = 1.0,
)
matrix = sparse([
rp_resolution * length(period time_block) / length(time_block) for
period in rp_partition, time_block in time_blocks
])

return matrix
end

"""
rp_partition = compute_rp_partition(partitions; strategy = :greedy)
Expand Down
32 changes: 0 additions & 32 deletions test/test-time-resolution.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
@testset "Time resolution" begin
@testset "resolution_matrix" begin
rp_partition = [1:4, 5:8, 9:12]
for rp_resolution in [1e-4, 0.5, 1.0, 3.14, 1e4]
time_blocks = [1:4, 5:8, 9:12]
expected = rp_resolution * [
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
]
@test resolution_matrix(rp_partition, time_blocks; rp_resolution = rp_resolution)
expected

time_blocks = [1:3, 4:6, 7:9, 10:12]
expected = rp_resolution * [
1.0 1/3 0.0 0.0
0.0 2/3 2/3 0.0
0.0 0.0 1/3 1.0
]
@test resolution_matrix(rp_partition, time_blocks; rp_resolution = rp_resolution)
expected

time_blocks = [1:6, 7:9, 10:10, 11:11, 12:12]
expected = rp_resolution * [
2/3 0.0 0.0 0.0 0.0
1/3 2/3 0.0 0.0 0.0
0.0 1/3 1.0 1.0 1.0
]
@test resolution_matrix(rp_partition, time_blocks; rp_resolution = rp_resolution)
expected
end
end

@testset "compute_rp_partition" begin
# regular
partition1 = [1:4, 5:8, 9:12] # every 4 hours
Expand Down

0 comments on commit dc8e169

Please sign in to comment.