forked from Pouria-Nazemi/Elevator-Scheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevators.py
74 lines (74 loc) · 2.69 KB
/
elevators.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# import time, threading
#
#
# class elevator(threading.Thread):
#
# def __init__(self, name, head=1, staticList=[]):
# threading.Thread.__init__(self)
#
# self.inputs = []
# self.up = []
# self.down = []
# self.head = 1
# self.direction = "both"
# self.seekProcedure = []
# self.name = ("elevator" + str(name))
# self.inputs.extend(staticList)
# self.head = head
# self.start()
#
# def inputsHandling(self):
# while not len(self.inputs) == 0:
# input = self.inputs.pop(0)
# if (input > self.head):
# if not self.up.__contains__(input):
# self.up.append(input)
# self.up.sort()
# else:
# if not self.down.__contains__(input):
# self.down.append(input)
# self.down.sort(reverse=True)
#
# def run(self):
# while (True):
# self.inputsHandling()
# if len(self.up) == 0 and len(self.down) == 0:
# self.direction = "both"
# continue
#
# if self.direction == "UP" or self.direction == "both":
# if not len(self.up) == 0:
# goalFloor = self.up[0]
# if goalFloor == self.head:
# self.seekProcedure.append(goalFloor)
# # from Graphic_Interface import inputElePlan
# print(self.name + " arrived to floor " + str(goalFloor) + "\n") #TODO
# self.up.pop(0)
# else:
# self.head = self.head + 1
# else:
# self.direction = "DOWN"
#
# if self.direction == "DOWN" or self.direction == "both":
# if not len(self.down) == 0:
# goalFloor = self.down[0]
# if goalFloor == self.head:
# self.seekProcedure.append(goalFloor)
# print(self.name + " arrived to floor " + str(goalFloor) + "\n") #TODO
# self.down.pop(0)
# else:
# self.head = self.head - 1
# else:
# self.direction = "UP"
# time.sleep(3) #TODO change time
#
# def addInput(self, floor):
# self.inputs.append(floor)
#
# def checkWhichFirst(self):
# if(len(self.up) != 0 and len(self.down) != 0 and self.direction == "both"):
# if(abs(self.head - self.up[0]) < self.head - self.down[0]):
# self.direction = "UP"
# else:
# self.direction = "DOWN"
#