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

Temporal constraints #177

Closed
Closed
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
6 changes: 6 additions & 0 deletions src/input_tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ struct RepPeriodData
id::Int # Representative period ID
weight::Float64 # Hours
end

struct AssetsTimeResolutionData
id::Int
rep_period_id::Int
time_steps::String
end
34 changes: 33 additions & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export create_parameters_and_sets_from_file, create_graph, save_solution_to_file
export create_parameters_and_sets_from_file,
create_graph, save_solution_to_file, read_time_resolution_data

"""
parameters, sets = create_parameters_and_sets_from_file(input_folder)
Expand Down Expand Up @@ -198,3 +199,34 @@ function create_graph(assets_path, flows_path)

return graph
end

"""
"""
function read_time_resolution_data(sets, file_path)
df = read_csv_with_schema(file_path, AssetsTimeResolutionData)
N = length(sets.time_steps)

time_resolution = Dict(
(a, rp) => begin
j = findfirst(df.id .== a_id .&& df.rep_period_id .== rp_id)
if j === nothing
[k:k for k = 1:N]
else
time_steps = UnitRange{Int}[]
range_start = 1
range_instruction = split(df[j, :time_steps], "+")
for R in range_instruction
@show R
num, len = Meta.parse.(split(R, "x"))
for _ = 1:num
r = (1:len) .+ (range_start - 1)
range_start += len
push!(time_steps, r)
end
end
time_steps
end
end for (a_id, a) in enumerate(sets.assets),
(rp_id, rp) in enumerate(sets.rep_periods)
)
end
9 changes: 8 additions & 1 deletion src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ export create_model, solve_model
Create the model using the `graph` structure, the parameters and sets.
"""

function create_model(graph, params, sets; verbose = false, write_lp_file = false)
function create_model(
graph,
params,
sets,
time_resolution;
verbose = false,
write_lp_file = false,
)
# Sets unpacking
A = sets.assets
Ac = sets.assets_consumer
Expand Down
5 changes: 5 additions & 0 deletions test/inputs/Norse/assets-time-resolution.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
,,
id,rep_period_id,time_steps
2,1,56x4
3,1,42x3
6,1,20x1+16x2+12x3+10x4+8x5
Loading