smartgrid.util.available_energy.RandomEnergyGenerator¶
- class smartgrid.util.available_energy.RandomEnergyGenerator(lower_proportion=0.8, upper_proportion=1.2)[source]¶
Bases:
EnergyGenerator
Generate a random amount, with respect to the agents’ current energy needed.
Assuming that the total maximum energy needed is
M
, that we want at least a lower bound of L=80% (i.e., L=0.8), and an upper bound of U=120% (i.e., U=1.2), this class returns amounts in the interval[L*M, U*M]
.Knowing the minimum sum of energy needed by all agents
minM
, we derive that the lowest amount of energy that can be produced by this generator isL*minM
, for any time step. Similarly, assuming the maximum sum ismaxM
, the highest amount that can be produced isU*maxM
. Thus, this generator’s possible bounds are[L*minM, U*maxM]
.Lower and upper bounds are configurable.
Methods
__init__
([lower_proportion, upper_proportion])available_energy_bounds
(current_need, ...)Determine the possible min and max bounds for the energy generation.
generate_available_energy
(current_need, ...)Generate an amount of available energy during a single time step.
set_random_generator
(random_generator)Attributes
Lower bound for generating energy, in proportion of the total need.
Upper bound for generating energy, in proportion of the total need.
- _random_generator: Generator¶
The pseudo-random number generator (PRNG).
EnergyGenerators that are purely deterministic can safely ignore this attribute; those that rely on random generation must use exclusively this attribute, to ensure reproducibility.
To set this attribute (and thus, to set the random seed), use the
set_random_generator()
method. It is initialized by default, so the EnergyGenerator can be used as-is without needing to configure.
- available_energy_bounds(current_need: int, current_step: int, min_need: int, max_need: int)[source]¶
Determine the possible min and max bounds for the energy generation.
This method is used to provide a range (a domain), which is important for specifying the
Observation
space ofAgent
s. This also allows scaling the generated amount to[0,1]
. For example, assuming the bounds are[0, 10_000]
, a generated amount of8_000
can be scaled to0.8
, which is easier to use by learning algorithms.- Parameters:
current_need – The total energy needed by all agents at the current step.
current_step – The current time step.
min_need – The minimum energy needed by all agents, for all time steps. This value is used for the same objective as
max_need
, but it does not need to be accurate, e.g.,0
can be used as a safe default.max_need – The maximum energy needed by all agents, for all time steps. This value can be used to accurately determine the bounds for all time steps, instead of a single time step. The
need_at_step
should always be lower or equal to themax_need
.
- Returns:
The min and max bounds of the energy generator, i.e., the minimum and maximum possible values that
generate_available_energy()
may return. It is important that these bounds are coherent with the method, otherwise scaling may not work properly, and Agents may receive incorrect observations.
- generate_available_energy(current_need: int, current_step: int, min_need: int, max_need: int)[source]¶
Generate an amount of available energy during a single time step.
EnergyGenerators can use any method to compute this amount, e.g., returning a fixed value, drawing from a distribution, using an array of realistic data for each time step, etc.
- Parameters:
current_need – The total energy needed by all agents at the current step. This value can be used to effectively scale the generator to the current agent population. This value can also be ignored by the generator. The
current_need
should be comprised betweenmin_need
andmax_need
.current_step – The current time step. Mostly used by “realistic” or data-based generators that need to know the current date/hour.
min_need – The minimum energy needed by all agents, for all time steps. It does not need to be exact, and only serve as a lower bound, e.g.,
0
is a perfectly sane value. However, the more accurate this value is, the more accurate the scaling of theObservation
space will be.max_need – The maximum energy needed by all agents, for all time steps. It does not need to be exact, and only serves as an upper bound, e.g., any sufficiently high value can be used. However, the more accurate this value is, the more accurate the scaling of the
Observation
space will be.
- Returns:
The amount of available energy, a value in \(\mathbb{R}\). For example, returning
40_000
means that 40,000Wh are available for the current time step.