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 getAvilableIf(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("1", "1", "S"))
|
---|
148 | lhbpGates.add(Gate("2", "1", "S"))
|
---|
149 | lhbpGates.add(Gate("3", "1", "S"))
|
---|
150 | lhbpGates.add(Gate("4", "1", "S"))
|
---|
151 | lhbpGates.add(Gate("5", "1", "S"))
|
---|
152 | lhbpGates.add(Gate("6", "1", "S"))
|
---|
153 | lhbpGates.add(Gate("25", "1", "S"))
|
---|
154 | lhbpGates.add(Gate("26", "1", "S"))
|
---|
155 | lhbpGates.add(Gate("27", "1", "S"))
|
---|
156 | lhbpGates.addSpace()
|
---|
157 |
|
---|
158 | lhbpGates.add(Gate("31", "2B", "G"))
|
---|
159 | lhbpGates.add(Gate("32", "2B", "G"))
|
---|
160 | lhbpGates.add(Gate("33", "2B", "G"))
|
---|
161 | lhbpGates.addNewColumn()
|
---|
162 |
|
---|
163 | lhbpGates.add(Gate("34", "2B", "G"))
|
---|
164 | lhbpGates.add(Gate("35", "2B", "G"))
|
---|
165 | lhbpGates.add(Gate("36", "2B", "G"))
|
---|
166 | lhbpGates.add(Gate("37", "2B", "G"))
|
---|
167 | lhbpGates.add(Gate("38", "2B", "G"))
|
---|
168 | lhbpGates.add(Gate("39", "2B", "G"))
|
---|
169 | lhbpGates.addSpace()
|
---|
170 |
|
---|
171 | lhbpGates.add(Gate("42", "2A", "G"))
|
---|
172 | lhbpGates.add(Gate("43", "2A", "G"))
|
---|
173 | lhbpGates.add(Gate("44", "2A", "G"))
|
---|
174 | lhbpGates.add(Gate("45", "2A", "G"))
|
---|
175 | lhbpGates.addNewColumn()
|
---|
176 |
|
---|
177 | lhbpGates.add(Gate("107", "1", "S"))
|
---|
178 | lhbpGates.add(Gate("108", "1", "S"))
|
---|
179 | lhbpGates.add(Gate("109", "1", "S"))
|
---|
180 | lhbpGates.add(Gate("R110", "1", "S",
|
---|
181 | availableFn = getAvilableIf(othersAvailable = ["R111"])))
|
---|
182 | lhbpGates.add(Gate("R111", "1", "S",
|
---|
183 | availableFn = getAvilableIf(othersAvailable = ["R110", "R112"])))
|
---|
184 | lhbpGates.add(Gate("R112", "1", "S",
|
---|
185 | availableFn = getAvilableIf(othersAvailable = ["R111"])))
|
---|
186 | lhbpGates.add(Gate("R113", "1", "S",
|
---|
187 | availableFn = getAvilableIf(othersAvailable = ["R114"])))
|
---|
188 | lhbpGates.add(Gate("R114", "1", "S",
|
---|
189 | availableFn = getAvilableIf(othersAvailable = ["R113"])))
|
---|
190 | lhbpGates.add(Gate("R115", "1", "S"))
|
---|
191 | lhbpGates.add(Gate("R116", "1", "S"))
|
---|
192 | lhbpGates.add(Gate("R117", "1", "S"))
|
---|
193 | lhbpGates.addNewColumn()
|
---|
194 |
|
---|
195 | lhbpGates.add(Gate("R210", "2A", "S",
|
---|
196 | availableFn = getAvilableIf(othersAvailable = ["R212A"]),
|
---|
197 | taxiThrough = True))
|
---|
198 | lhbpGates.add(Gate("R211", "2A", "S",
|
---|
199 | availableFn = getAvilableIf(othersAvailable = ["R212A"]),
|
---|
200 | taxiThrough = True))
|
---|
201 | lhbpGates.add(Gate("R212", "2A", "S",
|
---|
202 | availableFn = getAvilableIf(othersAvailable = ["R212A"]),
|
---|
203 | taxiThrough = True))
|
---|
204 | lhbpGates.add(Gate("R212A", "2A", "S",
|
---|
205 | availableFn = getAvilableIf(othersAvailable = ["R210", "R211", "R212"]),
|
---|
206 | taxiThrough = True))
|
---|
207 | lhbpGates.addSpace()
|
---|
208 |
|
---|
209 | lhbpGates.add(Gate("R220", "2B", "S"))
|
---|
210 | lhbpGates.add(Gate("R221", "2B", "S"))
|
---|
211 | lhbpGates.add(Gate("R222", "2B", "S"))
|
---|
212 | lhbpGates.add(Gate("R223", "2B", "S"))
|
---|
213 | lhbpGates.addSpace()
|
---|
214 |
|
---|
215 | lhbpGates.add(Gate("R224", "2A", "R"))
|
---|
216 | lhbpGates.add(Gate("R225", "2A", "S"))
|
---|
217 | lhbpGates.add(Gate("R226", "2A", "S"))
|
---|
218 | lhbpGates.add(Gate("R227", "2A", "S"))
|
---|
219 | lhbpGates.addNewColumn()
|
---|
220 |
|
---|
221 | lhbpGates.add(Gate("R270", "2A", "S"))
|
---|
222 | lhbpGates.add(Gate("R271", "2A", "S"))
|
---|
223 | lhbpGates.add(Gate("R272", "2A", "S"))
|
---|
224 | lhbpGates.add(Gate("R274", "2A", "S"))
|
---|
225 | lhbpGates.add(Gate("R275", "2A", "S"))
|
---|
226 | lhbpGates.add(Gate("R276", "2A", "S"))
|
---|
227 | lhbpGates.add(Gate("R277", "2A", "S"))
|
---|
228 | lhbpGates.add(Gate("R278", "2A", "S",
|
---|
229 | availableFn = getAvilableIf(othersAvailable = ["R278A"]),
|
---|
230 | taxiThrough = True))
|
---|
231 | lhbpGates.add(Gate("R278A", "2A", "S",
|
---|
232 | availableFn = getAvilableIf(othersAvailable = ["R278", "R279"]),
|
---|
233 | taxiThrough = True))
|
---|
234 | lhbpGates.add(Gate("R279", "2A", "S",
|
---|
235 | availableFn = getAvilableIf(othersAvailable = ["R278A"]),
|
---|
236 | taxiThrough = True))
|
---|