-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStation.py
43 lines (34 loc) · 1.09 KB
/
Station.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
41
42
43
from __future__ import division;
import math;
import random;
import Data;
import SimObject;
import Passenger;
import Service;
stations = {};
class Station(SimObject.SimObject):
def __init__(self, attrs, name):
SimObject.SimObject.__init__(self, attrs);
self.name = name;
self.platforms = [];
self.nodes = [];
self.passengers = [];
self.departures = [];
def AddPlatform(self, place):
self.platforms.append(place);
self.nodes.append(Data.places[place]);
Data.nodes[Data.places[place]].station = self;
def HasPlatform(self, node):
return node in self.nodes;
def Update(self):
passengersPerTick = Data.timeStep / 10;
if random.random() < (passengersPerTick - math.floor(passengersPerTick)):
for i in range(0, int(math.ceil(passengersPerTick))):
self.passengers.append(Passenger.Passenger(self));
# all the services that leave said node after said time
def DeparturesFrom(self, time):
for service in self.departures:
for stop in Service.services[service].orders:
if stop[0] > time and Data.Place(stop[1]) in self.platforms:
yield service;
break;