apply power limit to gross imports/exports #123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before:


After:
Description
I learned a nice trick (for some of you this probably old news, but I didn't know it and I think it is very helpful):
In PyPSA-DE we want to limit the total capacity of power imports. A relatively straightforward way to attempt this is to define a constraint for every snapshot
t
:However,
"Line-s"
may be both positive and negative. Hence this limit will only apply to the net import. In other words: If the model would like to import more from France, it can do so if it exports a bit to Switzerland. (This can get pretty bad, sometimes we observe gross imports that are twice as big as the limit.)To avoid this behaviour, what you actually want to constrain are only the gross imports, i.e., positive parts of the flows,
However,
max
is a nonlinear function. Here I thought, it's impossible to achieve this in PyPSA-DE without converting all lines to links, or the LP to a MILP. But actually there is another way, and ChatGPT gave it away pretty quickly:For every incoming flow introduce an auxiliary variable,
then add the constraint
and voila, the
max
has been linearized and the constraint applies to the gross import.Before asking for a review for this PR make sure to complete the following checklist:
ariadne_all
completes without errorsexport_ariadne_variables
has been adapted to the changesChangelog.md
main
has been merged into the PRYYYYMMDDdescriptive_title