Skip to content

Commit 4e58950

Browse files
Merge pull request #81 from holgerteichgraeber/master
Bring dev branch up to date with master
2 parents 8bfd7fd + 486f369 commit 4e58950

File tree

13 files changed

+123
-59
lines changed

13 files changed

+123
-59
lines changed

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ after_success:
1313

1414
jobs:
1515
include:
16-
- stage: "Documentation"
16+
- stage: "Testing"
1717
julia: 1.0
1818
os: linux
1919
script:
20-
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
21-
- julia --project=docs/ docs/make.jl
20+
- julia --project=test/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
21+
- julia --project=test/ test/clustering.jl
22+
- julia --project=test/ test/capacityexpansion.jl
2223
after_success:
23-
- stage: "Testing"
24+
- stage: "Documentation"
2425
julia: 1.0
2526
os: linux
2627
script:
27-
- julia --project=test/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
28-
- julia --project=test/ test/clustering.jl
28+
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
29+
- julia --project=docs/ docs/make.jl
2930
after_success:
3031
services: docker

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["clustering", "JuMP", "optimization"]
44
license = "MIT"
55
desc = "julia implementation of using different clustering methods for finding representative periods for the optimization of energy systems"
66
author = ["Holger Teichgraeber"]
7-
version = "0.2.3"
7+
version = "0.3.4"
88

99
[deps]
1010
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
@@ -18,3 +18,5 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1818
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1919
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2020

21+
[compat]
22+
julia = "^1.0"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![ClustForOpt](docs/src/assets/clust_for_opt_text.svg)
1+
![ClustForOpt](docs/src/assets/clust_for_opt_text.svg)
22
===
33
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://holgerteichgraeber.github.io/ClustForOpt.jl/stable)
44
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://holgerteichgraeber.github.io/ClustForOpt.jl/dev)
@@ -7,7 +7,7 @@
77

88
ClustForOpt is a [julia](www.juliaopt.com) implementation of clustering methods for finding representative periods for the optimization of energy systems. The package furthermore provides a multi-node capacity expansion model.
99

10-
The package has three main purposes: 1) Provide a simple process of clustering time-series input data, with clustered data output in a generalized type system 2) provide an interface between clustered data and optimization problem 3) provide a generalizable capacity expansion problem formulation and data to test clustering on this problem.
10+
The package has two main purposes: 1) Provide a simple process of clustering time-series input data, with clustered data output in a generalized type system 2) provide an interface between clustered data and optimization problem.
1111

1212
The package follows the clustering framework presented in [Teichgraeber and Brandt, 2019](https://doi.org/10.1016/j.apenergy.2019.02.012).
1313
The package is actively developed, and new features are continuously added. For a reproducible version of the methods and data of the original paper by [Teichgraeber and Brandt, 2019](https://doi.org/10.1016/j.apenergy.2019.02.012), please refer to release [v0.1](https://github.com/holgerteichgraeber/ClustForOpt.jl/tree/v0.1).
@@ -34,7 +34,7 @@ Install using:
3434

3535
```julia
3636
]
37-
add https://github.com/holgerteichgraeber/ClustForOpt.jl.git
37+
add ClustForOpt
3838
```
3939
where `]` opens the julia package manager.
4040

@@ -102,4 +102,4 @@ For use of DTW barycenter averaging (DBA) and k-shape clustering on single-attri
102102
### Optimization
103103
The function `run_opt()` runs the optimization problem and gives as an output a struct that contains optimal objective function value, decision variables, and additional info. The `run_opt()` function infers the optimization problem type from the input data. See the examples folder for further details.
104104

105-
More detailed documentation on the Capacity Expansion Problem can be found in the documentation.
105+
A Capacity Expansion Optimization Problem that utilizes `ClustForOpt` can be found in the package [CEP](https://github.com/YoungFaithful/CEP.jl).

docs/src/clust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ClustResultSimple
3636
## Example running clustering
3737
```@example
3838
using ClustForOpt
39-
# laod ts-input-data
39+
# load ts-input-data
4040
ts_input_data = load_timeseries_data(normpath(joinpath(@__DIR__,"..","..","data","TS_GER_1")); T=24, years=[2016])
4141
ts_clust_data = run_clust(ts_input_data).best_results
4242
using Plots

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://holgerteichgraeber.github.io/ClustForOpt.jl/dev)
55
[![Build Status](https://travis-ci.com/holgerteichgraeber/ClustForOpt.jl.svg?token=HRFemjSxM1NBCsbHGNDG&branch=master)](https://travis-ci.com/holgerteichgraeber/ClustForOpt.jl)
66

7-
[ClustForOpt](https://github.com/holgerteichgraeber/ClustForOpt.jl) is a [julia](https://www.juliaopt.com) implementation of clustering methods for finding representative periods for optimization problems. A utilization in a scalable capacity expansion problem can be found in the package [CEP](https://github.com/YoungFaithful/CEP.jl).
7+
[ClustForOpt](https://github.com/holgerteichgraeber/ClustForOpt.jl) is a [julia](https://www.juliaopt.com) implementation of clustering methods for finding representative periods for optimization problems. A utilization in a scalable capacity expansion problem can be found in the package [CEP](https://github.com/YoungFaithful/CapacityExpansion.jl).
88

99
The package has two main purposes: 1) Provide a simple process of clustering time-series input data, with clustered data output in a generalized type system 2) provide an interface between clustered data and optimization problem.
1010

@@ -33,6 +33,6 @@ Install using:
3333

3434
```julia
3535
]
36-
add https://github.com/holgerteichgraeber/ClustForOpt.jl.git
36+
add ClustForOpt
3737
```
3838
where `]` opens the julia package manager.

src/clustering/extreme_vals.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function simple_extr_val_ident(clust_data::ClustData,
7878
data_type::String;
7979
extremum::String="max",
8080
peak_def::String="absolute",
81-
consecutive_periods::Int64=1)
81+
consecutive_periods::Int=1)
8282
data=clust_data.data[data_type]
8383
delta_period=consecutive_periods-1
8484
# set data to be compared
@@ -168,7 +168,7 @@ function extreme_val_output(data::ClustData,
168168
end
169169
weights_ed=[]
170170
#initiate new k-ids-ed that don't represent any original time-period
171-
k_ids_ed=zeros(Int64,size(data.k_ids))
171+
k_ids_ed=zeros(Int,size(data.k_ids))
172172
if rep_mod_method == "feasibility"
173173
weights_ed = zeros(length(unique_extr_val_idcs))
174174
#no representation is done of the original time-period, it's just for feasibility

src/clustering/intraperiod_segmentation.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function run_clust_segmentation(period::Array{Float64,2};
3838
norm_period, typely_mean, typely_sdv=z_normalize(period;scope=norm_scope)
3939
#x,weights,clustids,x,iter= run_clust_hierarchical(norm_period,n_seg,iterations)
4040
data=norm_period
41-
clustids=run_clust_hierarchical_partitional(data::Array, n_seg::Int64)
41+
clustids=run_clust_hierarchical_partitional(data::Array, n_seg::Int)
4242
weights = calc_weights(clustids,n_seg)
4343

4444

@@ -48,7 +48,7 @@ function run_clust_segmentation(period::Array{Float64,2};
4848
return centers,weights,clustids,cost,1
4949
end
5050

51-
function get_clustids(ends::Array{Int64,1})
51+
function get_clustids(ends::Array{Int,1})
5252
clustids=collect(1:size(data,2))
5353
j=1
5454
for i in 1:size(data,2)
@@ -61,12 +61,12 @@ function get_clustids(ends::Array{Int64,1})
6161
end
6262

6363
"""
64-
run_clust_hierarchical_partitional(data::Array, n_seg::Int64)
64+
run_clust_hierarchical_partitional(data::Array, n_seg::Int)
6565
!!! Not yet proven
6666
Usees provided data and number of segments to aggregate them together
6767
"""
6868
function run_clust_hierarchical_partitional(data::Array,
69-
n_seg::Int64)
69+
n_seg::Int)
7070
_dist= SqEuclidean()
7171
#Assign each timeperiod it's own cluster
7272
clustids=collect(1:size(data,2))
@@ -99,20 +99,20 @@ function run_clust_hierarchical_partitional(data::Array,
9999
end
100100

101101
"""
102-
merge_clustids!(clustids::Array{Int64,1},index::Int64)
102+
merge_clustids!(clustids::Array{Int,1},index::Int)
103103
Calculate the new clustids by merging the cluster of the index provided with the cluster of index+1
104104
"""
105-
function merge_clustids!(clustids::Array{Int64,1},index::Int64)
105+
function merge_clustids!(clustids::Array{Int,1},index::Int)
106106
clustids[index+1]=clustids[index]
107107
clustids[index+2:end].-=1
108108
end
109109

110110
"""
111-
get_mean_data(data::Array, clustids::Array{Int64,1})
111+
get_mean_data(data::Array, clustids::Array{Int,1})
112112
Calculate mean of data: The number of columns is kept the same, mean is calculated for aggregated columns and the same in all with same clustid
113113
"""
114114
function get_mean_data(data::Array,
115-
clustids::Array{Int64,1})
115+
clustids::Array{Int,1})
116116
mean_data=zeros(size(data))
117117
for i in 1:size(data,2)
118118
mean_data[:,i]=mean(data[:,findall(clustids.==clustids[i])], dims=2)

src/clustering/run_clust.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function run_clust(data_norm_merged::ClustDataMerged;
6262
n_clust::Int=5,
6363
n_init::Int=100,
6464
iterations::Int=300,
65-
orig_k_ids::Array{Int64,1}=Array{Int64,1}(),
65+
orig_k_ids::Array{Int,1}=Array{Int,1}(),
6666
kwargs...)
6767
6868
method: "kmeans","kmedoids","kmedoids_exact","hierarchical"
@@ -75,7 +75,7 @@ function run_clust(data_norm_merged::ClustDataMerged,
7575
n_clust::Int=5,
7676
n_init::Int=100,
7777
iterations::Int=300,
78-
orig_k_ids::Array{Int64,1}=Array{Int64,1}(),
78+
orig_k_ids::Array{Int,1}=Array{Int,1}(),
7979
kwargs...)
8080
# initialize data arrays
8181
centers = Array{Array{Float64},1}(undef,n_init)

src/utils/datastructs.jl

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ abstract type ClustResult end
77
"FullInputData"
88
struct FullInputData <: TSData
99
region::String
10-
years::Array{Int64}
10+
years::Array{Int,1}
1111
N::Int
1212
data::Dict{String,Array}
1313
end
1414

1515
"""
16-
ClustData{region::String,K::Int,T::Int,data::Dict{String,Array},weights::Array{Float64},mean::Dict{String,Array},sdv::Dict{String,Array}} <: TSData
16+
ClustData{region::String,K::Int,T::Int,data::Dict{String,Array},weights::Array{Float64,2},mean::Dict{String,Array},sdv::Dict{String,Array},delta_t::Array{Float64,2},k_ids::Array{Int}} <: TSData
1717
- region: optional information to specify the region data belongs to
1818
- K: number of periods
1919
- T: time steps per period
@@ -26,21 +26,21 @@ end
2626
"""
2727
struct ClustData <: TSData
2828
region::String
29-
years::Array{Int64}
29+
years::Array{Int}
3030
K::Int
3131
T::Int
3232
data::Dict{String,Array}
3333
weights::Array{Float64}
3434
mean::Dict{String,Array}
3535
sdv::Dict{String,Array}
3636
delta_t::Array{Float64,2}
37-
k_ids::Array{Int64}
37+
k_ids::Array{Int}
3838
end
3939

4040
"ClustDataMerged"
4141
struct ClustDataMerged <: TSData
4242
region::String
43-
years::Array{Int64}
43+
years::Array{Int}
4444
K::Int
4545
T::Int
4646
data::Array
@@ -49,7 +49,7 @@ struct ClustDataMerged <: TSData
4949
mean::Dict{String,Array}
5050
sdv::Dict{String,Array}
5151
delta_t::Array{Float64,2}
52-
k_ids::Array{Int64}
52+
k_ids::Array{Int}
5353
end
5454

5555
"ClustResultAll"
@@ -88,12 +88,12 @@ struct SimpleExtremeValueDescr
8888
data_type::String
8989
extremum::String
9090
peak_def::String
91-
consecutive_periods::Int64
91+
consecutive_periods::Int
9292
"Replace default constructor to only allow certain entries"
9393
function SimpleExtremeValueDescr(data_type::String,
9494
extremum::String,
9595
peak_def::String,
96-
consecutive_periods::Int64)
96+
consecutive_periods::Int)
9797
# only allow certain entries
9898
if !(extremum in ["min","max"])
9999
@error("extremum - "*extremum*" - not defined")
@@ -142,7 +142,7 @@ end
142142

143143
"""
144144
ClustData(region::String,
145-
years::Array{Int64,1},
145+
years::Array{Int,1},
146146
K::Int,
147147
T::Int;
148148
el_price::Array=[],
@@ -153,12 +153,12 @@ end
153153
mean::Dict{String,Array}=Dict{String,Array}(),
154154
sdv::Dict{String,Array}=Dict{String,Array}(),
155155
delta_t::Array{Float64,2}=ones(T,K),
156-
k_ids::Array{Int64,1}=collect(1:K)
156+
k_ids::Array{Int,1}=collect(1:K)
157157
)
158158
constructor 1 for ClustData: provide data individually
159159
"""
160160
function ClustData(region::String,
161-
years::Array{Int64,1},
161+
years::Array{Int,1},
162162
K::Int,
163163
T::Int;
164164
el_price::Array=[],
@@ -169,7 +169,7 @@ function ClustData(region::String,
169169
mean::Dict{String,Array}=Dict{String,Array}(),
170170
sdv::Dict{String,Array}=Dict{String,Array}(),
171171
delta_t::Array{Float64,2}=ones(T,K),
172-
k_ids::Array{Int64,1}=collect(1:K)
172+
k_ids::Array{Int,1}=collect(1:K)
173173
)
174174
dt = Dict{String,Array}()
175175
mean_sdv_provided = ( !isempty(mean) && !isempty(sdv))
@@ -208,26 +208,26 @@ end
208208

209209
"""
210210
ClustData(region::String,
211-
years::Array{Int64,1},
211+
years::Array{Int,1},
212212
K::Int,
213213
T::Int,
214214
data::Dict{String,Array},
215215
weights::Array{Float64},
216216
delta_t::Array{Float64,2},
217-
k_ids::Array{Int64,1};
217+
k_ids::Array{Int,1};
218218
mean::Dict{String,Array}=Dict{String,Array}(),
219219
sdv::Dict{String,Array}=Dict{String,Array}()
220220
)
221221
constructor 2 for ClustData: provide data as dict
222222
"""
223223
function ClustData(region::String,
224-
years::Array{Int64,1},
224+
years::Array{Int,1},
225225
K::Int,
226226
T::Int,
227227
data::Dict{String,Array},
228228
weights::Array{Float64},
229229
delta_t::Array{Float64,2},
230-
k_ids::Array{Int64,1};
230+
k_ids::Array{Int,1};
231231
mean::Dict{String,Array}=Dict{String,Array}(),
232232
sdv::Dict{String,Array}=Dict{String,Array}()
233233
)
@@ -273,27 +273,28 @@ end
273273

274274
"""
275275
ClustDataMerged(region::String,
276-
years::Array{Int64,1},
276+
years::Array{Int,1},
277277
K::Int,
278278
T::Int,
279279
data::Array,
280280
data_type::Array{String},
281281
weights::Array{Float64},
282-
k_ids::Array{Int64,1};
282+
k_ids::Array{Int,1};
283+
delta_t::Array{Float64,2}=ones(T,K),
283284
mean::Dict{String,Array}=Dict{String,Array}(),
284285
sdv::Dict{String,Array}=Dict{String,Array}()
285286
)
286287
constructor 1: construct ClustDataMerged
287288
"""
288289
function ClustDataMerged(region::String,
289-
years::Array{Int64,1},
290+
years::Array{Int,1},
290291
K::Int,
291292
T::Int,
292293
data::Array,
293294
data_type::Array{String},
294295
weights::Array{Float64},
295-
k_ids::Array{Int64,1};
296-
delta_t::Array{Float64}=ones(T,K),
296+
k_ids::Array{Int,1};
297+
delta_t::Array{Float64,2}=ones(T,K),
297298
mean::Dict{String,Array}=Dict{String,Array}(),
298299
sdv::Dict{String,Array}=Dict{String,Array}()
299300
)

0 commit comments

Comments
 (0)