Пример #1
0
 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"),
     ]
Пример #2
0
    def setUpClass(cls) -> None:
        timezone = pytz.timezone("America/Los_Angeles")
        start = timezone.localize(datetime(2018, 9, 1))
        period = 5  # minute
        voltage = 208  # volts

        cn = acnsim.ChargingNetwork()
        cn.register_evse(acnsim.get_evse_by_type("PS-1", "BASIC"), voltage, 0)
        cn.add_constraint(acnsim.Current("PS-1"), 100)

        batt = acnsim.Battery(100, 0, 7)
        ev = acnsim.EV(5, 5 + 12, voltage * 32 / 1000, "PS-1", "test", batt)
        events = acnsim.EventQueue([acnsim.PluginEvent(ev.arrival, ev)])

        quick_charge_obj = [
            ObjectiveComponent(quick_charge),
            ObjectiveComponent(equal_share, 1e-12),
        ]
        cls.alg = AdaptiveChargingAlgorithmOffline(quick_charge_obj, solver=cp.ECOS)
        cls.alg.register_events(events)
        cls.sim = acnsim.Simulator(
            cn, cls.alg, events, start, period=period, verbose=False
        )
        cls.alg.solve()
        cls.sim.run()
Пример #3
0
    def setUpClass(self):
        self.plugin_event1 = acnsim.PluginEvent(
            10,
            acnsim.EV(10, 20, 30, "PS-001", "EV-001",
                      acnsim.Battery(100, 50, 20)))
        self.plugin_event2 = acnsim.PluginEvent(
            20,
            acnsim.EV(20, 30, 40, "PS-002", "EV-002",
                      acnsim.Battery(100, 50, 20)))

        self.evse1 = acnsim.EVSE("PS-001", max_rate=32, min_rate=0)
        self.evse2 = acnsim.EVSE("PS-002", max_rate=32, min_rate=0)

        self.event_queue = acnsim.EventQueue()
        self.event_queue.add_events([self.plugin_event1, self.plugin_event2])

        self.network = acnsim.ChargingNetwork()
        self.network.register_evse(self.evse1, 220, 30)
        self.network.register_evse(self.evse2, 220, 30)

        # Simulator with scheduler that always returns an empty
        # schedule.
        self.simulator = acnsim.Simulator(
            self.network,
            EmptyScheduler(),
            self.event_queue,
            datetime(2019, 1, 1),
            verbose=False,
        )

        self.simulator.run()
 def build(self):
     """ Build experiment from configuration. """
     events = self.get_events()
     network = self.get_charging_network()
     sch = self.get_scheduling_algorithm()
     signals = {"tariff": TimeOfUseTariff(self.tariff_name)}
     return acnsim.Simulator(network,
                             sch,
                             events,
                             self.start,
                             period=self.period,
                             signals=signals)
Пример #5
0
    def setUpClass(cls) -> None:
        API_KEY = "DEMO_TOKEN"
        tz = pytz.timezone("America/Los_Angeles")
        period = 5  # minutes
        voltage = 208  # volts
        default_battery_power = 32 * voltage / 1000  # kW
        site = "caltech"
        basic_evse = False
        start = "9-01-2018"
        end = "9-02-2018"
        force_feasible = True

        start_time = tz.localize(datetime.strptime(start, "%m-%d-%Y"))
        end_time = tz.localize(datetime.strptime(end, "%m-%d-%Y"))

        events = acnsim.acndata_events.generate_events(
            API_KEY,
            site,
            start_time,
            end_time,
            period,
            voltage,
            default_battery_power,
            force_feasible=force_feasible,
        )
        cn = acnsim.network.sites.caltech_acn(
            basic_evse=basic_evse, voltage=voltage, transformer_cap=60
        )
        quick_charge_obj = [
            ObjectiveComponent(quick_charge),
            ObjectiveComponent(equal_share, 1e-12),
        ]

        cls.alg = AdaptiveSchedulingAlgorithm(
            quick_charge_obj, solver=cp.ECOS, quantize=True, uninterrupted_charging=True
        )
        cls.sim = acnsim.Simulator(
            cn, cls.alg, events, start_time, period=period, verbose=False
        )
        cls.sim.run()
Пример #6
0
    def setUpClass(cls) -> None:
        API_KEY = "DEMO_TOKEN"
        tz = pytz.timezone("America/Los_Angeles")
        period = 5  # minutes
        voltage = 208  # volts
        default_battery_power = 32 * voltage / 1000  # kW
        site = "caltech"
        basic_evse = True
        start = "9-01-2019"
        end = "9-02-2019"
        force_feasible = True

        start_time = tz.localize(datetime.strptime(start, "%m-%d-%Y"))
        end_time = tz.localize(datetime.strptime(end, "%m-%d-%Y"))

        events = acnsim.acndata_events.generate_events(
            API_KEY,
            site,
            start_time,
            end_time,
            period,
            voltage,
            default_battery_power,
            force_feasible=force_feasible,
        )
        cn = acnsim.network.sites.caltech_acn(basic_evse=basic_evse, voltage=voltage)

        quick_charge_obj = [ObjectiveComponent(quick_charge)]
        cls.alg = AdaptiveChargingAlgorithmOffline(
            quick_charge_obj, solver=cp.ECOS, enforce_energy_equality=True
        )
        cls.alg.register_events(events)
        cls.sim = acnsim.Simulator(
            cn, cls.alg, events, start_time, period=period, verbose=False
        )
        cls.alg.solve()
        cls.sim.run()
Пример #7
0
def _random_sim_builder(algorithm: Optional[BaseAlgorithm],
                        interface_type: type) -> Simulator:
    timezone = pytz.timezone("America/Los_Angeles")
    start = timezone.localize(datetime(2018, 9, 5))
    period = 1

    # Make random event queue
    cn = acnsim.sites.simple_acn(["EVSE-001", "EVSE-002"],
                                 aggregate_cap=32 * 208 / 1000)
    event_list = []
    for station_id in cn.station_ids:
        event_list.extend(random_plugin(10, 100, station_id))
    event_queue = events.EventQueue(event_list)

    # Simulation to be wrapped
    return acnsim.Simulator(
        deepcopy(cn),
        algorithm,
        deepcopy(event_queue),
        start,
        period=period,
        verbose=False,
        interface_type=interface_type,
    )
Пример #8
0
cn = acnsim.sites.caltech_acn(basic_evse=True, voltage=voltage)

# -- Events ------------------------------------------------------------------------------------------------------------
API_KEY = 'DEMO_TOKEN'
events = acnsim.acndata_events.generate_events(API_KEY, site, start, end,
                                               period, voltage,
                                               default_battery_power)

# -- Scheduling Algorithm ----------------------------------------------------------------------------------------------
sch = EarliestDeadlineFirstAlgo(increment=1)
sch2 = algorithms.SortedSchedulingAlgo(algorithms.earliest_deadline_first)

# -- Simulator ---------------------------------------------------------------------------------------------------------
sim = acnsim.Simulator(deepcopy(cn),
                       sch,
                       deepcopy(events),
                       start,
                       period=period,
                       verbose=True)
sim.run()

# For comparison we will also run the builtin earliest deadline first algorithm
sim2 = acnsim.Simulator(deepcopy(cn),
                        sch2,
                        deepcopy(events),
                        start,
                        period=period)
sim2.run()

# -- Analysis ----------------------------------------------------------------------------------------------------------
# We can now compare the two algorithms side by side by looking that the plots of aggregated current.
# We see from these plots that our implementation matches th included one quite well. If we look closely however, we
Пример #9
0
    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",
            ],
        }
Пример #10
0
    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'
            ]
        }
Пример #11
0
API_KEY = "DEMO_TOKEN"

# An EventQueue is a special container which stores the events for the simulation. In this case we use the
# acndata_events utility to pre-fill the event queue based on real events in the Caltech Charging Dataset.
events = acnsim.acndata_events.generate_events(API_KEY, site, start, end,
                                               period, voltage,
                                               default_battery_power)

# -- Scheduling Algorithm ----------------------------------------------------------------------------------------------
# For this simple experiment we will use the predefined Uncontrolled Charging algorithm. We will cover more advanced
# algorithms and how to define a custom algorithm in future tutorials.
sch = algorithms.UncontrolledCharging()

# -- Simulator ---------------------------------------------------------------------------------------------------------
# We can now load the simulator enviroment with the network, scheduler, and events we have already defined.
sim = acnsim.Simulator(cn, sch, events, start, period=period)

# To execute the simulation we simply call the run() function.
sim.run()

# -- Analysis ----------------------------------------------------------------------------------------------------------
# After running the simulation, we can analyze the results using data stored in the simulator.

# Find percentage of requested energy which was delivered.
total_energy_prop = acnsim.proportion_of_energy_delivered(sim)
print(
    "Proportion of requested energy delivered: {0}".format(total_energy_prop))

# Find peak aggregate current during the simulation
print("Peak aggregate current: {0} A".format(sim.peak))
Пример #12
0
# # Scheduling Algorithm

# In[6]:


algorithm = algorithms.UncontrolledCharging()
# Alternative algorithms: RoundRobin, earliest_deadline_first, first_come_first_served, 
# largest_remaining_processing_time, last_come_first_served, least_laxity_first


# # Simulation

# In[7]:


sim = acnsim.Simulator(cn, algorithm, events, start, period=period, verbose=False)
sim.run()


# # Analysis

# In[8]:


def analyze_simulation(sim):
    total_energy_prop = acnsim.proportion_of_energy_delivered(sim)
    print('Proportion of requested energy delivered: {0}'.format(total_energy_prop))
    print('Peak aggregate current: {0} A'.format(sim.peak))
    # Plotting aggregate current
    agg_current = acnsim.aggregate_current(sim)
    plt.plot(agg_current)