Skip to content

Commit

Permalink
fix taking in account the comments on the pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann-Temudjin committed Mar 4, 2024
1 parent 927cc47 commit 18a4b1f
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 249 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pet-mit
sylvlecl
tbittar
vargastat
Yann-Temudjin
126 changes: 79 additions & 47 deletions src/andromede/libs/standard_sc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

from andromede.expression import literal, param, var
from andromede.expression.expression import port_field
from andromede.libs.standard import CONSTANT, TIME_AND_SCENARIO_FREE
from andromede.libs.standard import BALANCE_PORT_TYPE, CONSTANT, TIME_AND_SCENARIO_FREE
from andromede.model import (
Constraint,
ModelPort,
Expand All @@ -12,41 +24,6 @@
)
from andromede.model.model import PortFieldDefinition, PortFieldId

"""
Flow port
"""
FLOW_PORT = PortType(id="flow_port", fields=[PortField("flow")])

"""
Simple node that manage flow interconnections.
"""
NODE_MODEL = model(
id="Noeud",
ports=[ModelPort(port_type=FLOW_PORT, port_name="FlowN")],
binding_constraints=[
Constraint(
name="Balance",
expression=port_field("FlowN", "flow").sum_connections() == literal(0),
)
],
)

"""
Basic consumption model.
It consume a fixed amount of energy "d" each hour.
"""
DEMAND_MODEL = model(
id="Energy Demand model",
parameters=[float_parameter("demand", CONSTANT)],
ports=[ModelPort(port_type=FLOW_PORT, port_name="FlowD")],
port_fields_definitions=[
PortFieldDefinition(
port_field=PortFieldId("FlowD", "flow"),
definition=-param("demand"),
)
],
)

"""
Model of a power generator.
The power production p is bounded between p_min and p_max.
Expand All @@ -58,7 +35,7 @@
variables=[
float_variable("prod", lower_bound=literal(0), upper_bound=param("p_max"))
],
ports=[ModelPort(port_type=FLOW_PORT, port_name="FlowP")],
ports=[ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowP")],
port_fields_definitions=[
PortFieldDefinition(
port_field=PortFieldId("FlowP", "flow"),
Expand All @@ -79,8 +56,8 @@
float_variable("output"),
],
ports=[
ModelPort(port_type=FLOW_PORT, port_name="FlowDI"),
ModelPort(port_type=FLOW_PORT, port_name="FlowDO"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDI"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDO"),
],
port_fields_definitions=[
PortFieldDefinition(
Expand Down Expand Up @@ -112,9 +89,9 @@
float_variable("output"),
],
ports=[
ModelPort(port_type=FLOW_PORT, port_name="FlowDI1"),
ModelPort(port_type=FLOW_PORT, port_name="FlowDI2"),
ModelPort(port_type=FLOW_PORT, port_name="FlowDO"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDI1"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDI2"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDO"),
],
port_fields_definitions=[
PortFieldDefinition(
Expand Down Expand Up @@ -147,9 +124,9 @@
float_variable("output"),
],
ports=[
ModelPort(port_type=FLOW_PORT, port_name="FlowDI1"),
ModelPort(port_type=FLOW_PORT, port_name="FlowDI2"),
ModelPort(port_type=FLOW_PORT, port_name="FlowDO"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDI1"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDI2"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDO"),
],
port_fields_definitions=[
PortFieldDefinition(
Expand Down Expand Up @@ -179,8 +156,8 @@
float_variable("input", lower_bound=literal(0)),
],
ports=[
ModelPort(port_type=FLOW_PORT, port_name="FlowDI"),
ModelPort(port_type=FLOW_PORT, port_name="FlowDO"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDI"),
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowDO"),
],
port_fields_definitions=[
PortFieldDefinition(
Expand All @@ -195,3 +172,58 @@
)
],
)

"""
CO² emmission port
"""
EMISSION_PORT = PortType(id="emission_port", fields=[PortField("Q")])

"""
Model of a simple power generator that takes account of CO² emissions related to the production.
The power production p is bounded between p_min and p_max.
An emission factor is used to determine the CO² emission according to the production.
"""
C02_POWER_MODEL = model(
id="CO2 power",
parameters=[
float_parameter("p_min", CONSTANT),
float_parameter("p_max", CONSTANT),
float_parameter("cost", CONSTANT),
float_parameter("emission_rate", CONSTANT),
],
variables=[
float_variable("p", lower_bound=param("p_min"), upper_bound=param("p_max"))
],
ports=[
ModelPort(port_type=BALANCE_PORT_TYPE, port_name="FlowP"),
ModelPort(port_type=EMISSION_PORT, port_name="OutCO2"),
],
port_fields_definitions=[
PortFieldDefinition(
port_field=PortFieldId("FlowP", "flow"),
definition=var("p"),
),
PortFieldDefinition(
port_field=PortFieldId("OutCO2", "Q"),
definition=var("p") * param("emission_rate"),
),
],
objective_operational_contribution=(param("cost") * var("p")).sum().expec(),
)

"""
Model of the CO² quota.
It takes a set a CO² emissions as input. It forces the sum of those emissions to be smaller than a predefined quota.
"""
QUOTA_CO2_MODEL = model(
id="QuotaCO2",
parameters=[float_parameter("quota", CONSTANT)],
ports=[ModelPort(port_type=EMISSION_PORT, port_name="emissionCO2")],
binding_constraints=[
Constraint(
name="Bound CO2",
expression=port_field("emissionCO2", "Q").sum_connections()
<= param("quota"),
)
],
)
Loading

0 comments on commit 18a4b1f

Please sign in to comment.