pycity_scheduling.classes.base package

Subpackages

Submodules

pycity_scheduling.classes.base.definition module

class pycity_scheduling.classes.base.definition.Definition(name: str, parent: Definition | None = None)

Bases: object

Base Class for all definition classes.

Parameters:
  • name (str) – Name of this Definition object.

  • parent (Optional[Definition]) – Parent to which this Definition belongs to.

name

Name used for child definition identification

parent

Immediate parent definition of this definition

parents

List of ancestor definitions that contain this definition from the top parent down

full_name

Full name used for definition identification and sympy symbol distinction

Attributes:
full_name
name
parent
parents
Parameters:

Methods

copy([parent, name])

Copies this definition to a new parent under a new name

symbols()

Yields:

sympy.core.symbol.Symbol -- Sympy Symbols that belong to this definition

copy(parent=None, name=None)

Copies this definition to a new parent under a new name

Parameters:
  • parent – Optional new Parent the copy of this definition should belong to.

  • name – Optional new name for the copy.

property full_name: str
property name: str
property parent: Definition
property parents: List[Definition]
symbols()
Yields:

sympy.core.symbol.Symbol – Sympy Symbols that belong to this definition

pycity_scheduling.classes.base.entity_container module

The pycity_scheduling framework

Copyright (C) 2022, Institute for Automation of Complex Power Systems (ACS), E.ON Energy Research Center (E.ON ERC), RWTH Aachen University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pycity_scheduling.classes.base.entity_container.EntityContainer(environment: Environment, subs: dict = {}, location=None, ts: TimeSampler | None = None, *args, **kwargs)

Bases: OptimizationEntity

Base class for entities containing other entities.

p_th and p_el imbalances are propagated to this entities variables. During calls to its scheduling functions, the contained entities are also called with the same parameters.

Notes

  • EntityContainers offer sets of constraints for operation. The following constraints are added.

\[\begin{split}p_{th\_cool} &=& \sum_i p_{th\_cool\_i} \\ p_{th\_heat} &=& \sum_i p_{th\_heat\_i} \\ p_{el} &=& \sum_i p_{el\_i}\end{split}\]
  • \(p_{th\_cool\_i}\), \(p_{th\_heat\_i}\), and \(p_{el\_i}\) are the variables from lower entities. The Bounds from TEC, TEH, and EE are removed.

Methods

get_lower_entities()

Yield all lower-level entities.

populate_model([mode])

Add entity block and lower entities blocks to pyomo ConcreteModel.

reset([schedule])

Reset all values of specified schedule.

update_model([mode])

Update block parameters and bounds.

update_schedule()

Update the schedule with the scheduling model solution.

Parameters:
get_lower_entities()

Yield all lower-level entities.

Yields:

All contained entities.

populate_model(mode='convex')

Add entity block and lower entities blocks to pyomo ConcreteModel.

Call both parent’s populate_model methods and set variables lower bounds to None. Then call populate_model method of all contained entities and add constraints that the sum of their variables for each period equals the corresponding own variable.

Parameters:
  • model (pyomo.ConcreteModel) –

  • mode (str, optional) –

    Specifies which set of constraints to use.

    • convex : Use linear constraints

    • integer : Use same constraints as convex mode

reset(schedule=None)

Reset all values of specified schedule.

Parameters:

schedule

Specify which schedule to reset.

  • None : Resets all schedules

  • ’default’ : Resets normal schedule

  • ’ref’ : Resets reference schedule

update_model(mode='')

Update block parameters and bounds.

Set parameters and bounds according to the current situation of the device according to the previous schedule and the current forecasts.

Parameters:

mode (str, optional) –

Specifies which set of constraints to use.

  • convex : Use linear constraints

  • integer : Use integer variables representing discrete control decisions

update_schedule()

Update the schedule with the scheduling model solution.

Retrieve the solution from the scheduling model and write it to the schedule. The model must be optimal. The time / position of the solution in the schedule is determined by self.timer.current_timestep.

pycity_scheduling.classes.base.environment module

The pycity_scheduling framework

Copyright (C) 2022, Institute for Automation of Complex Power Systems (ACS), E.ON Energy Research Center (E.ON ERC), RWTH Aachen University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pycity_scheduling.classes.base.environment.ComponentStorage(rd: ResourceDefinition)

Bases: ChainMap

Storage Class for Components for Definitions of specific ResourceDefinitions.

Parameters:

rd (ResourceDefinition) – ResourceDefinition this class stores Components of.

Notes

The underlying ResourceDefinition can change after initialization. This happens when new Definitions are stored that

are implemented by a child class of the current ResourceDefinition. In this case, rd is changed to the child class.

Methods

add(x)

Add an underlying ComponentStorage or an environment to the saved components of this object.

components

add(x: Environment | ComponentStorage)

Add an underlying ComponentStorage or an environment to the saved components of this object. These objects are then used for Component lookup, if this object does not yield a result.

Parameters:

x (Environment | ComponentStorage) – ComponentStorage or Environment to add.

components() Component
Return type:

Component

class pycity_scheduling.classes.base.environment.Environment(timer: Timer | TimeSampler)

Bases: object

Environment description for scheduling purposes.

Parameters:

timer (Union[Timer | TimeSampler]) – Timer or TimeSampler used for Component creation.

Methods

add_relation(r)

Add an equation to this environment.

has(item)

Check if a certain Definition is stored in this Environment.

add

components

infer

keys

rels

symbol

add(x: Environment)
Parameters:

x (Environment) –

add_relation(r: Relational)

Add an equation to this environment. This equation is then added to the optimization model on creation.

Parameters:

r (Relational) – sympy Relation to add to the environment.

components()
has(item: Definition) bool

Check if a certain Definition is stored in this Environment.

Parameters:

item (Definition) – Definition to check for

Returns:

True if Definition was found, false otherwise.

Return type:

bool

static infer(es: List[Environment])
Parameters:

es (List[Environment]) –

keys()
rels()
static_entity_id = 0
symbol(sd: SymbolDefinition)
Parameters:

sd (SymbolDefinition) –

symbol_lookup = <WeakValueDictionary>
t = t

pycity_scheduling.classes.base.operations module

class pycity_scheduling.classes.base.operations.OperatorGroup(name: str, ignore_types=(<class 'float'>, <class 'int'>, <class 'bool'>))

Bases: object

This class registers packages that can be used to evaluate expressions rapidly after model initialization.

Its functionality is similar to sympy’s lambdify and the functionality should probably be merged eventually.

Methods

__call__(*args, **kwargs)

Call self as a function.

add_from_package

add_operator

Parameters:

name (str) –

classmethod add_from_package(t: type, m: module, exceptions={})
Parameters:
  • t (type) –

  • m (module) –

add_operator(t: type, f: callable)
Parameters:
  • t (type) –

  • f (callable) –

pycity_scheduling.classes.base.optimization_entity module

The pycity_scheduling framework

Copyright (C) 2022, Institute for Automation of Complex Power Systems (ACS), E.ON Energy Research Center (E.ON ERC), RWTH Aachen University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pycity_scheduling.classes.base.optimization_entity.OptimizationEntity(environment: Environment, subs: dict = {}, location=None, ts: TimeSampler | None = None, *args, **kwargs)

Bases: object

Base class for all optimization entities.

This class provides functionality common to all entities which take part in the scheduling optimization.

Parameters:
  • environment (Environment) – Common Environment instance.

  • subs (dict) – Dictionary with symbol substitutions

  • ts (TimeSampler) –

Attributes:
op_horizon

Number of time steps in a scheduling period.

op_vec

Iterator over scheduling period.

schedule

The current loaded schedule.

simu_horizon

Number of time steps in the whole simulation horizon.

time_slots

Length of a time steps.

timestep

Time step indicating the current scheduling.

Methods

copy_schedule([dst, src, name])

Copy values of one schedule in another schedule.

get_all_entities()

Yield all entities.

get_entities()

Yield all lowest contained entities.

get_lower_entities()

Yield all lower-level entities.

get_objective([coeff])

Objective function for entity level scheduling.

load_schedule(schedule)

Copy values of one schedule in another schedule.

load_schedule_into_model([schedule])

Overwrites the values in the entity model with the values in the schedule.

new_schedule(schedule)

Create a new schedule with default values.

new_var(sd[, func])

Create a new entry and empty schedule for variable with specified name.

populate_model([mode])

Add entity block to pyomo ConcreteModel.

reset([schedule])

Reset all values of specified schedule.

set_objective(objective)

Set a new objective to be returned by get_objective.

update_model([mode])

Update block parameters and bounds.

update_schedule()

Update the schedule with the scheduling model solution.

activate_rel

activate_rel(r: Relational)
Parameters:

r (Relational) –

copy_schedule(dst: str | None = None, src: str | None = None, name: str | None = None)

Copy values of one schedule in another schedule.

Parameters:
  • dst (str | None) – Name of schedule to insert values into. If None, use current schedule.

  • src (str | None) – Name of schedule to copy values from. If None, use current schedule.

  • name (str | None) – Name of variable to copy sub schedule of. If None, copy all variables between schedules.

get_all_entities() Generator[OptimizationEntity]

Yield all entities.

Yields:

All contained entities and sub-entities.

Return type:

Generator[OptimizationEntity]

get_entities() Generator[OptimizationEntity]

Yield all lowest contained entities.

Yields:

Lowest contained entities or self.

Return type:

Generator[OptimizationEntity]

get_lower_entities() Generator[OptimizationEntity]

Yield all lower-level entities.

Yields:

All contained entities.

Return type:

Generator[OptimizationEntity]

get_objective(coeff: float = 1)

Objective function for entity level scheduling.

Return the objective function of the entity weighted with coeff.

Parameters:

coeff (float) – Coefficient for the objective function.

Returns:

Objective function.

Return type:

ExpressionBase

load_schedule(schedule)

Copy values of one schedule in another schedule.

Parameters:
  • schedule (str) –

  • schedule. (Name of schedule to set as current) –

load_schedule_into_model(schedule: str | None = None)

Overwrites the values in the entity model with the values in the schedule.

Parameters:

schedule (str | None) – Name of schedule to load values from. If None, use current schedule.

new_schedule(schedule: str)

Create a new schedule with default values.

Parameters:

schedule (str) – Name of new schedule.

new_var(sd: SymbolDefinition, func=None)

Create a new entry and empty schedule for variable with specified name.

Parameters:
  • name (str) – Name to access new variable with.

  • dtype (numpy.dtype, optional) – Data type which should be used for new schedule.

  • func (Callable[[int], Any], optional) – Function to generate schedule with. If None, schedule is generated with values of variables.

  • sd (SymbolDefinition) –

property op_horizon

Number of time steps in a scheduling period.

property op_vec

Iterator over scheduling period.

populate_model(mode='')

Add entity block to pyomo ConcreteModel.

Places the block with the name of the entity in the ConcreteModel.

Parameters:
  • model (pyomo.ConcreteModel) –

  • mode (str, optional) –

    Specifies which set of constraints to use.

    • convex : Use linear constraints

    • integer : May use integer variables

reset(schedule: str | None = None)

Reset all values of specified schedule.

Parameters:

schedule (str | None) –

Specify which schedule to reset.

  • None : Resets all schedules

  • ’default’ : Resets normal schedule

  • ’ref’ : Resets reference schedule

property schedule

The current loaded schedule.

set_objective(objective: str)

Set a new objective to be returned by get_objective.

Parameters:

objective (str) –

Objective for the scheduling.

  • ’none’ : No objective (leave all flexibility to other participants).

property simu_horizon

Number of time steps in the whole simulation horizon.

static_entity_id = 0
t = t
property time_slots

Length of a time steps.

property timestep

Time step indicating the current scheduling.

update_model(mode='')

Update block parameters and bounds.

Set parameters and bounds according to the current situation of the device according to the previous schedule and the current forecasts.

Parameters:

mode (str, optional) –

Specifies which set of constraints to use.

  • convex : Use linear constraints

  • integer : Use integer variables representing discrete control decisions

update_schedule()

Update the schedule with the scheduling model solution.

Retrieve the solution from the scheduling model and write it to the schedule. The model must be optimal. The time / position of the solution in the schedule is determined by self.timer.current_timestep.

pycity_scheduling.classes.base.ressource_definition module

class pycity_scheduling.classes.base.ressource_definition.ResourceDefinition(name: str, parent: Definition | None = None)

Bases: Definition

Definition representing a collection of symbols that can be used in equations

bases

Resource Definition Classes that are created for this object from the ResourceDefinition class

definitions

Yields definitions contained by this ResourceDefinition

rels

Sympy Relations that apply to this definition Relations only use symbols defined in this ResourceDefinition

Type:

sympy.Rel

Attributes:
bases
definitions
rels
Parameters:

Methods

copy(name, parent)

Copies this definition to a new parent under a new name

symbols()

Yields:

sympy.core.symbol.Symbol -- Sympy Symbols that belong to this definition

property bases: Tuple[Type[ResourceDefinition]]
copy(name, parent)

Copies this definition to a new parent under a new name

Parameters:
  • parent – Optional new Parent the copy of this definition should belong to.

  • name – Optional new name for the copy.

property definitions
property rels: Generator[Rel]
symbols() Generator[Definition]
Yields:

sympy.core.symbol.Symbol – Sympy Symbols that belong to this definition

Return type:

Generator[Definition]

pycity_scheduling.classes.base.symbol_definition module

class pycity_scheduling.classes.base.symbol_definition.SymbolDefinition(name: str, parent: Definition | None = None, unit: str | None = None, **assumptions)

Bases: Definition

Definition representing a single symbol that can be used in equations

Parameters:
t

Helper Symbol representing time to support integrals and derivatives

Type:

sympy.core.symbol.Symbol

x

Sympy Function for use in equations

Type:

sympy.core.Function

unit

Unit universally used for this definition

Methods

copy(name, parent)

Copies this definition to a new parent under a new name

symbols()

Yields:

sympy.core.symbol.Symbol -- Sympy Symbols that belong to this definition

get_definition

copy(name, parent)

Copies this definition to a new parent under a new name

Parameters:
  • parent – Optional new Parent the copy of this definition should belong to.

  • name – Optional new name for the copy.

function_symbol_map = <WeakKeyDictionary>
static get_definition(x: Function)
Parameters:

x (Function) –

symbols()
Yields:

sympy.core.symbol.Symbol – Sympy Symbols that belong to this definition

t = t

pycity_scheduling.classes.base.time_sampler module

class pycity_scheduling.classes.base.time_sampler.TimeSampler(timer: Timer, step_sizes: int | Iterable[int] = 1)

Bases: object

Attributes:
delta_t
op_dt_range
op_index
op_slc
samples
step_index
step_size
step_slc
Parameters:
property delta_t
property op_dt_range
property op_index
property op_slc
property samples
property step_index
property step_size
property step_slc

pycity_scheduling.classes.base.timer module

The pycity_scheduling framework

Copyright (C) 2022, Institute for Automation of Complex Power Systems (ACS), E.ON Energy Research Center (E.ON ERC), RWTH Aachen University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pycity_scheduling.classes.base.timer.Timer(step_size: int = 900, op_horizon: int = 96, mpc_horizon: int | None = None, mpc_step_width: int | None = None, initial_datetime: Timestamp = Timestamp('2015-01-01 00:00:00+0100', tz='Europe/Berlin'))

Bases: object

Timer class for scheduling purposes

Parameters:
  • step_size (int) – Number of the smallest sampling steps

  • op_horizon (int) – Number of sampling time steps used in one scheduling optimization.

  • mpc_horizon (int | None) – Number of samplings in whole simulation. All data must be available for this time. If None set value to op_horizon.

  • mpc_step_width (int | None) – Number of samplings between two optimizations in MPC. If None set value to op_horizon.

  • initial_datetime (Timestamp) – Initial date

step_size

Number of the smallest sampling steps

op_horizon

Number of sampling time steps used in one scheduling optimization.

mpc_horizon

Number of samplings in whole simulation. All data must be available for this time. If None set value to op_horizon.

mpc_step_width

Number of samplings between two optimizations in MPC. If None set value to op_horizon.

initial_datetime

Initial date

tz

Timezone for

Notes

  • This class’ behaviour may differ from the one of the baseclass, as it keeps an actual date rather than a relative counter only

Attributes:
current_timestep
date

The date of the current timestep.

dates
datetime

The datetime of the current timestep.

day

The day of the month for the current timestep.

delta_t
has_leaps
hour

The hour of the current timestep.

is_leap

If the year of the current timestep is a leap year.

minute

The minute of the current timestep.

month

The month of the current timestep.

mpc_dt_range
mpc_end
mpc_horizon
mpc_index
mpc_start
op_dt_range
op_end
op_horizon
op_index
op_slc
op_start
second

The second of the current timestep.

step_size
time

The time for the current timestep.

time_slots
weekday

The weekday of the current timestep.

year

The year of the current timestep.

Parameters:
  • step_size (int) –

  • op_horizon (int) –

  • mpc_horizon (int | None) –

  • mpc_step_width (int | None) –

  • initial_datetime (Timestamp) –

Methods

mpc_update()

Update Timer for MPC.

print_datetime()

Print the datetime for the current timestep.

reset()

Reset the Timer to the initial state.

float_to_timestamp

x_to_float

property current_timestep
property date

The date of the current timestep.

property dates
property datetime

The datetime of the current timestep.

property day

The day of the month for the current timestep.

property delta_t
float_to_timestamp(x)
property has_leaps
property hour

The hour of the current timestep.

property is_leap

If the year of the current timestep is a leap year.

property minute

The minute of the current timestep.

property month

The month of the current timestep.

property mpc_dt_range
property mpc_end
property mpc_horizon
property mpc_index
property mpc_start
mpc_update()

Update Timer for MPC.

Move self.mpc_step_width timesteps forward.

property op_dt_range
property op_end
property op_horizon
property op_index
property op_slc
property op_start
print_datetime()

Print the datetime for the current timestep.

reset()

Reset the Timer to the initial state.

property second

The second of the current timestep.

property step_size
property time

The time for the current timestep.

property time_slots
property weekday

The weekday of the current timestep.

x_to_float(x)
property year

The year of the current timestep.

pycity_scheduling.classes.base.timer.is_scalar_int(x)

Module contents

The pycity_scheduling framework

Copyright (C) 2022, Institute for Automation of Complex Power Systems (ACS), E.ON Energy Research Center (E.ON ERC), RWTH Aachen University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.