source: src/mlx/gates.py@ 1151:2ef1ab0b28cb

python3
Last change on this file since 1151:2ef1ab0b28cb was 1151:2ef1ab0b28cb, checked in by István Váradi <ivaradi@…>, 7 months ago

Gate information is updated to reflect the current situation (re #386).

File size: 10.4 KB
Line 
1#--------------------------------------------------------------------------------------
2
3## @package mlx.gates
4#
5# The module to handle the LHBP gate information.
6#
7
8#--------------------------------------------------------------------------------------
9
10class Gate(object):
11 """Information about a gate."""
12 def __init__(self, number, terminal, type,
13 availableFn = None, taxiThrough = False):
14 """Construct the gate with the given information.
15
16 number is the gate's number as a string (as it can contain letters).
17 terminal is the terminal the gate belongs to (not used currently).
18 type is the gate's type: G for gate, S for stand.
19 availableFn is a function that can determine if the gate is available based on
20 the statuses of other gates. Its arguments are:
21 - a collection of the gates, and
22 - a set of occupied gate numbers."""
23 self._number = number
24 self._terminal = terminal
25 self._type = type
26 self._availableFn = availableFn
27 self._taxiThrough = taxiThrough
28
29 @property
30 def number(self):
31 """Get the number of the gate."""
32 return self._number
33
34 @property
35 def taxiThrough(self):
36 """Get if the gate is a taxi through one."""
37 return self._taxiThrough
38
39 def isAvailable(self, gates, occupiedGateNumbers):
40 """Determine if this gate is available given the set of gates and
41 occupied gate numbers."""
42 if self._number in occupiedGateNumbers:
43 return False
44 return True if self._availableFn is None else \
45 self._availableFn(gates, occupiedGateNumbers)
46
47#--------------------------------------------------------------------------------------
48
49class Gates(object):
50 """A collection of gates."""
51 # Display info type: a gate (number)
52 DISPLAY_GATE=1
53
54 # Display info type: a space
55 DISPLAY_SPACE=2
56
57 # Display info type: a new column
58 DISPLAY_NEW_COLUMN=3
59
60 def __init__(self):
61 """Construct the gate collection."""
62 self._gates = []
63 self._displayInfos = []
64 self._numColumns = 1
65 self._numRows = 0
66 self._numRowsInColumn = 0
67
68 @property
69 def gates(self):
70 """Get an iterator over the gates."""
71 return iter(self._gates)
72
73 @property
74 def displayInfos(self):
75 """Get an iterator over the display info tuples.
76
77 Each tuple consists of
78 - a type (one of the DISPLAY_XXX constants), and
79 - an additional data (the gate for DISPLAY_GATE, None for others)."""
80 return iter(self._displayInfos)
81
82 @property
83 def numRows(self):
84 """Get the number of rows."""
85 return self._numRows
86
87 @property
88 def numColumns(self):
89 """Get the number of columns."""
90 return self._numColumns
91
92 def add(self, gate):
93 """Add a gate to the collection."""
94 self._gates.append(gate)
95 self._displayInfos.append((Gates.DISPLAY_GATE, gate))
96 self._addRow()
97
98 def find(self, gateNumber):
99 """Find a gate by its number."""
100 for gate in self._gates:
101 if gate.number == gateNumber:
102 return gate
103
104 def addSpace(self):
105 """Add a space between subsequent gates."""
106 self._displayInfos.append((Gates.DISPLAY_SPACE, None))
107 self._addRow()
108
109 def addNewColumn(self):
110 """Start a new column of gates."""
111 self._displayInfos.append((Gates.DISPLAY_NEW_COLUMN, None))
112 self._numRowsInColumn = 0
113 self._numColumns += 1
114
115 def _addRow(self):
116 """Add a new row."""
117 self._numRowsInColumn += 1
118 if self._numRowsInColumn > self._numRows:
119 self._numRows = self._numRowsInColumn
120
121#--------------------------------------------------------------------------------------
122
123def availableIf(occupiedGateNumbers, othersAvailable = []):
124 """Determine if a gate is available.
125
126 othersAvailable is a list of numbers of gates, that must be available so
127 that the one we are considering is available."""
128 for otherNumber in othersAvailable:
129 if otherNumber in occupiedGateNumbers:
130 return False
131 return True
132
133#--------------------------------------------------------------------------------------
134
135def getAvailableIf(othersAvailable = []):
136 """Get a function that determines if a gate is available based on the
137 statuses of other gates."""
138 return lambda gates, occupiedGateNumbers: availableIf(occupiedGateNumbers,
139 othersAvailable =
140 othersAvailable)
141
142#--------------------------------------------------------------------------------------
143
144# The gates at LHBP
145lhbpGates = Gates()
146
147lhbpGates.add(Gate("R101", "1", "S"))
148lhbpGates.add(Gate("R102", "1", "S"))
149lhbpGates.add(Gate("R103", "1", "S"))
150lhbpGates.add(Gate("R104", "1", "S",
151 availableFn = getAvailableIf(othersAvailable = ["R105"])))
152lhbpGates.add(Gate("R105", "1", "S",
153 availableFn = getAvailableIf(othersAvailable = ["R104", "R106"])))
154lhbpGates.add(Gate("R106", "1", "S",
155 availableFn = getAvailableIf(othersAvailable = ["R105", "R108"])))
156lhbpGates.add(Gate("R107", "1", "S",
157 availableFn = getAvailableIf(othersAvailable = ["R108"])))
158lhbpGates.add(Gate("R108", "1", "S",
159 availableFn = getAvailableIf(othersAvailable = ["R106", "R107"])))
160
161lhbpGates.addSpace()
162lhbpGates.add(Gate("R110", "1", "S",
163 availableFn = getAvailableIf(othersAvailable = ["R111"])))
164lhbpGates.add(Gate("R111", "1", "S",
165 availableFn = getAvailableIf(othersAvailable = ["R110", "R112"])))
166lhbpGates.add(Gate("R112", "1", "S",
167 availableFn = getAvailableIf(othersAvailable = ["R111"])))
168lhbpGates.add(Gate("R113", "1", "S",
169 availableFn = getAvailableIf(othersAvailable = ["R112", "R114"])))
170lhbpGates.add(Gate("R114", "1", "S",
171 availableFn = getAvailableIf(othersAvailable = ["R113"])))
172lhbpGates.add(Gate("R115", "1", "S"))
173lhbpGates.add(Gate("R116", "1", "S",
174 availableFn = getAvailableIf(othersAvailable = ["R117"])))
175lhbpGates.add(Gate("R117", "1", "S",
176 availableFn = getAvailableIf(othersAvailable = ["R116", "R117A"])))
177lhbpGates.add(Gate("R117A", "1", "S",
178 availableFn = getAvailableIf(othersAvailable = ["R116", "R117"])))
179lhbpGates.addNewColumn()
180
181lhbpGates.add(Gate("G150", "1", "S"))
182lhbpGates.add(Gate("G151", "1", "S"))
183lhbpGates.add(Gate("G152", "1", "S"))
184lhbpGates.add(Gate("G153", "1", "S"))
185lhbpGates.add(Gate("G154", "1", "S"))
186lhbpGates.add(Gate("G155", "1", "S"))
187
188lhbpGates.addSpace()
189lhbpGates.add(Gate("G170", "1", "S"))
190lhbpGates.add(Gate("G171", "1", "S"))
191lhbpGates.add(Gate("G172", "1", "S"))
192lhbpGates.addNewColumn()
193
194lhbpGates.add(Gate("31", "2B", "G"))
195lhbpGates.add(Gate("32", "2B", "G"))
196lhbpGates.add(Gate("33", "2B", "G"))
197lhbpGates.add(Gate("34", "2B", "G",
198 availableFn = getAvailableIf(othersAvailable = ["34L", "34R"])))
199lhbpGates.add(Gate("34L", "2B", "G",
200 availableFn = getAvailableIf(othersAvailable = ["34", "34R"])))
201lhbpGates.add(Gate("34R", "2B", "G",
202 availableFn = getAvailableIf(othersAvailable = ["34L", "34"])))
203lhbpGates.add(Gate("35", "2B", "G",
204 availableFn = getAvailableIf(othersAvailable = ["35L", "35R"])))
205lhbpGates.add(Gate("35L", "2B", "G",
206 availableFn = getAvailableIf(othersAvailable = ["35", "35R"])))
207lhbpGates.add(Gate("35R", "2B", "G",
208 availableFn = getAvailableIf(othersAvailable = ["35L", "35"])))
209lhbpGates.add(Gate("36", "2B", "G",
210 availableFn = getAvailableIf(othersAvailable = ["36L", "36R"])))
211lhbpGates.add(Gate("36L", "2B", "G",
212 availableFn = getAvailableIf(othersAvailable = ["36", "36R"])))
213lhbpGates.add(Gate("36R", "2B", "G",
214 availableFn = getAvailableIf(othersAvailable = ["36L", "36"])))
215lhbpGates.addSpace()
216
217lhbpGates.add(Gate("37", "2B", "G"))
218lhbpGates.add(Gate("38", "2B", "G"))
219lhbpGates.add(Gate("39", "2B", "G",
220 availableFn = getAvailableIf(othersAvailable = ["37L", "37R"])))
221lhbpGates.add(Gate("39L", "2B", "G",
222 availableFn = getAvailableIf(othersAvailable = ["37", "37R"])))
223lhbpGates.add(Gate("39R", "2B", "G",
224 availableFn = getAvailableIf(othersAvailable = ["37L", "37"])))
225lhbpGates.addNewColumn()
226
227lhbpGates.add(Gate("42", "2A", "G"))
228lhbpGates.add(Gate("43", "2A", "G"))
229lhbpGates.add(Gate("44", "2A", "G"))
230lhbpGates.add(Gate("45", "2A", "G"))
231lhbpGates.addSpace()
232
233lhbpGates.add(Gate("R210", "2A", "S",
234 availableFn = getAvailableIf(othersAvailable = ["R212A"]),
235 taxiThrough = True))
236lhbpGates.add(Gate("R211", "2A", "S",
237 availableFn = getAvailableIf(othersAvailable = ["R212A"]),
238 taxiThrough = True))
239lhbpGates.add(Gate("R212", "2A", "S",
240 availableFn = getAvailableIf(othersAvailable = ["R212A"]),
241 taxiThrough = True))
242lhbpGates.add(Gate("R212A", "2A", "S",
243 availableFn = getAvailableIf(othersAvailable = ["R210", "R211", "R212"]),
244 taxiThrough = True))
245lhbpGates.addSpace()
246
247lhbpGates.add(Gate("R220", "2B", "S"))
248lhbpGates.add(Gate("R221", "2B", "S"))
249lhbpGates.add(Gate("R222", "2B", "S"))
250lhbpGates.add(Gate("R223", "2B", "S"))
251lhbpGates.addSpace()
252
253lhbpGates.add(Gate("R224", "2A", "S"))
254lhbpGates.add(Gate("R225", "2A", "S"))
255lhbpGates.add(Gate("R226", "2A", "S"))
256lhbpGates.add(Gate("R227", "2A", "S"))
257lhbpGates.addNewColumn()
258
259lhbpGates.add(Gate("R270", "2A", "S"))
260lhbpGates.add(Gate("R271", "2A", "S"))
261lhbpGates.add(Gate("R272", "2A", "S"))
262lhbpGates.add(Gate("R273", "2A", "S"))
263lhbpGates.add(Gate("R274", "2A", "S"))
264lhbpGates.add(Gate("R275", "2A", "S"))
265lhbpGates.add(Gate("R276", "2A", "S"))
266lhbpGates.add(Gate("R277", "2A", "S"))
267lhbpGates.add(Gate("R278", "2A", "S",
268 availableFn = getAvailableIf(othersAvailable = ["R278A"]),
269 taxiThrough = True))
270lhbpGates.add(Gate("R278A", "2A", "S",
271 availableFn = getAvailableIf(othersAvailable = ["R278", "R279"]),
272 taxiThrough = True))
273lhbpGates.add(Gate("R279", "2A", "S",
274 availableFn = getAvailableIf(othersAvailable = ["R278A"]),
275 taxiThrough = True))
Note: See TracBrowser for help on using the repository browser.