zach401 / acnportal

Research tools for the Adaptive Charging Network
BSD 3-Clause "New" or "Revised" License
75 stars 32 forks source link

BUG: unexpected zero output current #102

Open Mosa94 opened 3 years ago

Mosa94 commented 3 years ago

I have stumbled upon a strange output from acnsim. To be sure that it is not an issue with me messing around with code, I created a new virtual environment in python with the latest acnportal code from github. And the problem is still there

Description Basically it seems like after a while (around 100 iterations) the simulation does not take into account the pilot signals to the EVSEs (the total aggregate current is always 0).

To Reproduce

import pytz
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
from acnportal import acnsim
from acnportal import algorithms
import random

# Timezone of the ACN we are using.
timezone = pytz.timezone('America/Los_Angeles')

# Start and End times are used when collecting data.
start = timezone.localize(datetime(2020, 10, 5))
#end = timezone.localize(datetime(2018, 9, 6))

# How long each time discrete time interval in the simulation should be.

#network.
voltage = 208  # volts
aggregate_cap=150 #kW
evse_names=["EVSE-001"]#,"EVSE-002"]
#which implies
cap_current=aggregate_cap*1000/voltage

cn = acnsim.network.sites.simple_acn(evse_names,voltage=voltage, ...
aggregate_cap=aggregate_cap)

#the plugin events function is taken from from gym-acnsim
#it is crucial that it lasts enough iterations
iterations=500

def random_plugin(num, time_limit, evse, laxity_ratio=1/2,
                  max_rate=32, voltage=voltage, period=1):
    """ Returns a list of num random plugin events occurring anytime from time 0
    to time_limit. Each plugin has a random arrival and departure under the time
    limit, and a satisfiable requested energy assuming no other cars plugged in.
    Each EV has initial laxity equal to half the staying duration unless
    otherwise specified.

    The plugins occur for a single EVSE, whose maximal rate and voltage are
    assumed to be 32 A and  208 V, respectively, unless otherwise specified.

    Args: TODO
    Return: TODO
    """
    out_event_lst = [None] * num
    times = []
    i = 0
    while i < 2 * num:
        rnum = random.randint(0, time_limit)
        if rnum not in times:
            times.append(rnum)
            i += 1
    times = sorted(times)
    battery = acnsim.models.Battery(100, 0, 100)
    for i in range(num):
        arrival_time = times[2*i]
        departure_time = times[2*i+1]
        requested_energy = (
            (departure_time - arrival_time) / (60 / period) 
            * max_rate * voltage / (1 / laxity_ratio)
        )
        ev = acnsim.models.EV(arrival_time, departure_time, requested_energy,
                       evse, f'rs-{evse}-{i}', battery)
        out_event_lst[i] = acnsim.events.PluginEvent(arrival_time, ev)
    return out_event_lst

event_list = []
for station_id in cn.station_ids:
    event_list.extend(random_plugin(100, iterations, station_id))
event_queue = acnsim.events.EventQueue(event_list)
events = acnsim.events.EventQueue(event_list)

#print the pluginevents time
for i in range(len(events._queue)):
    print(events._queue[i][0])

sch = algorithms.UncontrolledCharging()
sim = acnsim.Simulator(cn, sch, events, start=start, period=period, verbose=True)
sim.run()

agg_current = acnsim.aggregate_current(sim)
plt.plot(agg_current)
plt.xlabel('Time (periods)')
plt.ylabel('Current (A)')
plt.title('Total Aggregate Current')
plt.show()

agg_power = acnsim.aggregate_power(sim)
plt.plot(agg_power)
plt.xlabel('Time (periods)')
plt.ylabel('Current (A)')
plt.title('Total Aggregate Power')
plt.show()

Expected behavior I expect total aggregate current (and power) to be roughly evenly distributed across time.

Screenshots Plots for the run: tot_agg_curr_bug tot_agg_pow_bug

System Info

Additional Info This are the iterations of plugin events for the reported run: 5 8 11 14 17 19 24 30 38 44 52 57 59 63 65 69 71 75 79 83 86 90 93 98 100 105 115 119 127 132 136 140 144 156 162 170 174 180 183 189 193 197 201 205 218 223 229 239 242 249 254 262 266 268 274 276 279 287 295 299 305 310 313 317 319 321 328 332 334 336 343 351 354 358 362 366 371 378 383 390 393 401 405 419 424 428 431 433 435 437 439 445 449 454 462 466 476 488 491 493