-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Stefan Pfenninger <stefan@pfenninger.org>
- Loading branch information
1 parent
39cb0e1
commit 52bb659
Showing
4 changed files
with
145 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
# Shadow prices | ||
|
||
In a linear problem, you can obtain the shadow prices (dual variables) for each constraint from the Pyomo backend. | ||
In a linear problem, you can obtain the [shadow prices](https://en.wikipedia.org/wiki/Shadow_price) (dual variables) for each constraint from the Pyomo backend. | ||
This can prove particularly useful if you are linking Calliope with other models or want to dig deeper into the economic impacts of your designed energy system. | ||
|
||
Currently, the only way to do so is by running Calliope in Python, and not through the command-line interface. | ||
You can access shadow prices for any constraint by running once you have an optimal solution by running `model.backend.shadow_prices.get("constraint_name")`, which returns an [xarray.DataArray][]. | ||
|
||
You need to enable the tracking of shadow prices after the model is built and before it is solved by running `model.backend.shadow_prices.activate()`: | ||
!!! example | ||
|
||
```python | ||
```python | ||
model = calliope.examples.national_scale() | ||
model.build() | ||
model.backend.shadow_prices.activate() # (1)! | ||
model.solve() | ||
|
||
model = calliope.examples.national_scale() | ||
model.build() | ||
model.backend.shadow_prices.activate() | ||
model.solve() | ||
``` | ||
balance_price = model.backend.shadow_prices.get("system_balance").to_series() | ||
``` | ||
|
||
Then, after solving the model successfully, you can get the shadow price(s) for any constraint by running `model.backend.shadow_prices.get("constraint_name")`, which returns a `pandas.DataFrame`. For example, to get the shadow prices of the system_balance constraint indexed over nodes, carriers and timesteps: | ||
1. With the Pyomo backend interface, tracking shadow prices can be memory-intensive. | ||
Therefore, you must actively activate tracking before solving your model. | ||
|
||
```python | ||
balance_price = model.backend.shadow_prices.get("system_balance").to_series() | ||
``` | ||
!!! note | ||
|
||
* Not all solvers provide an API to access duals. | ||
For instance, we know it is not possible with the CBC solver. | ||
* You cannot access shadow prices if you have integer/binary variables in your model. | ||
If you try to do so, you will receive a None/NaN-filled array. | ||
* You can check the status of shadow price tracking with `model.backend.shadow_prices.is_active`. | ||
* Currently, the only way to access shadow prices is by running Calliope in Python, and not through the command-line interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.