Skip to content

binding_constraint

Classes:

BindingConstraint

BindingConstraint(
    bc_id: str,
    name: str,
    binding_constraint_service: BaseBindingConstraintService,
    properties: Optional[BindingConstraintProperties] = None,
    terms: Optional[list[ConstraintTerm]] = None,
)

Define generic constraints (binding constraints) between transmission flows and/or power generated from thermal clusters.

Methods:

Attributes:

Source code in src/antares/craft/model/binding_constraint.py
def __init__(
    self,
    bc_id: str,
    name: str,
    binding_constraint_service: BaseBindingConstraintService,
    properties: Optional[BindingConstraintProperties] = None,
    terms: Optional[list[ConstraintTerm]] = None,
):
    self._name = name
    self._binding_constraint_service = binding_constraint_service
    self._id = bc_id
    self._properties = properties or BindingConstraintProperties()
    self._terms = {term.id: term for term in terms} if terms else {}

id property

id: str

ID of the constraint.

name property

name: str

Name of the constraint.

properties property

Binding constraints properties

get_equal_term_matrix

get_equal_term_matrix() -> DataFrame

Get the "equal" (==) term matrix

Source code in src/antares/craft/model/binding_constraint.py
def get_equal_term_matrix(self) -> pd.DataFrame:
    """Get the "equal" (==) term matrix"""
    return self._binding_constraint_service.get_constraint_matrix(self, ConstraintMatrixName.EQUAL_TERM)

get_greater_term_matrix

get_greater_term_matrix() -> DataFrame

Get the "greater than" (>) term matrix

Source code in src/antares/craft/model/binding_constraint.py
def get_greater_term_matrix(self) -> pd.DataFrame:
    """Get the "greater than" (>) term matrix"""
    return self._binding_constraint_service.get_constraint_matrix(self, ConstraintMatrixName.GREATER_TERM)

get_less_term_matrix

get_less_term_matrix() -> DataFrame

Get the "less than" (<) term matrix

Source code in src/antares/craft/model/binding_constraint.py
def get_less_term_matrix(self) -> pd.DataFrame:
    """Get the "less than" (<) term matrix"""
    return self._binding_constraint_service.get_constraint_matrix(self, ConstraintMatrixName.LESS_TERM)

get_terms

get_terms() -> dict[str, ConstraintTerm]

Get the terms of this binding constraint.

Returns:

Source code in src/antares/craft/model/binding_constraint.py
def get_terms(self) -> dict[str, ConstraintTerm]:
    """Get the terms of this binding constraint.

    Returns:
        The constraint terms, as a mapping of term ID to term.
    """
    return self._terms

set_equal_term

set_equal_term(matrix: DataFrame) -> None

Set the "equal" (==) term matrix

Parameters:

  • matrix

    (DataFrame) –

    the matrix to upload.

Source code in src/antares/craft/model/binding_constraint.py
def set_equal_term(self, matrix: pd.DataFrame) -> None:
    """Set the "equal" (==) term matrix

    Args:
        matrix: the matrix to upload.
    """
    self._binding_constraint_service.set_constraint_matrix(self, ConstraintMatrixName.EQUAL_TERM, matrix)

set_greater_term

set_greater_term(matrix: DataFrame) -> None

Set the "greater than" (>) term matrix

Parameters:

  • matrix

    (DataFrame) –

    the matrix to upload.

Source code in src/antares/craft/model/binding_constraint.py
def set_greater_term(self, matrix: pd.DataFrame) -> None:
    """Set the "greater than" (>) term matrix

    Args:
        matrix: the matrix to upload.
    """
    self._binding_constraint_service.set_constraint_matrix(self, ConstraintMatrixName.GREATER_TERM, matrix)

set_less_term

set_less_term(matrix: DataFrame) -> None

Set the "less than" (<) term matrix

Parameters:

  • matrix

    (DataFrame) –

    the matrix to upload.

Source code in src/antares/craft/model/binding_constraint.py
def set_less_term(self, matrix: pd.DataFrame) -> None:
    """Set the "less than" (<) term matrix

    Args:
        matrix: the matrix to upload.
    """
    self._binding_constraint_service.set_constraint_matrix(self, ConstraintMatrixName.LESS_TERM, matrix)

set_terms

set_terms(terms: list[ConstraintTerm]) -> None

Replace all terms of this binding constraint.

Parameters:

Source code in src/antares/craft/model/binding_constraint.py
def set_terms(self, terms: list[ConstraintTerm]) -> None:
    """Replace all terms of this binding constraint.

    Args:
        terms: The new list of constraint terms to set.
    """
    self._binding_constraint_service.set_constraint_terms(self, terms)
    new_terms = {term.id: term for term in terms}
    self._terms = new_terms

update_properties

Update properties of the binding constraint.

Source code in src/antares/craft/model/binding_constraint.py
def update_properties(self, properties: BindingConstraintPropertiesUpdate) -> BindingConstraintProperties:
    """Update properties of the binding constraint."""
    new_properties = self._binding_constraint_service.update_binding_constraints_properties({self.id: properties})
    self._properties = new_properties[self.id]
    return self._properties

BindingConstraintFrequency

An enumeration representing the possible frequencies for binding constraints.

The values are case-insensitive, so "HOURLY", "hourly", or "Hourly" are all valid.

Attributes:

  • HOURLY

    Constraints are applied every hour.

  • DAILY

    Constraints are applied every day.

  • WEEKLY

    Constraints are applied every week.

BindingConstraintOperator

An enumeration representing the possible operators for binding constraints.

The values are case-insensitive, so "LESS", "less", or "Less" are all valid.

Attributes:

  • LESS

    Represents a "less than" (<) constraint.

  • GREATER

    Represents a "greater than" (>) constraint.

  • BOTH

    Represents a "both less than and greater than" constraint.

  • EQUAL

    Represents an "equal to" (==) constraint.

BindingConstraintProperties dataclass

BindingConstraintProperties(
    enabled: bool = True,
    time_step: BindingConstraintFrequency = HOURLY,
    operator: BindingConstraintOperator = LESS,
    comments: str = "",
    filter_year_by_year: set[FilterOption] = (lambda: FILTER_VALUES)(),
    filter_synthesis: set[FilterOption] = (lambda: FILTER_VALUES)(),
    group: str = "default",
)

Binding constraint properties

Attributes:

  • enabled (bool) –

    Whether or not the binding constraint is enabled for the simulation.

  • time_step (BindingConstraintFrequency) –

    Frequency at which the binding constraint is applied.

  • operator (BindingConstraintOperator) –

    Bound of the bounding constraint (<, >, == or < and >).

  • comments (str) –

    User comments on the constraint.

  • filter_year_by_year (set[FilterOption]) –

    Set of filter options for output (hourly, daily, weekly, monthly, annual).

  • filter_synthesis (set[FilterOption]) –

    Set of filter options for synthesis (hourly, daily, weekly, monthly, annual).

  • group (str) –

    User defined group to organize binding constraints

BindingConstraintPropertiesUpdate dataclass

BindingConstraintPropertiesUpdate(
    enabled: Optional[bool] = None,
    time_step: Optional[BindingConstraintFrequency] = None,
    operator: Optional[BindingConstraintOperator] = None,
    comments: Optional[str] = None,
    filter_year_by_year: Optional[set[FilterOption]] = None,
    filter_synthesis: Optional[set[FilterOption]] = None,
    group: Optional[str] = None,
)

Update binding constraint properties

Attributes:

ClusterData dataclass

ClusterData(area: str, cluster: str)

Data Transfer Object (DTO) for a constraint term on a cluster in an area.

Attributes:

  • area (str) –

    The area

  • cluster (str) –

    The cluster

ConstraintTerm dataclass

ConstraintTerm(data: LinkData | ClusterData, weight: float = 1, offset: int = 0)

Constraint terms

Attributes:

  • weigth

    The coefficient multiplying the link or cluster

  • offset (int) –

    The time offset of flow on the given link or output of the cluster. For example, it allows to make a constraint on a previous time-step.

Methods:

  • from_dict

    Create a LinkData or ClusterData object from a dictionary.

  • from_ini

    Creates a LinkData or ClusterData object from a string.

  • weight_offset

    Format the weight and offset values into a string representation.

id property

id: str

Generate a unique string identifier for the constraint term - For a link term type: "area1%area2" (sorted alphabetically and lowercase) - For a cluster term type: "area.cluster" (lowercase)

from_dict staticmethod

from_dict(input: dict[str, str]) -> LinkData | ClusterData

Create a LinkData or ClusterData object from a dictionary.

Parameters:

  • input

    (dict[str, str]) –

    A dictionary containing either "area1" and "area2" keys (for LinkData) or "area" and "cluster" keys (for ClusterData).

Returns:

  • LinkData | ClusterData

    LinkData | ClusterData: An instance of LinkData or ClusterData based on the input.

Raises:

  • ValueError

    If the dictionary does not contain the required keys.

Source code in src/antares/craft/model/binding_constraint.py
@staticmethod
def from_dict(input: dict[str, str]) -> LinkData | ClusterData:
    """Create a `LinkData` or `ClusterData` object from a dictionary.

    Args:
        input: A dictionary containing either "area1" and "area2" keys (for `LinkData`)
               or "area" and "cluster" keys (for `ClusterData`).

    Returns:
        LinkData | ClusterData: An instance of `LinkData` or `ClusterData` based on the input.

    Raises:
        ValueError: If the dictionary does not contain the required keys.
    """
    if "area1" in input:
        return LinkData(area1=input["area1"], area2=input["area2"])
    elif "cluster" in input:
        return ClusterData(area=input["area"], cluster=input["cluster"])
    raise ValueError(f"Dict {input} couldn't be serialized as a ConstraintTermData object")

from_ini staticmethod

from_ini(input: str) -> LinkData | ClusterData

Creates a LinkData or ClusterData object from a string.

Parameters:

  • input

    (str) –

    A string formatted as "area1%area2" (for LinkData) or "area.cluster" (for ClusterData).

Returns:

Raises:

  • ValueError

    If the string does not match the expected format.

Source code in src/antares/craft/model/binding_constraint.py
@staticmethod
def from_ini(input: str) -> LinkData | ClusterData:
    """Creates a `LinkData` or `ClusterData` object from a string.

    Args:
        input: A string formatted as "area1%area2" (for `LinkData`) or "area.cluster" (for `ClusterData`).

    Returns:
        An instance of `LinkData` or `ClusterData` based on the input.

    Raises:
        ValueError: If the string does not match the expected format.
    """
    if "%" in input:
        area_1, area_2 = input.split("%")
        return LinkData(area1=area_1, area2=area_2)
    elif "." in input:
        area, cluster = input.split(".")
        return ClusterData(area=area, cluster=cluster)
    raise ValueError(f"Input {input} couldn't be serialized as a ConstraintTermData object")

weight_offset

weight_offset() -> str

Format the weight and offset values into a string representation.

Source code in src/antares/craft/model/binding_constraint.py
def weight_offset(self) -> str:
    """Format the weight and offset values into a string representation."""
    return f"{self.weight}%{self.offset}" if self.offset != 0 else f"{self.weight}"

ConstraintTermData dataclass

ConstraintTermData(data: LinkData | ClusterData)

Constraint term in the left hand side of a binding constraint.

Attributes:

  • data (LinkData | ClusterData) –

    The underlying data, which can be either a LinkData or ClusterData object.

Methods:

  • from_dict

    Create a LinkData or ClusterData object from a dictionary.

  • from_ini

    Creates a LinkData or ClusterData object from a string.

id property

id: str

Generate a unique string identifier for the constraint term - For a link term type: "area1%area2" (sorted alphabetically and lowercase) - For a cluster term type: "area.cluster" (lowercase)

from_dict staticmethod

from_dict(input: dict[str, str]) -> LinkData | ClusterData

Create a LinkData or ClusterData object from a dictionary.

Parameters:

  • input

    (dict[str, str]) –

    A dictionary containing either "area1" and "area2" keys (for LinkData) or "area" and "cluster" keys (for ClusterData).

Returns:

  • LinkData | ClusterData

    LinkData | ClusterData: An instance of LinkData or ClusterData based on the input.

Raises:

  • ValueError

    If the dictionary does not contain the required keys.

Source code in src/antares/craft/model/binding_constraint.py
@staticmethod
def from_dict(input: dict[str, str]) -> LinkData | ClusterData:
    """Create a `LinkData` or `ClusterData` object from a dictionary.

    Args:
        input: A dictionary containing either "area1" and "area2" keys (for `LinkData`)
               or "area" and "cluster" keys (for `ClusterData`).

    Returns:
        LinkData | ClusterData: An instance of `LinkData` or `ClusterData` based on the input.

    Raises:
        ValueError: If the dictionary does not contain the required keys.
    """
    if "area1" in input:
        return LinkData(area1=input["area1"], area2=input["area2"])
    elif "cluster" in input:
        return ClusterData(area=input["area"], cluster=input["cluster"])
    raise ValueError(f"Dict {input} couldn't be serialized as a ConstraintTermData object")

from_ini staticmethod

from_ini(input: str) -> LinkData | ClusterData

Creates a LinkData or ClusterData object from a string.

Parameters:

  • input

    (str) –

    A string formatted as "area1%area2" (for LinkData) or "area.cluster" (for ClusterData).

Returns:

Raises:

  • ValueError

    If the string does not match the expected format.

Source code in src/antares/craft/model/binding_constraint.py
@staticmethod
def from_ini(input: str) -> LinkData | ClusterData:
    """Creates a `LinkData` or `ClusterData` object from a string.

    Args:
        input: A string formatted as "area1%area2" (for `LinkData`) or "area.cluster" (for `ClusterData`).

    Returns:
        An instance of `LinkData` or `ClusterData` based on the input.

    Raises:
        ValueError: If the string does not match the expected format.
    """
    if "%" in input:
        area_1, area_2 = input.split("%")
        return LinkData(area1=area_1, area2=area_2)
    elif "." in input:
        area, cluster = input.split(".")
        return ClusterData(area=area, cluster=cluster)
    raise ValueError(f"Input {input} couldn't be serialized as a ConstraintTermData object")

LinkData dataclass

LinkData(area1: str, area2: str)

Data Transfer Object (DTO) for a constraint term on a link between two areas.

Attributes:

  • area1 (str) –

    The first area

  • area2 (str) –

    The second area