Skip to content

Commit

Permalink
Change capacity constraints to be defined in the lowest resolution (#322
Browse files Browse the repository at this point in the history
)
  • Loading branch information
datejada committed Dec 5, 2023
1 parent 53e0245 commit 3e91b75
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 116 deletions.
2 changes: 1 addition & 1 deletion docs/src/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The fields of `EnergyProblem` are

* `graph`: The [Graph](@ref) object that defines the geometry of the energy problem.
* `representative_periods`: A vector of [Representative Periods](@ref representative-periods).
* `constraints_partitions`: A dictionary that connects pairs of asset and representative periods to [time partitions (vectors of time blocks)](@ref Partition)
* `constraints_partitions`: Dictionaries that connects pairs of asset and representative periods to [time partitions (vectors of time blocks)](@ref Partition)
* `model`: A JuMP model object. Initially `nothing`.
* `solved`: A boolean indicating whether the `model` has been solved or not.
* `objective_value`: After the model has been solved, this is the objective value at the solution.
Expand Down
35 changes: 13 additions & 22 deletions docs/src/mathematical-formulation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# [Mathematical Formulation](@id math-formulation)

This section shows the mathematical formulation of the model.\
The full mathematical formulation is also freely available in the [preprint](https://arxiv.org/abs/2309.07711).
This section shows the mathematical formulation of the model assuming that the temporal definition of time steps is the same for all the elements in the model.\
The full mathematical formulation considering variable temporal resolutions is also freely available in the [preprint](https://arxiv.org/abs/2309.07711).

## [Sets](@id math-sets)

Expand Down Expand Up @@ -85,7 +85,7 @@ flows\_variable\_cost &= \sum_{f \in \mathcal{F}} \sum_{rp \in \mathcal{RP}} \su

```math
\begin{aligned}
\sum_{f \in \mathcal{F}_{in}(a)} v^{flow}_{f,rp,k} - \sum_{f \in \mathcal{F}_{out}(a)} v^{flow}_{f,rp,k} \left\{\begin{array}{l} = \\ \geqslant \\ \leqslant \end{array}\right\} p^{profile}_{a,rp,k} \cdot p^{peak\_demand}_{a} \quad
\sum_{f \in \mathcal{F}_{in}(a)} v^{flow}_{f,rp,k} - \sum_{f \in \mathcal{F}_{out}(a)} v^{flow}_{f,rp,k} = p^{profile}_{a,rp,k} \cdot p^{peak\_demand}_{a} \quad
\\ \\ \forall a \in \mathcal{A}_c, \forall rp \in \mathcal{RP},\forall k \in \mathcal{K}
\end{aligned}
```
Expand All @@ -94,7 +94,7 @@ flows\_variable\_cost &= \sum_{f \in \mathcal{F}} \sum_{rp \in \mathcal{RP}} \su

```math
\begin{aligned}
s_{a,rp,k}^{level} = s_{a,rp,k-1}^{level} + p_{a,rp,k}^{inflow} + \cdot \sum_{f \in \mathcal{F}_{in}(a)} p^{eff}_f \cdot v^{flow}_{f,rp,k} - \sum_{f \in \mathcal{F}_{out}(a)} \frac{1}{p^{eff}_f} \cdot v^{flow}_{f,rp,k} \quad
s_{a,rp,k}^{level} = s_{a,rp,k-1}^{level} + p_{a,rp,k}^{inflow} + \sum_{f \in \mathcal{F}_{in}(a)} p^{eff}_f \cdot v^{flow}_{f,rp,k} - \sum_{f \in \mathcal{F}_{out}(a)} \frac{1}{p^{eff}_f} \cdot v^{flow}_{f,rp,k} \quad
\\ \\ \forall a \in \mathcal{A}_s, \forall rp \in \mathcal{RP},\forall k \in \mathcal{K}
\end{aligned}
```
Expand All @@ -117,9 +117,9 @@ s_{a,rp,k}^{level} = s_{a,rp,k-1}^{level} + p_{a,rp,k}^{inflow} + \cdot \sum_{f
\end{aligned}
```

### Constraints that Define Bounds of Flows Related to Energy Assets $\mathcal{A}$
### Constraints that Define Capacity Limits of Flows Related to Energy Assets $\mathcal{A}$

#### Contraint for the Overall Output Flows from an Asset
#### Maximum Output Flows Limit

```math
\begin{aligned}
Expand All @@ -128,7 +128,7 @@ s_{a,rp,k}^{level} = s_{a,rp,k-1}^{level} + p_{a,rp,k}^{inflow} + \cdot \sum_{f
\end{aligned}
```

#### Contraint for the Overall Input Flows from an Asset
#### Maximum Input Flows Limit

```math
\begin{aligned}
Expand All @@ -137,24 +137,15 @@ s_{a,rp,k}^{level} = s_{a,rp,k-1}^{level} + p_{a,rp,k}^{inflow} + \cdot \sum_{f
\end{aligned}
```

#### Upper Bound Constraint for Associated with Asset

```math
\begin{aligned}
v^{flow}_{f,rp,k} \leq p^{profile}_{a,rp,k} \cdot \left(p^{init\_capacity}_{a} + p^{unit\_capacity}_a \cdot v^{investment}_a \right) \quad \\ \\ \forall a \notin \mathcal{A}_h \cup \mathcal{A}_c,
\forall f \in \mathcal{F}_{out}(a) \& \notin \mathcal{F}_t, \forall rp \in \mathcal{RP},\forall k \in \mathcal{K}
\end{aligned}
```

#### Lower Bound Constraint Flows Associated with Asset

```math
v^{flow}_{f,rp,k} \geq 0 \quad \forall f \notin \mathcal{F}_t, \forall rp \in \mathcal{RP}, \forall k \in \mathcal{k}
```

### Constraints that Define Bounds for a Transport Flow $\mathcal{F}_t$
### Constraints that Define Capacity Limits for a Transport Flow $\mathcal{F}_t$

#### Upper Bound Constraint for Transport Flows
#### Maximum Transport Flow Limit

```math
\begin{aligned}
Expand All @@ -163,7 +154,7 @@ v^{flow}_{f,rp,k} \leq p^{profile}_{f,rp,k} \cdot \left(p^{init\_capacity}_{f} +
\end{aligned}
```

#### Lower Bound Constraint for Transport Flows
#### Minimum Transport Flow Limit

```math
\begin{aligned}
Expand All @@ -174,7 +165,7 @@ v^{flow}_{f,rp,k} \geq p^{profile}_{f,rp,k} \cdot \left(p^{init\_capacity}_{f} +

### Extra Constraints for Energy Storage Assets $\mathcal{A}_s$

#### Upper and Lower Bound Constraints for Storage Level
#### Maximum Storage Level Limit

```math
0 \leq s_{a,rp,k}^{level} \leq p^{init\_storage\_capacity}_{a} + p^{ene\_to\_pow\_ratio}_a \cdot p^{unit\_capacity}_a \cdot v^{investment}_a \quad
Expand All @@ -190,14 +181,14 @@ s_{a,rp,k=K}^{level} \geq p^{init\_storage\_level}_{a} \quad

### Extra Constraints for Investments

#### Upper Bound for $\mathcal{A}_i$
#### Maximum Investment Limit for $\mathcal{A}_i$

```math
v^{investment}_a \leq \frac{p^{investment\_limit}_a}{ p^{unit\_capacity}_a} \quad
\\ \\ \forall a \in \mathcal{A}_i
```

#### Upper Bound for $\mathcal{F}_i$
#### Maximum Investment Limit for $\mathcal{F}_i$

```math
v^{investment}_f \leq \frac{p^{investment\_limit}_f}{\max\{p^{export\_capacity}_f,p^{import\_capacity}_f\}} \quad
Expand Down
13 changes: 9 additions & 4 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Creating an energy problem automatically computes this data, but since we are do
constraints_partitions = compute_constraints_partitions(graph, representative_periods)
```

The `constraints_partitions` has two dictionaries with the keys `:lowest_resolution` and `:highest_resolution`. The lowest resolution dictionary is mainly used to create the constraints for energy balance, whereas the highest resolution dictionary is mainly used to create the capacity constraints in the model.

Now we can compute the model.

```@example manual
Expand Down Expand Up @@ -223,10 +225,13 @@ To create a vector with the all values of `storage_level` for a given `a` and `r
```@example solution
a = first(labels(graph))
rp = 1
cons_parts = energy_problem.constraints_partitions
cons_parts = energy_problem.constraints_partitions[:lowest_resolution]
[solution.storage_level[a, rp, B] for B in cons_parts[(a, rp)]]
```

> **Note**
> Make sure to specify `constraints_partitions[:lowest_resolution]` since the storage level is determined in the energy balance constraint for the storage assets. This constraint is defined in the lowest resolution of all assets and flows involved.
### The solution inside the graph

In addition to the solution object, the solution is also stored by the individual assets and flows when [`solve_model!`](@ref) is called - i.e., when using a [EnergyProblem](@ref) object.
Expand All @@ -252,20 +257,20 @@ To create a vector with the all values of `storage_level` for a given `a` and `r
```@example solution
a = first(labels(graph))
rp = 1
cons_parts = energy_problem.constraints_partitions
cons_parts = energy_problem.constraints_partitions[:lowest_resolution]
[energy_problem.graph[a].storage_level[(rp, B)] for B in cons_parts[(a, rp)]]
```

### Values of constraints and expressions

By accessing the model directly, we can query the values of constraints and expresions.
For instance, we can get all incoming flow for a given asset at a given time block for a given representative periods with the following:
For instance, we can get all incoming flow in the lowest resolution for a given asset at a given time block for a given representative periods with the following:

```@example solution
using JuMP
# a, rp, and cons_parts are defined above
B = cons_parts[(a, rp)][1]
value(energy_problem.model[:incoming_flow][a, rp, B])
value(energy_problem.model[:incoming_flow_lowest_resolution][a, rp, B])
```

The same can happen for constraints.
Expand Down
Loading

0 comments on commit 3e91b75

Please sign in to comment.