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

Create functions for plotting #227

Closed
wants to merge 1 commit into from
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ version = "0.3.0"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Expand Down
3 changes: 3 additions & 0 deletions src/TulipaEnergyModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ using DataFrames
using Graphs
using HiGHS
using JuMP
using Plots

export plot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be necessary.


include("input-tables.jl")
include("io.jl")
Expand Down
18 changes: 18 additions & 0 deletions src/analysis_results.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using GraphPlot

sets, graph, F, solution = run_model()

# plot flow time series
from_flow = "Valhalla_Fuel_cell"
to_flow = "Valhalla_E_balance"
p = show_flow_time_series(from_flow, to_flow, 1, sets.time_steps, solution.flow)
display(p)

# plot graph with edge values
rp = 1
time = 1
edge_labels = Dict(f => solution.flow[f, rp, time] for f in F)

edge_label_list = [edge_labels[(src(e), dst(e))] for e in edges(graph)]
g = gplot(graph; edgelabel = edge_label_list)
display(g)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I ignore this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @abelsiqueira ,
The rationale for having this file is given above

In addition, I realized there is no existing function for running the model and deriving the results (apart from the test). For this purpose, also a file in src has been added. This may related to #209. Is creating such a file a desired way to do so?

The line 16-18 is just some early codes for plotting the graph with edge values, which are not working yet.

I'm not sure which you'd like to dump, but feel free to do so as I won't be able to follow it up soon. Thanks.

47 changes: 46 additions & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export create_parameters_and_sets_from_file,
create_graph, save_solution_to_file, compute_time_intervals
create_graph,
save_solution_to_file,
compute_time_intervals,
show_flow_time_series,
run_model

"""
parameters, sets = create_parameters_and_sets_from_file(input_folder)
Expand Down Expand Up @@ -207,6 +211,47 @@ function save_solution_to_file(
return
end

"""
show_flow_time_series()

Plots a time series for a flow, given asset `from_flow`, asset `to_flow`,
`representative_period`, `set_time_steps`, and solution flow.
"""
function show_flow_time_series(
from_flow,
to_flow,
representative_period,
set_time_steps,
v_flow,
)
Comment on lines +215 to +226
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these names have to be checked against #208

x_values = set_time_steps[representative_period]
y_values = [v_flow[(from_flow, to_flow), representative_period, t] for t in x_values]

p = plot(x_values, y_values; label = "Flow", legend = :top)

xlabel!("Time steps")

return p
end

"""
run_model()

Runs the model for the Norse case.
Returns several outputs for plotting purposes.
"""
function run_model()
INPUT_FOLDER = joinpath(dirname(@__DIR__), "test/inputs")
OUTPUT_FOLDER = joinpath(dirname(@__DIR__), "test/outputs")

dir = joinpath(INPUT_FOLDER, "Norse")
parameters, sets = create_parameters_and_sets_from_file(dir)
graph = create_graph(joinpath(dir, "assets-data.csv"), joinpath(dir, "flows-data.csv"))
model, F = create_model(graph, parameters, sets)
solution = solve_model(model)

return sets, graph, F, solution
end
"""
graph = create_graph(assets_path, flows_path)

Expand Down
2 changes: 1 addition & 1 deletion src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function create_model(graph, params, sets; verbose = false, write_lp_file = fals
write_to_file(model, "model.lp")
end

return model
return model, F
end

"""
Expand Down