def setUp(self): start = datetime(2018, 12, 31, tzinfo=pytz.timezone("America/Los_Angeles")) network = acnsim.ChargingNetwork() evse1 = acnsim.EVSE("PS-001", max_rate=32) network.register_evse(evse1, 240, 0) scheduler = create_autospec(BaseAlgorithm) scheduler.max_recompute = None self.events = acnsim.EventQueue(events=[acnsim.Event(1)]) self.simulator = acnsim.Simulator(network, scheduler, self.events, start, period=240) self.simulator._iteration = 10 self.expected_datetime_array = [ np.datetime64("2018-12-31T00:00:00.000000"), np.datetime64("2018-12-31T04:00:00.000000"), np.datetime64("2018-12-31T08:00:00.000000"), np.datetime64("2018-12-31T12:00:00.000000"), np.datetime64("2018-12-31T16:00:00.000000"), np.datetime64("2018-12-31T20:00:00.000000"), np.datetime64("2019-01-01T00:00:00.000000"), np.datetime64("2019-01-01T04:00:00.000000"), np.datetime64("2019-01-01T08:00:00.000000"), np.datetime64("2019-01-01T12:00:00.000000"), ]
def setUpClass(cls): # Make instance of each class in registry. # Battery cls.battery1 = acnsim.Battery(100, 50, 20) cls.battery1._current_charging_power = 10 # Linear2StageBattery cls.battery2 = acnsim.Linear2StageBattery(100, 50, 20) cls.battery2._current_charging_power = 10 cls.battery2._noise_level = 0.1 cls.battery2._transition_soc = 0.85 # EVs staying_time = 10 ev1_arrival = 10 cls.ev1 = acnsim.EV( ev1_arrival, ev1_arrival + staying_time, 30, "PS-001", "EV-001", deepcopy(cls.battery1), estimated_departure=35, ) cls.ev1._energy_delivered = 0.05 cls.ev1._current_charging_rate = 10 ev2_arrival = 40 cls.ev2 = acnsim.EV( ev2_arrival, ev2_arrival + staying_time, 30, "PS-002", "EV-002", deepcopy(cls.battery2), estimated_departure=65, ) cls.ev2._energy_delivered = 0.05 cls.ev2._current_charging_rate = 10 ev3_arrival = 50 cls.ev3 = acnsim.EV( ev3_arrival, ev3_arrival + staying_time, 30, "PS-003", "EV-003", deepcopy(cls.battery2), estimated_departure=75, ) cls.ev3._energy_delivered = 0.05 cls.ev3._current_charging_rate = 10 # EVSEs cls.evse0 = acnsim.EVSE("PS-000", max_rate=32) cls.evse1 = acnsim.EVSE("PS-001", max_rate=32) cls.evse1.plugin(cls.ev1) cls.evse1.set_pilot(30, 220, 1) cls.evse2 = acnsim.DeadbandEVSE("PS-002", max_rate=32, deadband_end=4) cls.evse2.plugin(cls.ev2) cls.evse2.set_pilot(30, 220, 1) cls.evse3 = acnsim.FiniteRatesEVSE("PS-003", allowable_rates=[0, 8, 16, 24, 32]) cls.evse3.plugin(cls.ev3) cls.evse3.set_pilot(24, 220, 1) # Events cls.event = acnsim.Event(0) cls.plugin_event1 = acnsim.PluginEvent(10, cls.ev1) cls.unplug_event = acnsim.UnplugEvent(20, cls.ev1) cls.recompute_event1 = acnsim.RecomputeEvent(30) cls.plugin_event2 = acnsim.PluginEvent(40, cls.ev2) cls.plugin_event3 = acnsim.PluginEvent(50, cls.ev3) # Modify a default attribute to check if it's loaded correctly. cls.recompute_event2 = acnsim.RecomputeEvent(10) cls.recompute_event2.event_type = "Recompute Modified" # EventQueue cls.event_queue = acnsim.EventQueue() cls.event_queue.add_events([ cls.event, cls.plugin_event1, cls.recompute_event1, cls.plugin_event2, cls.plugin_event3, ]) # Network cls.network = acnsim.ChargingNetwork(violation_tolerance=1e-3, relative_tolerance=1e-5) cls.network.register_evse(cls.evse1, 220, 30) cls.network.register_evse(cls.evse2, 220, 150) cls.network.register_evse(cls.evse3, 220, -90) cls.network.constraint_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) cls.network.magnitudes = np.array([32, 32, 32]) cls.network.constraint_index = ["C1", "C2", "C3"] _ = cls.network._update_info_store() cls.empty_network = acnsim.ChargingNetwork() # Simulator cls.simulator = acnsim.Simulator( cls.network, UncontrolledCharging(), cls.event_queue, datetime(2019, 1, 1), verbose=False, store_schedule_history=True, ) # Make a copy of the simulator to run cls.simulator_run = deepcopy(cls.simulator) # Do necessary unplugs. for evse in cls.simulator_run.network._EVSEs.values(): if evse.ev is not None: evse.unplug() # Run simulation cls.simulator_run.run() # Make a copy of the simulator with signals cls.simulator_signal = deepcopy(cls.simulator) cls.simulator_signal.signals = {"a": [0, 1, 2], "b": [3, 4]} cls.simulator_hard_signal = deepcopy(cls.simulator) cls.simulator_hard_signal.signals = {"a": BaseAlgorithm()} cls.simulator_no_sch_hist = deepcopy(cls.simulator) cls.simulator_no_sch_hist.schedule_history = None # Class data used for testing. cls.simple_attributes = { "Battery": [ "_max_power", "_current_charging_power", "_current_charge", "_capacity", "_init_charge", ], "Linear2StageBattery": [ "_max_power", "_current_charging_power", "_current_charge", "_capacity", "_init_charge", "_noise_level", "_transition_soc", ], "EV": [ "_arrival", "_departure", "_requested_energy", "_estimated_departure", "_session_id", "_station_id", "_energy_delivered", "_current_charging_rate", ], "EVSE": [ "_station_id", "_max_rate", "_min_rate", "_current_pilot", "is_continuous", ], "DeadbandEVSE": [ "_station_id", "_max_rate", "_current_pilot", "_deadband_end", "is_continuous", ], "FiniteRatesEVSE": [ "_station_id", "_current_pilot", "is_continuous", "allowable_rates", ], "Event": ["timestamp", "event_type", "precedence"], "PluginEvent": ["timestamp", "event_type", "precedence"], "UnplugEvent": ["timestamp", "event_type", "precedence"], "RecomputeEvent": ["timestamp", "event_type", "precedence"], "EventQueue": ["_timestep"], "ChargingNetwork": [ "constraint_index", "violation_tolerance", "relative_tolerance", "_station_ids_dict", ], "Simulator": [ "period", "max_recompute", "verbose", "peak", "_iteration", "_resolve", "_last_schedule_update", "schedule_history", ], }
def setUpClass(cls): # Make instance of each class in registry. # Battery cls.battery1 = acnsim.Battery(100, 50, 20) cls.battery1._current_charging_power = 10 # Linear2StageBattery cls.battery2 = acnsim.Linear2StageBattery(100, 50, 20) cls.battery2._current_charging_power = 10 cls.battery2._noise_level = 0.1 cls.battery2._transition_soc = 0.85 # EVs staying_time = 10 ev1_arrival = 10 cls.ev1 = acnsim.EV(ev1_arrival, ev1_arrival + staying_time, 30, 'PS-001', 'EV-001', deepcopy(cls.battery1), estimated_departure=25) cls.ev1._energy_delivered = 0.05 cls.ev1._current_charging_rate = 10 ev2_arrival = 40 cls.ev2 = acnsim.EV(ev2_arrival, ev2_arrival + staying_time, 30, 'PS-002', 'EV-002', deepcopy(cls.battery2), estimated_departure=25) cls.ev2._energy_delivered = 0.05 cls.ev2._current_charging_rate = 10 ev3_arrival = 50 cls.ev3 = acnsim.EV(ev3_arrival, ev3_arrival + staying_time, 30, 'PS-003', 'EV-003', deepcopy(cls.battery2), estimated_departure=25) cls.ev3._energy_delivered = 0.05 cls.ev3._current_charging_rate = 10 # EVSEs cls.evse0 = acnsim.EVSE('PS-000', max_rate=32) cls.evse1 = acnsim.EVSE('PS-001', max_rate=32) cls.evse1.plugin(cls.ev1) cls.evse1.set_pilot(30, 220, 1) cls.evse2 = acnsim.DeadbandEVSE('PS-002', max_rate=32, deadband_end=4) cls.evse2.plugin(cls.ev2) cls.evse2.set_pilot(30, 220, 1) cls.evse3 = acnsim.FiniteRatesEVSE('PS-003', allowable_rates=[0, 8, 16, 24, 32]) cls.evse3.plugin(cls.ev3) cls.evse3.set_pilot(24, 220, 1) # Events cls.event = acnsim.Event(0) cls.plugin_event1 = acnsim.PluginEvent(10, cls.ev1) cls.unplug_event = acnsim.UnplugEvent(20, 'PS-001', 'EV-001') cls.recompute_event1 = acnsim.RecomputeEvent(30) cls.plugin_event2 = acnsim.PluginEvent(40, cls.ev2) cls.plugin_event3 = acnsim.PluginEvent(50, cls.ev3) # Modify a default attribute to check if it's loaded correctly. cls.recompute_event2 = acnsim.RecomputeEvent(10) cls.recompute_event2.event_type = 'Recompute Modified' # EventQueue cls.event_queue = acnsim.EventQueue() cls.event_queue.add_events([ cls.event, cls.plugin_event1, cls.recompute_event1, cls.plugin_event2, cls.plugin_event3 ]) # Network cls.network = acnsim.ChargingNetwork(violation_tolerance=1e-3, relative_tolerance=1e-5) cls.network.register_evse(cls.evse1, 220, 30) cls.network.register_evse(cls.evse2, 220, 150) cls.network.register_evse(cls.evse3, 220, -90) cls.network.constraint_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) cls.network.magnitudes = np.array([32, 32, 32]) cls.network.constraint_index = ['C1', 'C2', 'C3'] cls.empty_network = acnsim.ChargingNetwork() # Simulator cls.simulator = acnsim.Simulator(cls.network, UncontrolledCharging(), cls.event_queue, datetime(2019, 1, 1), verbose=False, store_schedule_history=True) # Make a copy of the simulator to run cls.simulator_run = deepcopy(cls.simulator) # Do necessary unplugs. for evse in cls.simulator_run.network._EVSEs.values(): if evse.ev is not None: evse.unplug() # Run simulation cls.simulator_run.run() # Make a copy of the simulator with signals cls.simulator_signal = deepcopy(cls.simulator) cls.simulator_signal.signals = {'a': [0, 1, 2], 'b': [3, 4]} cls.simulator_hard_signal = deepcopy(cls.simulator) cls.simulator_hard_signal.signals = {'a': BaseAlgorithm()} cls.simulator_no_sch_hist = deepcopy(cls.simulator) cls.simulator_no_sch_hist.schedule_history = None # Class data used for testing. cls.simple_attributes = { 'Battery': [ '_max_power', '_current_charging_power', '_current_charge', '_capacity', '_init_charge' ], 'Linear2StageBattery': [ '_max_power', '_current_charging_power', '_current_charge', '_capacity', '_init_charge', '_noise_level', '_transition_soc' ], 'EV': [ '_arrival', '_departure', '_requested_energy', '_estimated_departure', '_session_id', '_station_id', '_energy_delivered', '_current_charging_rate' ], 'EVSE': [ '_station_id', '_max_rate', '_min_rate', '_current_pilot', 'is_continuous' ], 'DeadbandEVSE': [ '_station_id', '_max_rate', '_current_pilot', '_deadband_end', 'is_continuous' ], 'FiniteRatesEVSE': [ '_station_id', '_current_pilot', 'is_continuous', 'allowable_rates' ], 'Event': ['timestamp', 'event_type', 'precedence'], 'PluginEvent': ['timestamp', 'event_type', 'precedence'], 'UnplugEvent': [ 'timestamp', 'event_type', 'precedence', 'station_id', 'session_id' ], 'RecomputeEvent': ['timestamp', 'event_type', 'precedence'], 'EventQueue': ['_timestep'], 'ChargingNetwork': ['constraint_index', 'violation_tolerance', 'relative_tolerance'], 'Simulator': [ 'period', 'max_recompute', 'verbose', 'peak', '_iteration', '_resolve', '_last_schedule_update', 'schedule_history' ] }