Skip to content
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

Feature/ant 958 #12

Merged
merged 24 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7c8a540
See #ANT-958 Create model/common.py and refactor ValueType
ianmnz Jan 23, 2024
900c776
See #ANT-958 Add ProblemContext to Par, Var and Constraint
ianmnz Jan 24, 2024
b678875
See #ANT-958 Add ProblemType to build_problem
ianmnz Jan 31, 2024
9995811
See #ANT-958 Add ExportModel to tests
ianmnz Feb 1, 2024
5464f5d
See #ANT-958 Add Export MPS function for Xpansion's Bender
ianmnz Feb 1, 2024
87122d1
See #ANT-958 Set verbose name to variables and constraints
ianmnz Feb 8, 2024
e7aeb39
See #ANT-958 Add cluster_candidate to test
ianmnz Feb 8, 2024
12790b0
See #ANT-958 Fixed after merge
ianmnz Feb 12, 2024
435eee4
See #ANT-958 Avoid string parsing for structure.txt
ianmnz Feb 13, 2024
0af3cd8
See #ANT-958 Rename serialize function
ianmnz Feb 14, 2024
2997ee7
See #ANT-958 Separate optimization.py from xpansion.py
ianmnz Feb 14, 2024
98acf35
See #ANT-958 Add node_with_spillage_and_ens to standard models
ianmnz Feb 15, 2024
a56a4b1
See #ANT-958 Split Xpansion test into two
ianmnz Feb 15, 2024
b4ac1e6
See #ANT-958 To avoid CI errors when ./bender is not found
ianmnz Feb 15, 2024
b30b673
Merge branch 'main' into feature/ANT-958
ianmnz Feb 16, 2024
3d6990c
See #ANT-958 Fixes after PR review
ianmnz Feb 19, 2024
add3654
See #ANT-958 Add Coupling context for variables
ianmnz Feb 20, 2024
eb7a727
See #ANT-958 String fix after review
ianmnz Feb 21, 2024
ed94844
See #ANT-958 Rename cluster candidate to better relate to real life
ianmnz Feb 22, 2024
85c62db
See #ANT-958 Fixes after review
ianmnz Feb 22, 2024
635f78d
See #ANT-958 Rename Xpansion to BendersDecomposed
ianmnz Feb 22, 2024
8ecaa3d
See #ANT-958 Implement ProblemStrategy interface
ianmnz Feb 22, 2024
2a26daa
See #ANT-958 Rename build_problem parameter for better understanding
ianmnz Feb 23, 2024
07fca4f
See #ANT-958 Move ModelSelectionStrategy to simulation directory
ianmnz Feb 26, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ venv
.env
.coverage
coverage.xml
bin
outputs
58 changes: 45 additions & 13 deletions src/andromede/libs/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@
],
)

NODE_WITH_SPILL_AND_ENS_MODEL = model(
id="NODE_WITH_SPILL_AND_ENS_MODEL",
parameters=[float_parameter("spillage_cost"), float_parameter("ens_cost")],
variables=[
float_variable("spillage", lower_bound=literal(0)),
float_variable("unsupplied_energy", lower_bound=literal(0)),
],
ports=[ModelPort(port_type=BALANCE_PORT_TYPE, port_name="balance_port")],
binding_constraints=[
Constraint(
name="Balance",
expression=port_field("balance_port", "flow").sum_connections()
== var("spillage") - var("unsupplied_energy"),
)
],
objective_operational_contribution=(
param("spillage_cost") * var("spillage")
+ param("ens_cost") * var("unsupplied_energy")
)
.sum()
.expec(),
)
"""
A standard model for a linear cost generation, limited by a maximum generation.
"""
Expand All @@ -63,7 +85,9 @@
name="Max generation", expression=var("generation") <= param("p_max")
),
],
objective_contribution=(param("cost") * var("generation")).sum().expec(),
objective_operational_contribution=(param("cost") * var("generation"))
.sum()
.expec(),
)

"""
Expand Down Expand Up @@ -133,7 +157,9 @@
lower_bound=literal(0),
), # To test both ways of setting constraints
],
objective_contribution=(param("cost") * var("generation")).sum().expec(),
objective_operational_contribution=(param("cost") * var("generation"))
.sum()
.expec(),
)

# For now, no starting cost
Expand All @@ -159,17 +185,17 @@
"nb_on",
lower_bound=literal(0),
upper_bound=param("nb_units_max"),
structural_type=ANTICIPATIVE_TIME_VARYING,
structure=ANTICIPATIVE_TIME_VARYING,
),
int_variable(
"nb_stop",
lower_bound=literal(0),
structural_type=ANTICIPATIVE_TIME_VARYING,
structure=ANTICIPATIVE_TIME_VARYING,
),
int_variable(
"nb_start",
lower_bound=literal(0),
structural_type=ANTICIPATIVE_TIME_VARYING,
structure=ANTICIPATIVE_TIME_VARYING,
),
],
ports=[ModelPort(port_type=BALANCE_PORT_TYPE, port_name="balance_port")],
Expand Down Expand Up @@ -208,7 +234,9 @@
)
# It also works by writing ExpressionRange(-param("d_min_down") + 1, 0) as ExpressionRange's __post_init__ wraps integers to literal nodes. However, MyPy does not seem to infer that ExpressionRange's attributes are necessarily of ExpressionNode type and raises an error if the arguments in the constructor are integer (whereas it runs correctly), this why we specify it here with literal(0) instead of 0.
],
objective_contribution=(param("cost") * var("generation")).sum().expec(),
objective_operational_contribution=(param("cost") * var("generation"))
.sum()
.expec(),
)

# Same model as previous one, except that starting/stopping variables are now non anticipative
Expand All @@ -234,17 +262,17 @@
"nb_on",
lower_bound=literal(0),
upper_bound=param("nb_units_max"),
structural_type=NON_ANTICIPATIVE_TIME_VARYING,
structure=NON_ANTICIPATIVE_TIME_VARYING,
),
int_variable(
"nb_stop",
lower_bound=literal(0),
structural_type=NON_ANTICIPATIVE_TIME_VARYING,
structure=NON_ANTICIPATIVE_TIME_VARYING,
),
int_variable(
"nb_start",
lower_bound=literal(0),
structural_type=NON_ANTICIPATIVE_TIME_VARYING,
structure=NON_ANTICIPATIVE_TIME_VARYING,
),
],
ports=[ModelPort(port_type=BALANCE_PORT_TYPE, port_name="balance_port")],
Expand Down Expand Up @@ -282,7 +310,9 @@
<= param("nb_units_max").shift(-param("d_min_down")) - var("nb_on"),
),
],
objective_contribution=(param("cost") * var("generation")).sum().expec(),
objective_operational_contribution=(param("cost") * var("generation"))
.sum()
.expec(),
)

SPILLAGE_MODEL = model(
Expand All @@ -296,7 +326,7 @@
definition=-var("spillage"),
)
],
objective_contribution=(param("cost") * var("spillage")).sum().expec(),
objective_operational_contribution=(param("cost") * var("spillage")).sum().expec(),
)

UNSUPPLIED_ENERGY_MODEL = model(
Expand All @@ -310,7 +340,9 @@
definition=var("unsupplied_energy"),
)
],
objective_contribution=(param("cost") * var("unsupplied_energy")).sum().expec(),
objective_operational_contribution=(param("cost") * var("unsupplied_energy"))
.sum()
.expec(),
)

# Simplified model
Expand Down Expand Up @@ -357,5 +389,5 @@
== param("inflows"),
),
],
objective_contribution=literal(0), # Implcitement nul ?
objective_operational_contribution=literal(0), # Implcitement nul ?
)
15 changes: 12 additions & 3 deletions src/andromede/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
#
# This file is part of the Antares project.

from .common import ProblemContext, ValueType
from .constraint import Constraint
from .model import Model, ModelPort, model
from .parameter import Parameter, ParameterValueType, float_parameter, int_parameter
from .model import (
InvestmentProblemStrategy,
MergedProblemStrategy,
Model,
ModelPort,
ModelSelectionStrategy,
OperationalProblemStrategy,
model,
)
from .parameter import Parameter, float_parameter, int_parameter
from .port import PortField, PortType
from .variable import Variable, VariableValueType, float_variable, int_variable
from .variable import Variable, float_variable, int_variable
28 changes: 28 additions & 0 deletions src/andromede/model/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

"""
Module for common classes used in models.
"""
from enum import Enum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add open source header !



class ValueType(Enum):
FLOAT = "FLOAT"
INTEGER = "INTEGER"
# Needs more ?


class ProblemContext(Enum):
OPERATIONAL = 0
INVESTMENT = 1
COUPLING = 2
5 changes: 5 additions & 0 deletions src/andromede/model/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
literal,
)
from andromede.expression.print import print_expr
from andromede.model.common import ProblemContext


class Constraint:
Expand All @@ -33,15 +34,19 @@ class Constraint:
expression: ExpressionNode
lower_bound: ExpressionNode
upper_bound: ExpressionNode
context: ProblemContext

def __init__(
self,
name: str,
expression: ExpressionNode,
lower_bound: Optional[ExpressionNode] = None,
upper_bound: Optional[ExpressionNode] = None,
context: ProblemContext = ProblemContext.OPERATIONAL,
) -> None:
self.name = name
self.context = context

if isinstance(expression, ComparisonNode):
if lower_bound is not None or upper_bound is not None:
raise ValueError(
Expand Down
Loading
Loading