Simulating out-of-energy occurrences for an electric car
Electric cars are getting more and more popular these days. However, even though they are cheaper to run, the range of the car somewhat limits its use to travel long distance, at least until a sufficient infrastructure is in place to recharge the car along the way.
In this recipe, we will simulate out-of-power situations for an electric car. We start by randomly placing the recharge stations along the way of the car and then simulating the recharge situations. In this recipe, we will allow the driver of the car to drive the car without fully recharging.
Getting ready
To execute this recipe, you will need SimPy
and NumPy
. No other prerequisites are required.
How to do it…
As in the previous recipe, we start by defining the environment and all its agents (the sim_recharge.py
file):
import numpy as np import simpy if __name__ == '__main__': # what is the simulation horizon (in minutes) SIM_TIME = 10 * 60 * 60 # 10...