Skip to content

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 11 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/mathematical_formulation/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

@@add_constraint_node_state_capacity!

### [Minimum node state](@id min_node_state)

@@add_constraint_min_node_state!

### [Cyclic condition on node state variable](@id constraint_cyclic_node_state)

@@add_constraint_cyclic_node_state!
Expand Down
9 changes: 8 additions & 1 deletion examples/6_unit_system.json
Original file line number Diff line number Diff line change
Expand Up @@ -82929,7 +82929,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
9 changes: 8 additions & 1 deletion examples/capacity_planning.json
Original file line number Diff line number Diff line change
Expand Up @@ -3161,7 +3161,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3150,7 +3150,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3078,7 +3078,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
9 changes: 8 additions & 1 deletion examples/multi-year_investment_without_econ_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
9 changes: 8 additions & 1 deletion examples/reserves.json
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
19 changes: 13 additions & 6 deletions examples/rolling_horizon.json
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down Expand Up @@ -4809,17 +4816,17 @@
[
"node",
"electricity_node",
"node_state_cap",
100,
"node_availability_factor",
1,
"Base"
],
[
"node",
"electricity_node",
"node_availability_factor",
1,
"node_state_cap",
100,
"Base"
],
],
[
"node",
"electricity_node",
Expand Down
9 changes: 8 additions & 1 deletion examples/simple_system.json
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
9 changes: 8 additions & 1 deletion examples/stochastic.json
Original file line number Diff line number Diff line change
Expand Up @@ -3071,7 +3071,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
9 changes: 8 additions & 1 deletion examples/unit_commitment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,14 @@
"node_state_min",
0,
null,
"The minimum permitted value for a `node_state` variable."
"The minimum permitted absolute value for a `node_state` variable."
],
[
"node",
"node_state_min_factor",
0,
null,
"The minimum permitted per unit value for a `node_state` variable."
],
[
"node",
Expand Down
1 change: 1 addition & 0 deletions src/SpineOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ include("constraints/constraint_max_node_voltage_angle.jl")
include("constraints/constraint_min_capacity_margin.jl")
include("constraints/constraint_min_down_time.jl")
include("constraints/constraint_min_node_pressure.jl")
include("constraints/constraint_min_node_state.jl")
include("constraints/constraint_min_node_voltage_angle.jl")
include("constraints/constraint_min_scheduled_outage_duration.jl")
include("constraints/constraint_min_up_time.jl")
Expand Down
88 changes: 88 additions & 0 deletions src/constraints/constraint_min_node_state.jl
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
17 changes: 17 additions & 0 deletions src/data_structure/preprocess_data_structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function preprocess_data_structure()
generate_unit_flow_capacity()
generate_connection_flow_capacity()
generate_node_state_capacity()
generate_node_state_lower_limit()
generate_unit_commitment_parameters()
end

Expand Down Expand Up @@ -859,6 +860,22 @@ function generate_node_state_capacity()
end
end

function generate_node_state_lower_limit()
function _node_state_lower_limit(f; node=node, _default=nothing, kwargs...)
maximum([_prod_or_nothing(
f(node_state_cap; node=node, _default=_default, kwargs...),
f(node_state_min_factor; node=node, kwargs...)),
f(node_state_min; node=node, kwargs...)]
)
end

node_state_lower_limit = ParameterFunction(_node_state_lower_limit)
@eval begin
node_state_lower_limit = $node_state_lower_limit
export node_state_lower_limit
end
end

_prod_or_nothing(args...) = _prod_or_nothing(collect(args))
_prod_or_nothing(args::Vector) = any(isnothing.(args)) ? nothing : *(args...)
_prod_or_nothing(args::Vector{T}) where T<:Call = Call(_prod_or_nothing, args)
Expand Down
1 change: 1 addition & 0 deletions src/run_spineopt_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ function _add_constraints!(m; log_level=3)
add_constraint_nodal_balance!,
add_constraint_node_injection!,
add_constraint_node_state_capacity!,
add_constraint_min_node_state!,
add_constraint_node_voltage_angle!,
add_constraint_non_spinning_reserves_lower_bound!,
add_constraint_non_spinning_reserves_shut_down_upper_bound!,
Expand Down
8 changes: 7 additions & 1 deletion src/variables/variable_node_state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function node_state_indices(m::Model; node=anything, stochastic_scenario=anythin
)
end

function node_state_lb(m; node, kwargs...)
node_state_lower_limit(m; node=node, kwargs..., _default=NaN) * (
+ number_of_storages(m; node=node, kwargs..., _default=_default_nb_of_storages(node))
)
end

function node_state_ub(m; node, kwargs...)
node_state_capacity(m; node=node, kwargs..., _default=NaN) * (
+ number_of_storages(m; node=node, kwargs..., _default=_default_nb_of_storages(node))
Expand All @@ -52,7 +58,7 @@ function add_variable_node_state!(m::Model)
m,
:node_state,
node_state_indices;
lb=node_state_min,
lb=node_state_lb,
ub=node_state_ub,
fix_value=fix_node_state,
initial_value=initial_node_state,
Expand Down
3 changes: 2 additions & 1 deletion templates/spineopt_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@
["node", "node_slack_penalty", null, null, "A penalty cost for `node_slack_pos` and `node_slack_neg` variables. The slack variables won't be included in the model unless there's a cost defined for them."],
["node", "node_state_cap", null, null, "The maximum permitted value for a `node_state` variable."],
["node", "node_availability_factor", 1.0, null, "Availability of the `node`, acting as a multiplier on its `node_state_cap`. Typically between 0-1."],
["node", "node_state_min", 0.0, null, "The minimum permitted value for a `node_state` variable."],
["node", "node_state_min", 0.0, null, "The minimum permitted absolute value for a `node_state` variable."],
["node", "node_state_min_factor", 0.0, null, "The minimum permitted per unit value for a `node_state` variable."],
["node", "number_of_storages", 1.0, null, "Denotes the number of 'sub storages' aggregated to form the modelled `node`."],
["node", "state_coeff", 1.0, null, "Represents the `commodity` content of a `node_state` variable in respect to the `unit_flow` and `connection_flow` variables. Essentially, acts as a coefficient on the `node_state` variable in the `node_injection` constraint."],
["node", "storage_lead_time", {"type": "duration", "data": "0h"}, null, "A storage's lead time, i.e., the time between the moment at which a storage investment decision is takien, and the moment at which the storage investment becomes operational."],
Expand Down
Loading
Loading