1 | #--------------------------------------------------------------------------------------
|
---|
2 |
|
---|
3 | ## @package mlx.gates
|
---|
4 | #
|
---|
5 | # The module to handle the LHBP gate information.
|
---|
6 | #
|
---|
7 |
|
---|
8 | #--------------------------------------------------------------------------------------
|
---|
9 |
|
---|
10 | class 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 |
|
---|
49 | class 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 |
|
---|
123 | def 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 |
|
---|
135 | def 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
|
---|
145 | lhbpGates = Gates()
|
---|
146 |
|
---|
147 | lhbpGates.add(Gate("R101", "1", "S"))
|
---|
148 | lhbpGates.add(Gate("R102", "1", "S"))
|
---|
149 | lhbpGates.add(Gate("R103", "1", "S"))
|
---|
150 | lhbpGates.add(Gate("R104", "1", "S",
|
---|
151 | availableFn = getAvailableIf(othersAvailable = ["R105"])))
|
---|
152 | lhbpGates.add(Gate("R105", "1", "S",
|
---|
153 | availableFn = getAvailableIf(othersAvailable = ["R104", "R106"])))
|
---|
154 | lhbpGates.add(Gate("R106", "1", "S",
|
---|
155 | availableFn = getAvailableIf(othersAvailable = ["R105", "R108"])))
|
---|
156 | lhbpGates.add(Gate("R107", "1", "S",
|
---|
157 | availableFn = getAvailableIf(othersAvailable = ["R108"])))
|
---|
158 | lhbpGates.add(Gate("R108", "1", "S",
|
---|
159 | availableFn = getAvailableIf(othersAvailable = ["R106", "R107"])))
|
---|
160 |
|
---|
161 | lhbpGates.addSpace()
|
---|
162 | lhbpGates.add(Gate("R110", "1", "S",
|
---|
163 | availableFn = getAvailableIf(othersAvailable = ["R111"])))
|
---|
164 | lhbpGates.add(Gate("R111", "1", "S",
|
---|
165 | availableFn = getAvailableIf(othersAvailable = ["R110", "R112"])))
|
---|
166 | lhbpGates.add(Gate("R112", "1", "S",
|
---|
167 | availableFn = getAvailableIf(othersAvailable = ["R111"])))
|
---|
168 | lhbpGates.add(Gate("R113", "1", "S",
|
---|
169 | availableFn = getAvailableIf(othersAvailable = ["R112", "R114"])))
|
---|
170 | lhbpGates.add(Gate("R114", "1", "S",
|
---|
171 | availableFn = getAvailableIf(othersAvailable = ["R113"])))
|
---|
172 | lhbpGates.add(Gate("R115", "1", "S"))
|
---|
173 | lhbpGates.add(Gate("R116", "1", "S",
|
---|
174 | availableFn = getAvailableIf(othersAvailable = ["R117"])))
|
---|
175 | lhbpGates.add(Gate("R117", "1", "S",
|
---|
176 | availableFn = getAvailableIf(othersAvailable = ["R116", "R117A"])))
|
---|
177 | lhbpGates.add(Gate("R117A", "1", "S",
|
---|
178 | availableFn = getAvailableIf(othersAvailable = ["R116", "R117"])))
|
---|
179 | lhbpGates.addNewColumn()
|
---|
180 |
|
---|
181 | lhbpGates.add(Gate("G150", "1", "S"))
|
---|
182 | lhbpGates.add(Gate("G151", "1", "S"))
|
---|
183 | lhbpGates.add(Gate("G152", "1", "S"))
|
---|
184 | lhbpGates.add(Gate("G153", "1", "S"))
|
---|
185 | lhbpGates.add(Gate("G154", "1", "S"))
|
---|
186 | lhbpGates.add(Gate("G155", "1", "S"))
|
---|
187 |
|
---|
188 | lhbpGates.addSpace()
|
---|
189 | lhbpGates.add(Gate("G170", "1", "S"))
|
---|
190 | lhbpGates.add(Gate("G171", "1", "S"))
|
---|
191 | lhbpGates.add(Gate("G172", "1", "S"))
|
---|
192 | lhbpGates.addNewColumn()
|
---|
193 |
|
---|
194 | lhbpGates.add(Gate("31", "2B", "G"))
|
---|
195 | lhbpGates.add(Gate("32", "2B", "G"))
|
---|
196 | lhbpGates.add(Gate("33", "2B", "G"))
|
---|
197 | lhbpGates.add(Gate("34", "2B", "G",
|
---|
198 | availableFn = getAvailableIf(othersAvailable = ["34L", "34R"])))
|
---|
199 | lhbpGates.add(Gate("34L", "2B", "G",
|
---|
200 | availableFn = getAvailableIf(othersAvailable = ["34", "34R"])))
|
---|
201 | lhbpGates.add(Gate("34R", "2B", "G",
|
---|
202 | availableFn = getAvailableIf(othersAvailable = ["34L", "34"])))
|
---|
203 | lhbpGates.add(Gate("35", "2B", "G",
|
---|
204 | availableFn = getAvailableIf(othersAvailable = ["35L", "35R"])))
|
---|
205 | lhbpGates.add(Gate("35L", "2B", "G",
|
---|
206 | availableFn = getAvailableIf(othersAvailable = ["35", "35R"])))
|
---|
207 | lhbpGates.add(Gate("35R", "2B", "G",
|
---|
208 | availableFn = getAvailableIf(othersAvailable = ["35L", "35"])))
|
---|
209 | lhbpGates.add(Gate("36", "2B", "G",
|
---|
210 | availableFn = getAvailableIf(othersAvailable = ["36L", "36R"])))
|
---|
211 | lhbpGates.add(Gate("36L", "2B", "G",
|
---|
212 | availableFn = getAvailableIf(othersAvailable = ["36", "36R"])))
|
---|
213 | lhbpGates.add(Gate("36R", "2B", "G",
|
---|
214 | availableFn = getAvailableIf(othersAvailable = ["36L", "36"])))
|
---|
215 | lhbpGates.addSpace()
|
---|
216 |
|
---|
217 | lhbpGates.add(Gate("37", "2B", "G"))
|
---|
218 | lhbpGates.add(Gate("38", "2B", "G"))
|
---|
219 | lhbpGates.add(Gate("39", "2B", "G",
|
---|
220 | availableFn = getAvailableIf(othersAvailable = ["37L", "37R"])))
|
---|
221 | lhbpGates.add(Gate("39L", "2B", "G",
|
---|
222 | availableFn = getAvailableIf(othersAvailable = ["37", "37R"])))
|
---|
223 | lhbpGates.add(Gate("39R", "2B", "G",
|
---|
224 | availableFn = getAvailableIf(othersAvailable = ["37L", "37"])))
|
---|
225 | lhbpGates.addNewColumn()
|
---|
226 |
|
---|
227 | lhbpGates.add(Gate("42", "2A", "G"))
|
---|
228 | lhbpGates.add(Gate("43", "2A", "G"))
|
---|
229 | lhbpGates.add(Gate("44", "2A", "G"))
|
---|
230 | lhbpGates.add(Gate("45", "2A", "G"))
|
---|
231 | lhbpGates.addSpace()
|
---|
232 |
|
---|
233 | lhbpGates.add(Gate("R210", "2A", "S",
|
---|
234 | availableFn = getAvailableIf(othersAvailable = ["R212A"]),
|
---|
235 | taxiThrough = True))
|
---|
236 | lhbpGates.add(Gate("R211", "2A", "S",
|
---|
237 | availableFn = getAvailableIf(othersAvailable = ["R212A"]),
|
---|
238 | taxiThrough = True))
|
---|
239 | lhbpGates.add(Gate("R212", "2A", "S",
|
---|
240 | availableFn = getAvailableIf(othersAvailable = ["R212A"]),
|
---|
241 | taxiThrough = True))
|
---|
242 | lhbpGates.add(Gate("R212A", "2A", "S",
|
---|
243 | availableFn = getAvailableIf(othersAvailable = ["R210", "R211", "R212"]),
|
---|
244 | taxiThrough = True))
|
---|
245 | lhbpGates.addSpace()
|
---|
246 |
|
---|
247 | lhbpGates.add(Gate("R220", "2B", "S"))
|
---|
248 | lhbpGates.add(Gate("R221", "2B", "S"))
|
---|
249 | lhbpGates.add(Gate("R222", "2B", "S"))
|
---|
250 | lhbpGates.add(Gate("R223", "2B", "S"))
|
---|
251 | lhbpGates.addSpace()
|
---|
252 |
|
---|
253 | lhbpGates.add(Gate("R224", "2A", "S"))
|
---|
254 | lhbpGates.add(Gate("R225", "2A", "S"))
|
---|
255 | lhbpGates.add(Gate("R226", "2A", "S"))
|
---|
256 | lhbpGates.add(Gate("R227", "2A", "S"))
|
---|
257 | lhbpGates.addNewColumn()
|
---|
258 |
|
---|
259 | lhbpGates.add(Gate("R270", "2A", "S"))
|
---|
260 | lhbpGates.add(Gate("R271", "2A", "S"))
|
---|
261 | lhbpGates.add(Gate("R272", "2A", "S"))
|
---|
262 | lhbpGates.add(Gate("R273", "2A", "S"))
|
---|
263 | lhbpGates.add(Gate("R274", "2A", "S"))
|
---|
264 | lhbpGates.add(Gate("R275", "2A", "S"))
|
---|
265 | lhbpGates.add(Gate("R276", "2A", "S"))
|
---|
266 | lhbpGates.add(Gate("R277", "2A", "S"))
|
---|
267 | lhbpGates.add(Gate("R278", "2A", "S",
|
---|
268 | availableFn = getAvailableIf(othersAvailable = ["R278A"]),
|
---|
269 | taxiThrough = True))
|
---|
270 | lhbpGates.add(Gate("R278A", "2A", "S",
|
---|
271 | availableFn = getAvailableIf(othersAvailable = ["R278", "R279"]),
|
---|
272 | taxiThrough = True))
|
---|
273 | lhbpGates.add(Gate("R279", "2A", "S",
|
---|
274 | availableFn = getAvailableIf(othersAvailable = ["R278A"]),
|
---|
275 | taxiThrough = True))
|
---|