示例#1
0
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)
    plt.xlabel('Time (periods)')
    plt.ylabel('Current (A)')
    plt.title('Total Aggregate Current')
    plt.savefig('output.png')
    plt.show()
示例#2
0
                        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
# might see a small difference. This is because the included algorithm uses a more efficient bisection based method
# instead of our simpler linear search to find a feasible rate.

# Get list of datetimes over which the simulations were run.
sim_dates = mdates.date2num(acnsim.datetimes_array(sim))
sim2_dates = mdates.date2num(acnsim.datetimes_array(sim2))

# Set locator and formatter for datetimes on x-axis.
locator = mdates.AutoDateLocator(maxticks=6)
formatter = mdates.ConciseDateFormatter(locator)

fig, axs = plt.subplots(1, 2, sharey=True, sharex=True)
axs[0].plot(sim_dates, acnsim.aggregate_current(sim), label='Our EDF')
axs[1].plot(sim2_dates, acnsim.aggregate_current(sim2), label='Included EDF')
axs[0].set_title('Our EDF')
axs[1].set_title('Included EDF')
for ax in axs:
    ax.set_ylabel('Current (A)')
    for label in ax.get_xticklabels():
        label.set_rotation(40)
    ax.xaxis.set_major_locator(locator)
    ax.xaxis.set_major_formatter(formatter)

plt.show()
示例#3
0
 def test_aggregate_current(self) -> None:
     np.testing.assert_allclose(
         acnsim.aggregate_current(self.sim),
         np.array(self.edf_algo_true_analysis_dict["aggregate_current"]),
     )
示例#4
0
# -- 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))

# Plotting aggregate current
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()
示例#5
0
]
eval_env: DummyVecEnv = DummyVecEnv([
    lambda: FlattenObservation(
        CustomSimEnv(
            evaluation_algorithm.interface,
            observation_objects,
            action_object,
            reward_functions,
        ))
])
evaluation_algorithm.register_env(eval_env)
evaluation_algorithm.register_model(StableBaselinesRLModel(model))

evaluation_simulation.run()
edf_simulation.run()
rr_simulation.run()

fig, axs = plt.subplots(3)
rl = axs[0].plot(evaluation_simulation.charging_rates[0], label="RL Agent")
edf = axs[0].plot(rr_simulation.charging_rates[0], label="EDF")
axs[1].plot(evaluation_simulation.charging_rates[1])
axs[1].plot(rr_simulation.charging_rates[1])
axs[2].plot(acnsim.aggregate_current(evaluation_simulation))
axs[2].plot(acnsim.aggregate_current(rr_simulation))

axs[0].title.set_text("Current, Line 1")
axs[1].title.set_text("Current, Line 2")
axs[2].title.set_text("Total Current")

plt.show()
示例#6
0
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
# might see a small difference. This is because the included algorithm uses a more efficient bisection based method
# instead of our simpler linear search to find a feasible rate.
fig, ax = plt.subplots(1, 2, sharey=True, sharex=True)
ax[0].plot(acnsim.aggregate_current(sim), label='Our EDF')
ax[1].plot(acnsim.aggregate_current(sim2), label='Included EDF')
ax[1].set_xlabel('Time (periods)')
ax[0].set_ylabel('Current (A)')
ax[1].set_ylabel('Current (A)')
ax[0].set_title('Our EDF')
ax[1].set_title('Included EDF')
plt.show()