Microgrid class, used to define and simulate an environment with a variety of modules. Parameters ---------- modules : List[Union[Tuple[str, BaseMicrogridModule], BaseMicrogridModule]] List of modules that define the microgrid. The list can contain either/both microgrid mod
| 16 | |
| 17 | |
| 18 | class Microgrid(yaml.YAMLObject): |
| 19 | """ |
| 20 | Microgrid class, used to define and simulate an environment with a variety of modules. |
| 21 | |
| 22 | Parameters |
| 23 | ---------- |
| 24 | modules : List[Union[Tuple[str, BaseMicrogridModule], BaseMicrogridModule]] |
| 25 | List of modules that define the microgrid. The list can contain either/both microgrid modules -- subclasses of |
| 26 | ``BaseMicrogridModule`` -- and tuples of length two, which must contain a string defining the name of the module |
| 27 | followed by the module. |
| 28 | |
| 29 | ``Microgrid`` groups modules into lists based on their names. If no name is given (e.g. an element in ``modules`` |
| 30 | is a subclass of ``BaseMicrogridModule`` and not a tuple, then the name is defined to be |
| 31 | ``module.__class__.name[0]``. Modules are then exposed (within lists) by name as attributes to the microgrid. |
| 32 | See below for an example. |
| 33 | |
| 34 | .. note:: |
| 35 | The constructor copies modules passed to it. |
| 36 | |
| 37 | add_unbalanced_module : bool, default True. |
| 38 | Whether to add an unbalanced energy module to your microgrid. Such a module computes and attributes |
| 39 | costs to any excess supply or demand. |
| 40 | Set to True unless ``modules`` contains an ``UnbalancedEnergyModule``. |
| 41 | |
| 42 | loss_load_cost : float, default 10.0 |
| 43 | Cost per unit of unmet demand. Ignored if ``add_unbalanced_module=False``. |
| 44 | |
| 45 | overgeneration_cost : float, default 2.0 |
| 46 | Cost per unit of excess generation. Ignored if ``add_unbalanced_module=False``. |
| 47 | |
| 48 | reward_shaping_func : callable or None, default None |
| 49 | Function that allows for custom definition of the microgrid's reward/cost. |
| 50 | If None, the cost of each step is simply the total cost of all modules. |
| 51 | For example, you may define a function that defines the cost as only being the loss load, or only |
| 52 | the pv curtailment. |
| 53 | |
| 54 | trajectory_func : callable or None, default None |
| 55 | Callable that sets an initial and final step for an episode. ``trajectory_func`` must take two inputs: |
| 56 | :attr:`.initial_step` and :attr:`.final_step`, and return two integers: the initial and final step for |
| 57 | that particular episode, respectively. This function will be called every time :meth:`.reset` is called. |
| 58 | |
| 59 | If None, :attr:`.initial_step` and :attr:`.final_step` are used to define every episode. |
| 60 | |
| 61 | |
| 62 | Examples |
| 63 | -------- |
| 64 | >>> from pymgrid import Microgrid |
| 65 | >>> from pymgrid.modules import LoadModule, RenewableModule, GridModule, BatteryModule |
| 66 | >>> timesteps = 10 |
| 67 | >>> load = LoadModule(10*np.random.rand(timesteps), loss_load_cost=10.) |
| 68 | >>> pv = RenewableModule(10*np.random.rand(timesteps)) |
| 69 | >>> grid = GridModule(max_import=100, max_export=10, time_series=np.random.rand(timesteps, 3)) |
| 70 | >>> battery_0 = BatteryModule(min_capacity=0, \ |
| 71 | max_capacity=100, \ |
| 72 | max_charge=1,\ |
| 73 | max_discharge=10, \ |
| 74 | efficiency=0.9, \ |
| 75 | init_soc=0.5) |
no outgoing calls