building_sizer package

Submodules

building_sizer.building_sizer_algorithm module

building_sizer.evolutionary_algorithm module

Evolutionary algorithms evaluate the fitness of various individuals of a population - and inspired by biology - combine them randomly to a new generation. The fitter the individuals the better the chance to propagate. In this context an individual would be a specified building configurations for HiSIM calls and the new generation is built by combination and variation of parameters in the building configuration. This file incoporates one step of the evolutionary algorithm creating a new population based on a rated one. In addition, the file includes all necesary functions for the evaluation step: mutation, crossover, selection,… .

building_sizer.evolutionary_algorithm.complete_population(original_parents: List[Individual], population_size: int, options: SizingOptions) List[Individual]

Adds random individuals to population, if the population size is too small.

Parameters:
  • original_parents (List[individual_encoding.Individual]) – list of individuals of original population

  • population_size (int) – number of individuals the population should finally contain

  • options (individual_encoding.SizingOptions:) – contains all available options for the sizing of each component.

Returns:

list of individuals of the completed population

Return type:

completed_population: List[individual_encoding.Individual]

building_sizer.evolutionary_algorithm.crossover_conventional(parent1: Individual, parent2: Individual) Tuple[Individual, Individual]

Combines two individuals (parents) to two new individuals (children). This is done by randomly generating an index and exchanging parts of the bitstrings, which describe individuals.

Parameters:
Returns:

encoding of childs resulting from cross over

Rtype child1:

Tuple[individual_encoding.RatedIndividual,individual_encoding.RatedIndividual]

building_sizer.evolutionary_algorithm.evolution(parents: List[Individual], r_cross: float, r_mut: float, mode: str, options: SizingOptions) List[Individual]

One step of the evolutionary algorithm (evolution) not including the selection process. Random numbers are generated to decide if cross over, mutation or nothing is considered for the creation of a new generation.

Parameters:
  • parents (List[individual_encoding.RatedIndividual]) – list of rated individuals

  • r_cross (float) – cross over probability.

  • r_mut (float) – mutation probability

  • mode (str) – iteration mode: “bool” or “discrete”

Returns:

list of unrated individuals

Return type:

List[individual_encoding.Individual]

building_sizer.evolutionary_algorithm.mutation_bool(parent: Individual) Individual

Slightly changes individual by randomly changing one bit of the boolean bitstring, which describes an individual.

Parameters:

parent (individual_encoding.Individual) – encoding of parent used for mutation

Returns:

encoding of first resulting child from cross over

Return type:

individual_encoding.RatedIndividual

building_sizer.evolutionary_algorithm.mutation_discrete(parent: Individual, options: SizingOptions) Individual

Slightly changes individual by randomly changing one bit of the discrete bitstring, which describes an individual.

Parameters:
Returns:

encoding of first resulting child from cross over

Return type:

individual_encoding.RatedIndividual

building_sizer.evolutionary_algorithm.selection(rated_individuals: List[RatedIndividual], population_size: int) List[RatedIndividual]

Selects best individuals.

Parameters:
Returns:

list of individuals with best rating (fitness)

Return type:

List[individual_encoding.RatedIndividual]

building_sizer.evolutionary_algorithm.unique(individuals: List[Individual]) List[Individual]

Compares all individuals and deletes duplicates.

Parameters:
  • rated_individuals (List[individual_encoding.RatedIndividual]) – list of all individuals (HiSIM configurations) and KPIs (HiSIM results)

  • population_size – amount of individuals to be selected

Tpye population_size:

int

Returns:

shortened list of individuals (HiSIM configurations) and KPIs (HiSIM results)

Return type:

List[individual_encoding.RatedIndividual]

building_sizer.individual_encoding module

Translation of HiSIM system configurations to boolean and discrete vectors, which can be treated by the evolutionary algorithms, and back. Classes to gather information needed for the Translator as well as combine informations describing individuals. (HiSIM system config, boolean and discrete vectors as well as fitness or rating)

exception building_sizer.individual_encoding.BuildingSizerException

Bases: Exception

Exception for errors in the Building Sizer.

class building_sizer.individual_encoding.Individual(bool_vector: ~typing.List[bool] = <factory>, discrete_vector: ~typing.List[float] = <factory>)

Bases: object

System config as numerical vectors.

bool_vector: List[bool]

encoding of the individual (HiSIM configuration) of the boolean part - each digit decides if related technology is included or not

static create_random_individual(options: SizingOptions) Individual

Creates random individual.

Parameters:

options – Contains all available options for the sizing of each component.

Tpye options:

SizingOptions

Returns:

Individual with bool and discrete vector.

Rtype individual:

Individual

discrete_vector: List[float]

encoding of the individual (HiSIM configuration) of the discrete part - each digit describes the size of the considered technology

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) str
class building_sizer.individual_encoding.RatedIndividual(individual: Individual, rating: float)

Bases: object

System config as numerical vectors with associated fitness function value.

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
individual: Individual

the individual object, containing a system config encoded as numerical vectors

rating: float

the fitness function value of the individual

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) str
class building_sizer.individual_encoding.SizingOptions(pv_peak_power: ~typing.List[float] = <factory>, battery_capacity: ~typing.List[float] = <factory>, buffer_volume: ~typing.List[float] = <factory>, bool_attributes: ~typing.List[str] = <factory>, discrete_attributes: ~typing.List[str] = <factory>, probabilities: ~typing.List[float] = <factory>)

Bases: object

Contains all relevant information to encode and decode system configs.

battery_capacity: List[float]

list of all sizes of batteries considered in the optimization given in kWh

bool_attributes: List[str]

list of technologies (boolean attributes) considered in the optimization

buffer_volume: List[float]

list of all sizes of buffer storages considered in the optimization given in multiples of the default

discrete_attributes: List[str]

list of technologies with different sizing options (discrete attributes) used within the optimization

classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
probabilities: List[float]

defines probability of each component to be considered at the initial configurations

pv_peak_power: List[float]

list of all sizes of PV panels considered in the optimization given in Wp

classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) str
building_sizer.individual_encoding.create_config_from_individual(individual: Individual, options: SizingOptions) SystemConfig

Creates a SystemConfig object from the bool and discrete vectors of an Individual object. For this, the SizingOptions object is needed.

Parameters:
  • individual – Individual with bool and discrete vector.

  • options (SizingOptions) – Contains all available options for the sizing of each component.

Tpye individual:

Individual

Returns:

Household System configuration - input to HiSIM simulation.

Return type:

SystemConfig

building_sizer.individual_encoding.create_individual_from_config(system_config: SystemConfig, options: SizingOptions) Individual

Creates discrete and boolean vector from given SystemConfig.

Parameters:
  • system_config (SystemConfig) – Household System configuration - input to HiSIM simulation.

  • options (SizingOptions) – Contains all available options for the sizing of each component.

Returns:

Individual with bool and discrete vector.

Return type:

Individual

building_sizer.individual_encoding.create_random_system_configs(number: int, options: SizingOptions) List[SystemConfig]

Creates the desired number of random individuals (HiSIM system configurations).

Parameters:
  • number (int) – number of individuals in a population

  • options (SizingOptions) – Contains all available options for the sizing of each component.

Returns:

list of HiSIM system configurations providing input to HiSIM simulations

Return type:

hisim_configs: List[SystemConfig]

building_sizer.individual_encoding.save_system_configs_to_file(configs: List[str]) None

Writes List of system configurations to json file.

Parameters:

congigs – List of system configurations, in string formaat.

building_sizer.start_building_sizer module

Module contents