-
Notifications
You must be signed in to change notification settings - Fork 19
Add minimum node state constraint #1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bc6018c
Add node_state_lower_limit parameter calculation
datejada 2419301
Update lower bound of node state variable
datejada d254aed
Add minimum node state constraint
datejada dcfa4d3
Add test
datejada 9127fe8
Update documentation
datejada cd0fbfb
Fix representative periods test with new constraint
datejada 1739c50
Fix codecov
datejada 19300d2
Add new parameter to template and examples
datejada ba99a28
Update node_state_lower_limit calculation
datejada 6f5fe1f
Update docstring
datejada 1dda716
Update tests
datejada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
############################################################################# | ||
# Copyright (C) 2017 - 2021 Spine project consortium | ||
# Copyright SpineOpt contributors | ||
# | ||
# This file is part of SpineOpt. | ||
# | ||
# SpineOpt is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# SpineOpt is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
############################################################################# | ||
|
||
@doc raw""" | ||
To ensure a minimum storage content, the $v_{node\_state}$ variable needs be constrained by the following equation: | ||
|
||
```math | ||
v^{node\_state}_{(n, s, t)} \geq \max(p^{node\_state\_cap}_{(n, s, t)} \cdot p^{node\_state\_min\_factor}_{(n, s, t)}, p^{node\_state\_min}_{(n, s, t)}) \quad \forall n \in node : p^{has\_state}_{(n)}, \, \forall (s,t) | ||
``` | ||
|
||
Please note that the limit represents the maximum of the two terms. | ||
The first term is the product of the storage capacity and the minimum factor, which is a per-unit value of the storage capacity. | ||
The second term is the minimum state, given in absolute values. | ||
|
||
See also | ||
[node\_state\_cap](@ref), | ||
[node\_state\_min](@ref), | ||
[node\_state\_min\_factor](@ref), | ||
[has\_state](@ref). | ||
""" | ||
function add_constraint_min_node_state!(m::Model) | ||
_add_constraint!( | ||
m, :min_node_state, constraint_min_node_state_indices, _build_constraint_min_node_state | ||
) | ||
end | ||
|
||
function _build_constraint_min_node_state(m::Model, ng, s_path, t) | ||
@fetch node_state, storages_invested_available = m.ext[:spineopt].variables | ||
@build_constraint( | ||
+ sum( | ||
+ node_state[n, s, t] | ||
for (n, s, t) in node_state_indices(m; node=ng, stochastic_scenario=s_path, t=t); | ||
init=0, | ||
) | ||
>= | ||
+ sum( | ||
+ node_state_lower_limit(m; node=ng, stochastic_scenario=s, t=t) | ||
* ( | ||
+ number_of_storages(m; node=ng, stochastic_scenario=s, t=t, _default=_default_nb_of_storages(n)) | ||
+ sum( | ||
storages_invested_available[n, s, t1] | ||
for (n, s, t1) in storages_invested_available_indices( | ||
m; node=ng, stochastic_scenario=s_path, t=t_in_t(m; t_short=t) | ||
); | ||
init=0, | ||
) | ||
) | ||
for (n, s, t) in node_state_indices(m; node=ng, stochastic_scenario=s_path, t=t); | ||
init=0, | ||
) | ||
) | ||
end | ||
|
||
function constraint_min_node_state_indices(m::Model) | ||
( | ||
(node=ng, stochastic_path=path, t=t) | ||
for (ng, t) in node_time_indices( | ||
m; node=intersect(indices(node_state_cap), indices(candidate_storages)), temporal_block=anything | ||
) | ||
if (has_state(node=ng) && is_longterm_storage(node=ng)) || _is_representative(t) | ||
for path in active_stochastic_paths( | ||
m, | ||
Iterators.flatten( | ||
( | ||
node_state_indices(m; node=ng, t=t), | ||
storages_invested_available_indices(m; node=ng, t=t_in_t(m; t_short=t)), | ||
) | ||
) | ||
) | ||
) | ||
end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.