Skip to content

Commit 97107fd

Browse files
committed
Update documentation
1 parent 3b8acca commit 97107fd

File tree

7 files changed

+356
-425
lines changed

7 files changed

+356
-425
lines changed

docs/src/10-how-to-use.md

Lines changed: 119 additions & 330 deletions
Large diffs are not rendered by default.

docs/src/20-tutorials.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,22 @@ There is currently no reason to manually create and maintain these structures yo
102102

103103
To avoid having to update this documentation whenever we make changes to the internals of TulipaEnergyModel before the v1.0.0 release, we will keep this section empty until then.
104104

105-
### Change optimizer and specify parameters
105+
## Change optimizer and specify parameters
106106

107107
By default, the model is solved using the [HiGHS](https://github.com/jump-dev/HiGHS.jl) optimizer (or solver).
108108
To change this, we can give the functions `run_scenario` or `solve_model!` a
109109
different optimizer.
110110

111111
!!! warning
112-
HiGHS is the only open source solver that we recommend. GLPK and Cbc are missing features and are not (fully) tested for Tulipa.
112+
HiGHS is the only open source solver that we recommend. GLPK and Cbc are not (fully) tested for Tulipa.
113113

114-
For instance, we run the [GLPK](https://github.com/jump-dev/GLPK.jl) optimizer below:
114+
For instance, let's run the Tiny example using the [GLPK](https://github.com/jump-dev/GLPK.jl) optimizer:
115115

116116
```@example
117117
using DuckDB, TulipaIO, TulipaEnergyModel, GLPK
118118
119119
input_dir = "../../test/inputs/Tiny" # hide
120+
# input_dir should be the path to Tiny as a string (something like "test/inputs/Tiny")
120121
connection = DBInterface.connect(DuckDB.DB)
121122
read_csv_folder(connection, input_dir; schemas = TulipaEnergyModel.schema_per_table_name)
122123
energy_problem = run_scenario(connection, optimizer = GLPK.Optimizer)
@@ -130,8 +131,8 @@ using GLPK
130131
solution = solve_model!(energy_problem, GLPK.Optimizer)
131132
```
132133

133-
Notice that, in any of these cases, we need to explicitly add the GLPK package
134-
ourselves and add `using GLPK` before using `GLPK.Optimizer`.
134+
!!! info
135+
Notice that, in any of these cases, we need to explicitly add the GLPK package ourselves and add `using GLPK` before using `GLPK.Optimizer`.
135136

136137
In any of these cases, default parameters for the `GLPK` optimizer are used,
137138
which you can query using [`default_parameters`](@ref).

docs/src/30-concepts.md

Lines changed: 124 additions & 80 deletions
Large diffs are not rendered by default.

docs/src/40-formulation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ v^{\text{intra-storage}}_{a,k_y,b^{\text{first}}_{k_y}} \geq p^{\text{init stora
577577

578578
This constraint allows us to consider the storage seasonality throughout the model's timeframe (e.g., a year). The parameter $p^{\text{map}}_{p_y,k_y}$ determines how much of the representative period $k_y$ is in the period $p_y$, and you can use a clustering technique to calculate it. For _TulipaEnergyModel.jl_, we recommend using [_TulipaClustering.jl_](https://github.com/TulipaEnergy/TulipaClustering.jl) to compute the clusters for the representative periods and their map.
579579

580-
For the sake of simplicity, we show the constraint assuming the inter-storage level between two consecutive periods $p_y$; however, _TulipaEnergyModel.jl_ can handle more flexible period block definition through the timeframe definition in the model using the information in the file [`assets-timeframe-partitions.csv`](@ref assets-timeframe-partitions).
580+
For the sake of simplicity, we show the constraint assuming the inter-storage level between two consecutive periods $p_y$; however, _TulipaEnergyModel.jl_ can handle more flexible period block definition through the timeframe definition in the model using the information in the timeframe partitions file, see [schemas](@ref schemas).
581581

582582
```math
583583
\begin{aligned}
@@ -679,23 +679,23 @@ v^{\text{flow}}_{f,k_y,b_{k_y}} \geq - p^{\text{availability profile}}_{f,y,k_y,
679679
v^{\text{inv}}_{a,y} \leq \frac{p^{\text{inv limit}}_{a,y}}{p^{\text{capacity}}_{a}} \quad \forall y \in \mathcal{Y}, \forall a \in \mathcal{A}^{\text{i}}_y
680680
```
681681

682-
If the parameter `investment_integer` in the [`assets-data.csv`](@ref assets-data) file is set to true, then the right-hand side of this constraint uses a least integer function (floor function) to guarantee that the limit is integer.
682+
If the parameter `investment_integer` is set to true, then the right-hand side of this constraint uses a least integer function (floor function) to guarantee that the limit is integer.
683683

684684
#### Maximum Energy Investment Limit for Assets
685685

686686
```math
687687
v^{\text{inv energy}}_{a,y} \leq \frac{p^{\text{inv limit energy}}_{a,y}}{p^{\text{energy capacity}}_{a}} \quad \forall y \in \mathcal{Y}, \forall a \in \mathcal{A}^{\text{i}}_y \cap \mathcal{A}^{\text{se}}_y
688688
```
689689

690-
If the parameter `investment_integer_storage_energy` in the [`assets-data.csv`](@ref assets-data) file is set to true, then the right-hand side of this constraint uses a least integer function (floor function) to guarantee that the limit is integer.
690+
If the parameter `investment_integer_storage_energy` is set to true, then the right-hand side of this constraint uses a least integer function (floor function) to guarantee that the limit is integer.
691691

692692
#### Maximum Investment Limit for Flows
693693

694694
```math
695695
v^{\text{inv}}_{f,y} \leq \frac{p^{\text{inv limit}}_{f,y}}{p^{\text{capacity}}_{f}} \quad \forall y \in \mathcal{Y}, \forall f \in \mathcal{F}^{\text{ti}}_y
696696
```
697697

698-
If the parameter `investment_integer` in the [`flows-data.csv`](@ref flows-data) file is set to true, then the right-hand side of this constraint uses a least integer function (floor function) to guarantee that the limit is integer.
698+
If the parameter `investment_integer` is set to true, then the right-hand side of this constraint uses a least integer function (floor function) to guarantee that the limit is integer.
699699

700700
### [Inter-temporal Energy Constraints](@id inter-temporal-energy-constraints)
701701

docs/src/50-schemas.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# [Model Parameters](@id schemas)
2+
3+
The optimization model parameters with the input data must follow the schema below for each table. To create these tables we currently use CSV files that follow this same schema and then convert them into tables using TulipaIO, as shown in the basic example of the [Tutorials](@ref basic-example) section.
4+
5+
The schemas can be accessed at any time after loading the package by typing `TulipaEnergyModel.schema_per_table_name` in the Julia console. Here is the complete list of model parameters in the schemas per table (or CSV file):
6+
7+
```@eval
8+
using Markdown, TulipaEnergyModel
9+
10+
Markdown.parse(
11+
join(["- **`$filename`**\n" *
12+
join(
13+
[" - `$f: $t`" for (f, t) in schema],
14+
"\n",
15+
) for (filename, schema) in TulipaEnergyModel.schema_per_table_name
16+
] |> sort, "\n")
17+
)
18+
```

docs/src/60-structures.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# [Model Structures](@id structures)
2+
3+
```@contents
4+
Pages = ["60-structures.md"]
5+
Depth = 3
6+
```
7+
8+
The list of relevant structures used in this package are listed below:
9+
10+
## EnergyProblem
11+
12+
The `EnergyProblem` structure is a wrapper around various other relevant structures.
13+
It hides the complexity behind the energy problem, making the usage more friendly, although more verbose.
14+
15+
### Fields
16+
17+
- `db_connection`: A DuckDB connection to the input tables in the model
18+
- `graph`: The Graph object that defines the geometry of the energy problem.
19+
- `model`: A JuMP.Model object representing the optimization model.
20+
- `objective_value`: The objective value of the solved problem (Float64).
21+
- `variables`: A [TulipaVariable](@ref TulipaVariable) structure to store all the information related to the variables in the model.
22+
- `constraints`: A [TulipaConstraint](@ref TulipaConstraint) structure to store all the information related to the constraints in the model.
23+
- `representative_periods`: A vector of [Representative Periods](@ref representative-periods).
24+
- `solved`: A boolean indicating whether the `model` has been solved or not.
25+
- `termination_status`: The termination status of the optimization model.
26+
- `timeframe`: A structure with the number of periods in the `representative_periods` and the mapping between the periods and their representatives.
27+
- `model_parameters`: A [ModelParameters](@ref ModelParameters) structure to store all the parameters that are exclusive of the model.
28+
- `years`: A vector with the information of all the milestone years.
29+
30+
### Constructor
31+
32+
The `EnergyProblem` can also be constructed using the minimal constructor below.
33+
34+
- `EnergyProblem(connection)`: Constructs a new `EnergyProblem` object with the given `connection` that has been created and the data loaded into it using [TulipaIO](https://github.com/TulipaEnergy/TulipaIO.jl). The `graph`, `representative_periods`, `timeframe`, and `years` are computed using `create_internal_structures`.
35+
36+
See the [basic example tutorial](@ref basic-example) to see how these can be used.
37+
38+
## GraphAssetData
39+
40+
This structure holds all the information of a given asset.
41+
These are stored inside the Graph.
42+
Given a graph `graph`, an asset `a` can be accessed through `graph[a]`.
43+
44+
## GraphFlowData
45+
46+
This structure holds all the information of a given flow.
47+
These are stored inside the Graph.
48+
Given a graph `graph`, a flow from asset `u` to asset `v` can be accessed through `graph[u, v]`.
49+
50+
## [Timeframe](@id timeframe)
51+
52+
The timeframe is the total period we want to analyze with the model. Usually this is a year, but it can be any length of time. A timeframe has two fields:
53+
54+
- `num_periods`: The timeframe is defined by a certain number of periods. For instance, a year can be defined by 365 periods, each describing a day.
55+
- `map_periods_to_rp`: Indicates the periods of the timeframe that map into a [representative period](@ref representative-periods) and the weight of the representative period to construct that period.
56+
57+
## [Representative Periods](@id representative-periods)
58+
59+
The [timeframe](@ref timeframe) (e.g., a full year) is described by a selection of representative periods, for instance, days or weeks, that nicely summarize other similar periods. For example, we could model the year into 3 days, by clustering all days of the year into 3 representative days. Each one of these days is called a representative period. _TulipaEnergyModel.jl_ has the flexibility to consider representative periods of different lengths for the same timeframe (e.g., a year can be represented by a set of 4 days and 2 weeks). To obtain the representative periods, we recommend using [TulipaClustering](https://github.com/TulipaEnergy/TulipaClustering.jl).
60+
61+
A representative period has three fields:
62+
63+
- `weight`: Indicates how many representative periods are contained in the [timeframe](@ref timeframe); this is inferred automatically from `map_periods_to_rp` in the [timeframe](@ref timeframe).
64+
- `timesteps`: The number of timesteps blocks in the representative period.
65+
- `resolution`: The duration in time of each timestep.
66+
67+
The number of timesteps and resolution work together to define the coarseness of the period.
68+
Nothing is defined outside of these timesteps; for instance, if the representative period represents a day and you want to specify a variable or constraint with a coarseness of 30 minutes. You need to define the number of timesteps to 48 and the resolution to `0.5`.
69+
70+
## [Time Blocks](@id time-blocks)
71+
72+
A time block is a range for which a variable or constraint is defined.
73+
It is a range of numbers, i.e., all integer numbers inside an interval.
74+
Time blocks are used for the periods in the [timeframe](@ref timeframe) and the timesteps in the [representative period](@ref representative-periods). Time blocks are disjunct (not overlapping), but do not have to be sequential.

src/structures.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ mutable struct TulipaVariable
5151
end
5252
end
5353

54+
"""
55+
Structure to hold the JuMP constraints for the TulipaEnergyModel
56+
"""
5457
mutable struct TulipaConstraint
5558
indices::DataFrame
5659
table_name::String
@@ -311,16 +314,18 @@ Structure to hold all parts of an energy problem. It is a wrapper around various
311314
It hides the complexity behind the energy problem, making the usage more friendly, although more verbose.
312315
313316
# Fields
317+
- `db_connection`: A DuckDB connection to the input tables in the model
314318
- `graph`: The Graph object that defines the geometry of the energy problem.
315-
- `representative_periods`: A vector of [Representative Periods](@ref representative-periods).
316-
- `constraints_partitions`: Dictionaries that connect pairs of asset and representative periods to [time partitions (vectors of time blocks)](@ref Partition)
317-
- `timeframe`: The number of periods of the `representative_periods`.
318-
- `dataframes`: The data frames used to linearize the variables and constraints. These are used internally in the model only.
319-
- `model_parameters`: The model parameters.
320319
- `model`: A JuMP.Model object representing the optimization model.
320+
- `objective_value`: The objective value of the solved problem (Float64).
321+
- `variables`: A [TulipaVariable](@ref TulipaVariable) structure to store all the information related to the variables in the model.
322+
- `constraints`: A [TulipaConstraint](@ref TulipaConstraint) structure to store all the information related to the constraints in the model.
323+
- `representative_periods`: A vector of [Representative Periods](@ref representative-periods).
321324
- `solved`: A boolean indicating whether the `model` has been solved or not.
322-
- `objective_value`: The objective value of the solved problem.
323325
- `termination_status`: The termination status of the optimization model.
326+
- `timeframe`: A structure with the number of periods in the `representative_periods` and the mapping between the periods and their representatives.
327+
- `model_parameters`: A [ModelParameters](@ref ModelParameters) structure to store all the parameters that are exclusive of the model.
328+
- `years`: A vector with the information of all the milestone years.
324329
325330
# Constructor
326331
- `EnergyProblem(connection)`: Constructs a new `EnergyProblem` object with the given connection. The `constraints_partitions` field is computed from the `representative_periods`, and the other fields are initialized with default values.

0 commit comments

Comments
 (0)