Skip to content

Commit

Permalink
Remove graph and other internal structures and general cleaning (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira authored Feb 18, 2025
1 parent b192ac4 commit 9da0775
Show file tree
Hide file tree
Showing 29 changed files with 145 additions and 1,283 deletions.
4 changes: 0 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DuckDB = "d2f5444f-75bc-4fdf-ac35-56f514c445e1"
DuckDB_jll = "2cbbab25-fc8b-58cf-88d4-687a02676033"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -26,11 +24,9 @@ CSV = "0.10"
DataFrames = "1"
DuckDB = "0.10, ~1.0" # ~1.0 until they fix https://github.com/duckdb/duckdb/issues/13911
DuckDB_jll = "0.10, ~1.0" # DuckDB 1.0.0 still allows DuckDB_jll 1.1.0
Graphs = "1.8"
HiGHS = "1"
JuMP = "1"
MathOptInterface = "1"
MetaGraphsNext = "0.6, 0.7"
OrderedCollections = "1"
SparseArrays = "1"
Statistics = "1"
Expand Down
1 change: 0 additions & 1 deletion benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BenchmarkTools
using TulipaEnergyModel
using MetaGraphsNext
using TulipaIO
using DuckDB

Expand Down
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
TulipaEnergyModel = "5d7bd171-d18e-45a5-9111-f1f11ac5d04d"
TulipaIO = "7b3808b7-0819-42d4-885c-978ba173db11"
16 changes: 7 additions & 9 deletions docs/src/60-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ It hides the complexity behind the energy problem, making the usage more friendl

### Fields

- `db_connection`: A DuckDB connection to the input tables in the model
- `graph`: The Graph object that defines the geometry of the energy problem.
- `db_connection`: A DuckDB connection to the input tables in the model.
- `variables`: A dictionary of [TulipaVariable](@ref TulipaVariable)s containing the variables of the model.
- `expressions`: A dictionary of [TulipaExpression](@ref TulipaExpression)s containing the expressions of the model attached to tables.
- `constraints`: A dictionary of [TulipaConstraint](@ref TulipaConstraint)s containing the constraints of the model.
- `profiles`: Holds the profiles per `rep_period` or `over_clustered_year` in dictionary format. See [ProfileLookup](@ref).
- `model_parameters`: A [ModelParameters](@ref ModelParameters) structure to store all the parameters that are exclusive of the model.
- `model`: A JuMP.Model object representing the optimization model.
- `objective_value`: The objective value of the solved problem (Float64).
- `variables`: A [TulipaVariable](@ref TulipaVariable) structure to store all the information related to the variables in the model.
- `constraints`: A [TulipaConstraint](@ref TulipaConstraint) structure to store all the information related to the constraints in the model.
- `representative_periods`: A vector of [Representative Periods](@ref representative-periods).
- `solved`: A boolean indicating whether the `model` has been solved or not.
- `objective_value`: The objective value of the solved problem (Float64).
- `termination_status`: The termination status of the optimization model.
- `timeframe`: A structure with the number of periods in the `representative_periods` and the mapping between the periods and their representatives.
- `model_parameters`: A [ModelParameters](@ref ModelParameters) structure to store all the parameters that are exclusive of the model.
- `years`: A vector with the information of all the milestone years.

### Constructor

Expand Down
5 changes: 0 additions & 5 deletions src/TulipaEnergyModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ using DuckDB: DuckDB, DBInterface
using TOML: TOML
using TulipaIO: TulipaIO

## Graph
using Graphs: Graphs, SimpleDiGraph
using MetaGraphsNext: MetaGraphsNext, MetaGraph

## Optimization
using HiGHS: HiGHS
using JuMP: JuMP, @constraint, @expression, @objective, @variable
Expand Down Expand Up @@ -48,7 +44,6 @@ for folder_name in ["variables", "constraints", "expressions"]
include(joinpath(folder_path, file))
end
end
include("economic-parameters.jl")
include("objective.jl")
include("create-model.jl")

Expand Down
2 changes: 1 addition & 1 deletion src/constraints/capacity.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export add_capacity_constraints!

"""
add_capacity_constraints!(model, graph,...)
add_capacity_constraints!(connection, model, expressions, constraints, profiles)
Adds the capacity constraints for all asset types to the model
"""
Expand Down
8 changes: 1 addition & 7 deletions src/constraints/consumer.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
export add_consumer_constraints!

"""
add_consumer_constraints!(model,
graph,
dataframes,
Ac,
incoming_flow_highest_in_out_resolution,
outgoing_flow_highest_in_out_resolution,
)
add_consumer_constraints!(connection, model, constraints, profiles)
Adds the consumer asset constraints to the model.
"""
Expand Down
1 change: 0 additions & 1 deletion src/constraints/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ add_conversion_constraints!(model,
Adds the conversion asset constraints to the model.
"""

function add_conversion_constraints!(model, constraints)
# - Balance constraint (using the lowest temporal resolution)
let table_name = :balance_conversion, cons = constraints[table_name]
Expand Down
5 changes: 2 additions & 3 deletions src/constraints/energy.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export add_energy_constraints!

"""
function add_energy_constraints!(model, graph, dataframes)
add_energy_constraints!(connection, model, constraints, profiles)
Adds the energy constraints for assets withnin the period blocks of the timeframe (inter-temporal) to the model.
Adds the energy constraints for assets within the period blocks of the timeframe (inter-temporal) to the model.
"""

function add_energy_constraints!(connection, model, constraints, profiles)
## INTER-TEMPORAL CONSTRAINTS (between representative periods)

Expand Down
8 changes: 1 addition & 7 deletions src/constraints/hub.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
export add_hub_constraints!

"""
add_hub_constraints!(model,
dataframes,
Ah,
incoming_flow_highest_in_out_resolution,
outgoing_flow_highest_in_out_resolution,
)
add_hub_constraints!(model, constraints)
Adds the hub asset constraints to the model.
"""

function add_hub_constraints!(model, constraints)
# - Balance constraint (using the lowest temporal resolution)
let table_name = :balance_hub, cons = constraints[:balance_hub]
Expand Down
9 changes: 8 additions & 1 deletion src/constraints/ramping-and-unit-commitment.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
export add_ramping_and_unit_commitment_constraints!

"""
add_ramping_and_unit_commitment_constraints!(model, graph, ...)
add_ramping_and_unit_commitment_constraints!(
connection,
model,
variables,
expressions,
constraints,
profiles
)
Adds the ramping constraints for producer and conversion assets where ramping = true in assets_data
"""
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/storage.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export add_storage_constraints!

"""
add_storage_constraints!(model, graph,...)
add_storage_constraints!(connection, model, variables, expressions, constraints, profiles)
Adds the storage asset constraints to the model.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/transport.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export add_transport_constraints!

"""
add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_investment)
add_transport_constraints!(connection, model, variables, expressions, constraints, profiles)
Adds the transport flow constraints to the model.
"""
Expand Down
23 changes: 13 additions & 10 deletions src/create-model.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
export create_model!, create_model

"""
create_model!(energy_problem; verbose = false)
create_model!(energy_problem; kwargs...)
Create the internal model of an [`TulipaEnergyModel.EnergyProblem`](@ref).
Any keyword argument will be passed to the underlyting [`create_model`](@ref).
"""
function create_model!(energy_problem; kwargs...)
energy_problem.model = @timeit to "create_model" create_model(
energy_problem.db_connection,
energy_problem.graph,
energy_problem.variables,
energy_problem.expressions,
energy_problem.constraints,
energy_problem.profiles,
energy_problem.representative_periods,
energy_problem.model_parameters;
kwargs...,
)
Expand All @@ -25,18 +24,25 @@ function create_model!(energy_problem; kwargs...)
end

"""
model = create_model(args...; write_lp_file = false, enable_names = true)
model = create_model(
connection,
variables,
expressions,
constraints,
profiles,
model_parameters;
write_lp_file = false,
enable_names = true
)
Create the energy model manually. We recommend using [`create_model!`](@ref) instead.
"""
function create_model(
connection,
graph,
variables,
expressions,
constraints,
profiles,
representative_periods,
model_parameters;
write_lp_file = false,
enable_names = true,
Expand All @@ -58,17 +64,14 @@ function create_model(
@timeit to "add_flow_variables!" add_flow_variables!(connection, model, variables)
@timeit to "add_investment_variables!" add_investment_variables!(model, variables)
@timeit to "add_unit_commitment_variables!" add_unit_commitment_variables!(model, variables)
@timeit to "add_storage_variables!" add_storage_variables!(model, graph, variables)
@timeit to "add_storage_variables!" add_storage_variables!(connection, model, variables)

## Add expressions to dataframes
# TODO: What will improve this? Variables (#884)?, Constraints?
@timeit to "add_expressions_to_constraints!" add_expressions_to_constraints!(
connection,
variables,
constraints,
model,
expression_workspace,
profiles,
)

## Expressions for multi-year investment
Expand Down
Loading

0 comments on commit 9da0775

Please sign in to comment.