Simulator

class acnportal.acnsim.simulator.Simulator(network, scheduler, events, start, period: float = 1, signals=None, store_schedule_history=False, verbose=True, interface_type=<class 'acnportal.acnsim.interface.Interface'>)

Central class of the acnsim package.

The Simulator class is the central place where everything about a particular simulation is stored including the network, scheduling algorithm, and events. It is also where timekeeping is done and orchestrates calling the scheduling algorithm, sending pilots to the network, and updating the energy delivered to each EV.

Parameters:
  • network (ChargingNetwork) – The charging network which the simulation will use.
  • scheduler (BaseAlgorithm) – The scheduling algorithm used in the simulation. If scheduler = None, Simulator.run() cannot be called.
  • events (EventQueue) – Queue of events which will occur in the simulation.
  • start (datetime) – Date and time of the first period of the simulation.
  • period (float) – Length of each time interval in the simulation in minutes. Default: 1
  • signals (Dict[str, ..]) –
  • store_schedule_history (bool) – If True, store the scheduler output each time it is run. Note this can use lots of memory for long simulations.
  • interface_type (type) – The class of interface to register with the scheduler.
charging_rates_as_df()

Return the charging rates as a pandas DataFrame, with EVSE id as columns and iteration as index.

Returns:
A DataFrame containing the charging rates
of the simulation. Columns are EVSE id, and the index is the iteration.
Return type:pandas.DataFrame
get_active_evs()

Return all EVs which are plugged in and not fully charged at the current time.

Wrapper for self.network.active_evs. See its documentation for more details.

Returns:List of all EVs which are plugged in but not fully charged at the current time.
Return type:List[EV]
index_of_evse(station_id)

Return the numerical index of the EVSE given by station_id in the (ordered) dictionary of EVSEs.

pilot_signals_as_df()

Return the pilot signals as a pandas DataFrame

Returns:
A DataFrame containing the pilot signals
of the simulation. Columns are EVSE id, and the index is the iteration.
Return type:pandas.DataFrame
run()

If scheduler is not None, run the simulation until the event queue is empty.

The run function is the heart of the simulator. It triggers all actions and keeps the simulator moving forward. Its actions are (in order):

  1. Get current events from the event queue and execute them.
  2. If necessary run the scheduling algorithm.
  3. Send pilot signals to the network.
  4. Receive back actual charging rates from the network and store the results.
Returns:None
Raises:TypeError – If called when the scheduler attribute is None. The run() method requires a BaseAlgorithm-like scheduler to execute.
step(new_schedule)

Step the simulation until the next schedule recompute is required.

The step function executes a single iteration of the run() function. However, the step function updates the simulator with an input schedule rather than query the scheduler for a new schedule when one is required. Also, step will return a flag if the simulation is done.

Parameters:new_schedule (Dict[str, List[number]]) – Dictionary mapping station ids to a schedule of pilot signals.
Returns:True if the simulation is complete.
Return type:bool
update_scheduler(new_scheduler)

Updates a Simulator’s schedule.

exception acnportal.acnsim.simulator.InvalidScheduleError

Raised when the schedule passed to the simulator is invalid.