Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatability update for ClustForOpt 0.4.0 #16

Merged
merged 3 commits into from
Jun 26, 2019
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["energy", "capacity", "JuMP", "optimization"]
license = "MIT"
desc = "Capacity Expansion Problem Formulation for Julia"
author = ["Elias Kuepper <elias.kuepper@rwth-aachen.de>"]
version = "0.1.4"
version = "0.1.5"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -19,4 +19,4 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
[compat]
julia = "^1.0"
JuMP = "^0.19"
ClustForOpt = "^0.3.4"
ClustForOpt = "^0.4.0"
2 changes: 1 addition & 1 deletion docs/src/assets/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plot(ts_input_data.data["solar-germany"], legend=false, linestyle=:dot, xlabel="
savefig(joinpath(dirname(@__FILE__),"preparing_clust_data_load.svg"))


ts_clust_data = run_clust(ts_input_data;method="kmeans",representation="centroid",n_init=50,n_clust=5).best_results
ts_clust_data = run_clust(ts_input_data;method="kmeans",representation="centroid",n_init=50,n_clust=5).clust_data
plot(ts_clust_data.data["solar-germany"], legend=false, linestyle=:solid, width=3, xlabel="Time [h]", ylabel="Solar availability factor [%]")
savefig(joinpath(dirname(@__FILE__),"preparing_clust_data_agg.svg"))

Expand Down
16 changes: 8 additions & 8 deletions examples/workflow_example_cep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ ts_seg_data = run_clust(ts_input_data;method="kmeans",representation="centroid",
optimizer=Clp.Optimizer

# tweak the CO2 level
co2_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;co2_limit=50) #generally values between 1250 and 10 are interesting
co2_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;co2_limit=50) #generally values between 1250 and 10 are interesting

# Include a Slack-Variable
slack_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;lost_el_load_cost=1e6, lost_CO2_emission_cost=700)
slack_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;lost_el_load_cost=1e6, lost_CO2_emission_cost=700)


# Include existing infrastructure at no COST
ex_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;existing_infrastructure=true)
ex_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;existing_infrastructure=true)

# Intraday storage (just within each period, same storage level at beginning and end)
simplestor_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;storage="simple")
simplestor_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;storage="simple")

# Interday storage (within each period & between the periods)
seasonalstor_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;storage="seasonal")
seasonalstor_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;storage="seasonal")

# Transmission
transmission_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;transmission=true)
transmission_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;transmission=true)

# Segmentation
seg_result = run_opt(ts_seg_data.best_results,cep_data,optimizer)
seg_result = run_opt(ts_seg_data.clust_data,cep_data,optimizer)

# Desing with clusered data and operation with ts_full_data
# First solve the clustered case
design_result = run_opt(ts_clust_data.best_results,cep_data,optimizer;co2_limit=50)
design_result = run_opt(ts_clust_data.clust_data,cep_data,optimizer;co2_limit=50)

#capacity_factors
design_variables=get_cep_design_variables(design_result)
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow_example_cep_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ts_clust_data = run_clust(ts_input_data;method="kmeans",representation="centroid
optimizer=Clp.Optimizer

# Optimize the capacity expansion problem with a co2_limit of 1000
cep = run_opt(ts_clust_data.best_results,cep_data,optimizer;co2_limit=1000)
cep = run_opt(ts_clust_data.clust_data,cep_data,optimizer;co2_limit=1000)

# Extract the CAP-Variable
cap=cep.variables["CAP"]
Expand Down
2 changes: 1 addition & 1 deletion examples/workflow_introduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
#############
# Quick example and investigation of the best result:
ts_clust_result = run_clust(ts_input_data; method="kmeans", representation="centroid", n_init=5, n_clust=5) # note that you should use n_init=1000 at least for kmeans.
ts_clust_data = ts_clust_result.best_results
ts_clust_data = ts_clust_result.clust_data
# And some plotting:
plot_comb_solar=plot!(plot_input_solar, ts_clust_data.data["solar-germany"], linestyle=:solid, width=3)
plot_clust_soar=plot(ts_clust_data.data["el_demand-germany"], legend=false, linestyle=:solid, width=3, xlabel="Time [h]", ylabel="Solar availability factor [%]")
Expand Down
6 changes: 3 additions & 3 deletions src/utils/datastructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ end


"""
Scenario{descriptor::String,clust_res::ClustResult,opt_res::OptResult}
Scenario{descriptor::String,clust_res::AbstractClustResult,opt_res::OptResult}
-`descriptor::String`
-`clust_res::ClustResult`
-`clust_res::AbstractClustResult`
-`opt_res::OptResult`
"""
struct Scenario
descriptor::String
clust_res::ClustResult
clust_res::AbstractClustResult
opt_res::OptResult
end
8 changes: 4 additions & 4 deletions src/utils/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,21 @@ function get_total_demand(cep::OptModelCEP,
end

"""
get_cost_series(cep_data::OptDataCEP,clust_res::ClustResultBest, opt_res::OptResult)
get_cost_series(cep_data::OptDataCEP,clust_res::ClustResult, opt_res::OptResult)
Return an array for the time series of costs in all the impact dimensions and the set of impacts
"""
function get_cost_series(nodes::DataFrame,
var_costs::DataFrame,
clust_res::ClustResultBest,
clust_res::ClustResult,
set::Dict{String,Array},
variables::Dict{String,OptVariable})
## DATA ##
# ts_ids: n_clustered periods
ts_ids=clust_res.best_ids
#ts_weights: k - weight of each period:
ts_weights=clust_res.best_results.weights
ts_weights=clust_res.clust_data.weights
#ts_deltas: t x k - Δt of each segment x period
ts_deltas=clust_res.best_results.delta_t
ts_deltas=clust_res.clust_data.delta_t

#emision at each period-step
cost_ts=zeros(length(ts_ids)+1,length(set["impact"]))
Expand Down
16 changes: 8 additions & 8 deletions test/cep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ using Clp
## OPTIMIZATION ##
optimizer=Clp.Optimizer
optimizer_config=Dict{Symbol,Any}(:LogLevel => 0)
scenarios["$state-$years-co2"] = run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="co2",co2_limit=1000,optimizer_config=optimizer_config)
scenarios["$state-$years-slack"] = run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="slack",lost_el_load_cost=1e6, lost_CO2_emission_cost=700,optimizer_config=optimizer_config)
scenarios["$state-$years-ex"] = run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="ex",existing_infrastructure=true,optimizer_config=optimizer_config)
scenarios["$state-$years-simple"] = run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="simple storage",storage="simple",optimizer_config=optimizer_config)
scenarios["$state-$years-seasonal"] = run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="seasonal storage",storage="seasonal",optimizer_config=optimizer_config)
design_result=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="des&op",optimizer_config=optimizer_config)
scenarios["$state-$years-des&op"] = run_opt(ts_full_data.best_results,cep_data,design_result.opt_config,get_cep_design_variables(design_result),optimizer;lost_el_load_cost=1e6,lost_CO2_emission_cost=700)
scenarios["$state-$years-co2"] = run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="co2",co2_limit=1000,optimizer_config=optimizer_config)
scenarios["$state-$years-slack"] = run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="slack",lost_el_load_cost=1e6, lost_CO2_emission_cost=700,optimizer_config=optimizer_config)
scenarios["$state-$years-ex"] = run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="ex",existing_infrastructure=true,optimizer_config=optimizer_config)
scenarios["$state-$years-simple"] = run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="simple storage",storage="simple",optimizer_config=optimizer_config)
scenarios["$state-$years-seasonal"] = run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="seasonal storage",storage="seasonal",optimizer_config=optimizer_config)
design_result=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="des&op",optimizer_config=optimizer_config)
scenarios["$state-$years-des&op"] = run_opt(ts_full_data.clust_data,cep_data,design_result.opt_config,get_cep_design_variables(design_result),optimizer;lost_el_load_cost=1e6,lost_CO2_emission_cost=700)
end
end
#Test transmission for a multi-node scenario
Expand All @@ -43,7 +43,7 @@ using Clp
ts_clust_data = run_clust(ts_input_data;method="hierarchical",representation="centroid",n_init=1,n_clust=3)
## OPTIMIZATION ##
optimizer=Clp.Optimizer
scenarios["$state-$years-trans"] = run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="trans",transmission=true,optimizer_config=Dict{Symbol,Any}(:LogLevel => 0))
scenarios["$state-$years-trans"] = run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="trans",transmission=true,optimizer_config=Dict{Symbol,Any}(:LogLevel => 0))
end
end
#Test exact values for each of the previously calculated scenarios by comparison with exact scenarios
Expand Down
16 changes: 8 additions & 8 deletions test/cep_exact_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ for (state, years) in [["GER_1", [2016]],["CA_1", [2016]]]
ts_full_data = run_clust(ts_input_data;method="hierarchical",representation="centroid",n_init=1,n_clust=30)
## OPTIMIZATION ##
optimizer=Clp.Optimizer
exact_scenarios["$state-$years-co2"]=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="co2",co2_limit=1000)
exact_scenarios["$state-$years-slack"]=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="slack",lost_el_load_cost=1e6, lost_CO2_emission_cost=700)
exact_scenarios["$state-$years-ex"]=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="ex",existing_infrastructure=true)
exact_scenarios["$state-$years-simple"]=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="simple storage",storage="simple")
exact_scenarios["$state-$years-seasonal"]=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="seasonal storage",storage="seasonal")
design_result=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="des&op")
exact_scenarios["$state-$years-des&op"]=run_opt(ts_full_data.best_results,cep_data,design_result.opt_config,get_cep_design_variables(design_result),optimizer;lost_el_load_cost=1e6,lost_CO2_emission_cost=700)
exact_scenarios["$state-$years-co2"]=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="co2",co2_limit=1000)
exact_scenarios["$state-$years-slack"]=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="slack",lost_el_load_cost=1e6, lost_CO2_emission_cost=700)
exact_scenarios["$state-$years-ex"]=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="ex",existing_infrastructure=true)
exact_scenarios["$state-$years-simple"]=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="simple storage",storage="simple")
exact_scenarios["$state-$years-seasonal"]=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="seasonal storage",storage="seasonal")
design_result=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="des&op")
exact_scenarios["$state-$years-des&op"]=run_opt(ts_full_data.clust_data,cep_data,design_result.opt_config,get_cep_design_variables(design_result),optimizer;lost_el_load_cost=1e6,lost_CO2_emission_cost=700)
end
for (state, years) in [["GER_18", [2016]],["CA_14", [2016]]]
# laod data
Expand All @@ -26,7 +26,7 @@ for (state, years) in [["GER_18", [2016]],["CA_14", [2016]]]
ts_clust_data = run_clust(ts_input_data;method="hierarchical",representation="centroid",n_init=1,n_clust=3)
## OPTIMIZATION ##
optimizer=Clp.Optimizer
exact_scenarios["$state-$years-trans"]=run_opt(ts_clust_data.best_results,cep_data,optimizer;descriptor="trans",transmission=true)
exact_scenarios["$state-$years-trans"]=run_opt(ts_clust_data.clust_data,cep_data,optimizer;descriptor="trans",transmission=true)
end

@save normpath(joinpath(dirname(@__FILE__),"cep_exact_data.jld2")) exact_scenarios