Skip to content

odys.optimization.formulations

Model formulations, one per entity type. A Formulation owns, for every entity of its type: the parameter arrays, the decision variables, the constraints, the net power it injects into the power balance and its profit per scenario. FORMULATIONS lists every entity type's formulation, in build and power-balance order.

Modules

  • base
  • charging
  • commitment
  • electric_vehicle
  • energy_market
  • fixed_load
  • flexible_load
  • generator
  • battery_storage
  • storage

Model formulations, one per entity type.

FORMULATIONS = (GeneratorFormulation, EnergyMarketFormulation, FixedLoadFormulation, FlexibleLoadFormulation, BatteryStorageFormulation, ElectricVehicleFormulation, ChargingFormulation) module-attribute

Every entity type's formulation, in build and power-balance order (charging after electric vehicles).

The only per-type list in the model layer.

validate_entities_supported(entities)

Validate that a formulation models every entity's type.

A bare Asset or a user-defined Asset subclass would otherwise be accepted and then silently left out of the model.

Parameters:

Name Type Description Default
entities Sequence[EnergyEntity]

Every asset and market of the system.

required

Raises:

Type Description
OdysValidationError

If no formulation models an entity's type.

Source code in src/odys/optimization/formulations/__init__.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def validate_entities_supported(entities: Sequence[EnergyEntity]) -> None:
    """Validate that a formulation models every entity's type.

    A bare `Asset` or a user-defined `Asset` subclass would otherwise be
    accepted and then silently left out of the model.

    Args:
        entities: Every asset and market of the system.

    Raises:
        OdysValidationError: If no formulation models an entity's type.

    """
    supported = tuple(formulation_type.entity_type for formulation_type in FORMULATIONS)
    for entity in entities:
        if not isinstance(entity, supported):
            names = ", ".join(entity_type.__name__ for entity_type in supported)
            msg = (
                f"Asset type {type(entity).__name__} is not supported by the optimizer: '{entity.name}'. "
                f"Supported types: {names}."
            )
            raise OdysValidationError(msg)