-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathChargingStation.py
40 lines (31 loc) · 1008 Bytes
/
ChargingStation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import simpy
import random
import logging
import numpy as np
import pandas as pd
# import matplotlib.pyplot as plt
# from Router import Network
# import time
class ChargingStation:
def __init__(self, env, station_id):
self.env = env
self.station_id = station_id
self.location = None
self.capacity = 0
self.n_bikes = 0
self.bikes = []
def set_location(self, lat, lon):
self.location = np.array([lat, lon])
def set_capacity(self, capacity):
self.capacity = capacity
def has_space(self):
return self.capacity - self.n_bikes > 0
def attach_bike(self, bike_id): # What hapens if no docks?
if self.has_space():
self.n_bikes += 1
self.bikes.append(bike_id)
else:
logging.info("[%.2f] Charging station %d has no spaces available" % (self.env.now, self.station_id))
def detach_bike(self, bike_id):
self.n_bikes -= 1
self.bikes.remove(bike_id)