-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkplaceOrSchool.py
57 lines (48 loc) · 3.14 KB
/
WorkplaceOrSchool.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
from Location import Location
from intervaltree import IntervalTree
import math
import numpy as np
class WorkplaceOrSchool(Location):
def initLocations(self):
self.rowCapacity = self.constantsAndRandom.getRandomNumberRowCapacityOfWorkplace_1()
self.capacity = self.rowCapacity**2
self.distanceBetweenSeats = self.constantsAndRandom.getRandomDistanceBetweenWorkplaceOrSchoolSeats()
def initDayCustom(self):
self.availableSeats = np.arange(1, self.capacity+1)
np.random.shuffle(self.availableSeats)
self.availableSeats = list(self.availableSeats)
def noteVisitFromPersonCustom(self,person):
person.daysInWorkplaceOrSchool.append(self.constantsAndRandom.time_day)
def assignPhysicsNewVisitor(self, person, timeToday):
indexOfSeat = self.availableSeats.pop(0)
seatXindex = indexOfSeat % self.rowCapacity
seatYindex = int((indexOfSeat - seatXindex) / self.rowCapacity)
person.workOrSchool_PositionSeat = (self.distanceBetweenSeats*(seatXindex+1),self.distanceBetweenSeats*(seatYindex+1))
person.workOrSchool_XcoordinateAisle = self.distanceBetweenSeats*(seatXindex+0.5)
person.position = (person.workOrSchool_XcoordinateAisle,0)
person.Xspeed = 0 # meters per millisecond
person.Yspeed = self.constantsAndRandom.WorklocationManager_WalkingSpeedMetersPerMilliSecond # meters per millisecond
person.Yacceleration = 0 # meters per millisecond^2
person.Xacceleration = 0 # meters per millisecond^2
def assignPhysicsUpdate(self, person, timeToday):
if(timeToday <= self.constantsAndRandom.WorklocationVisit_openingTime+self.constantsAndRandom.WorklocationVisit_duration/2): # arriving
if(person.Yspeed > 0 and person.position[1] >= person.workOrSchool_PositionSeat[1]): # walked to far in y direction
if(person.position[1] > person.workOrSchool_PositionSeat[1]):
person.position = (person.position[0],person.workOrSchool_PositionSeat[1])
person.Yspeed = 0
person.Xspeed = self.constantsAndRandom.WorklocationManager_WalkingSpeedMetersPerMilliSecond
if(person.Xspeed > 0 and person.position[0] >= person.workOrSchool_PositionSeat[0]): # walked to far in x direction
if(person.position[0] > person.workOrSchool_PositionSeat[0]):
person.position = (person.workOrSchool_PositionSeat[0],person.position[1])
person.Xspeed = 0
else: # leaving
if(timeToday == person.timeTodayWorkplaceOrSchoolVisit + self.constantsAndRandom.WorklocationVisit_duration):
person.Xspeed = - self.constantsAndRandom.WorklocationManager_WalkingSpeedMetersPerMilliSecond
if(person.Xspeed < 0 and person.position[0] <= person.workOrSchool_XcoordinateAisle): # walked to far in x direction
if(person.position[0] < person.workOrSchool_XcoordinateAisle):
person.position = (person.workOrSchool_XcoordinateAisle,person.position[1])
person.Xspeed = 0
person.Yspeed = - self.constantsAndRandom.WorklocationManager_WalkingSpeedMetersPerMilliSecond
if(person.position[1] <= 0):
self.visitorsNowList.remove(person)