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):
|
---|
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 |
|
---|
28 | @property
|
---|
29 | def number(self):
|
---|
30 | """Get the number of the gate."""
|
---|
31 | return self._number
|
---|
32 |
|
---|
33 | def isAvailable(self, gates, occupiedGateNumbers):
|
---|
34 | """Determine if this gate is available given the set of gates and
|
---|
35 | occupied gate numbers."""
|
---|
36 | if self._number in occupiedGateNumbers:
|
---|
37 | return False
|
---|
38 | return True if self._availableFn is None else \
|
---|
39 | self._availableFn(gates, occupiedGateNumbers)
|
---|
40 |
|
---|
41 | #--------------------------------------------------------------------------------------
|
---|
42 |
|
---|
43 | class Gates(object):
|
---|
44 | """A collection of gates."""
|
---|
45 | # Display info type: a gate (number)
|
---|
46 | DISPLAY_GATE=1
|
---|
47 |
|
---|
48 | # Display info type: a space
|
---|
49 | DISPLAY_SPACE=2
|
---|
50 |
|
---|
51 | # Display info type: a new column
|
---|
52 | DISPLAY_NEW_COLUMN=3
|
---|
53 |
|
---|
54 | def __init__(self):
|
---|
55 | """Construct the gate collection."""
|
---|
56 | self._gates = []
|
---|
57 | self._displayInfos = []
|
---|
58 | self._numColumns = 1
|
---|
59 | self._numRows = 0
|
---|
60 | self._numRowsInColumn = 0
|
---|
61 |
|
---|
62 | @property
|
---|
63 | def gates(self):
|
---|
64 | """Get an iterator over the gates."""
|
---|
65 | return iter(self._gates)
|
---|
66 |
|
---|
67 | @property
|
---|
68 | def displayInfos(self):
|
---|
69 | """Get an iterator over the display info tuples.
|
---|
70 |
|
---|
71 | Each tuple consists of
|
---|
72 | - a type (one of the DISPLAY_XXX constants), and
|
---|
73 | - an additional data (the gate for DISPLAY_GATE, None for others)."""
|
---|
74 | return iter(self._displayInfos)
|
---|
75 |
|
---|
76 | @property
|
---|
77 | def numRows(self):
|
---|
78 | """Get the number of rows."""
|
---|
79 | return self._numRows
|
---|
80 |
|
---|
81 | @property
|
---|
82 | def numColumns(self):
|
---|
83 | """Get the number of columns."""
|
---|
84 | return self._numColumns
|
---|
85 |
|
---|
86 | def add(self, gate):
|
---|
87 | """Add a gate to the collection."""
|
---|
88 | self._gates.append(gate)
|
---|
89 | self._displayInfos.append((Gates.DISPLAY_GATE, gate))
|
---|
90 | self._addRow()
|
---|
91 |
|
---|
92 | def addSpace(self):
|
---|
93 | """Add a space between subsequent gates."""
|
---|
94 | self._displayInfos.append((Gates.DISPLAY_SPACE, None))
|
---|
95 | self._addRow()
|
---|
96 |
|
---|
97 | def addNewColumn(self):
|
---|
98 | """Start a new column of gates."""
|
---|
99 | self._displayInfos.append((Gates.DISPLAY_NEW_COLUMN, None))
|
---|
100 | self._numRowsInColumn = 0
|
---|
101 | self._numColumns += 1
|
---|
102 |
|
---|
103 | def _addRow(self):
|
---|
104 | """Add a new row."""
|
---|
105 | self._numRowsInColumn += 1
|
---|
106 | if self._numRowsInColumn > self._numRows:
|
---|
107 | self._numRows = self._numRowsInColumn
|
---|
108 |
|
---|
109 | #--------------------------------------------------------------------------------------
|
---|
110 |
|
---|
111 | def availableIf(occupiedGateNumbers, othersAvailable = []):
|
---|
112 | """Determine if a gate is available.
|
---|
113 |
|
---|
114 | othersAvailable is a list of numbers of gates, that must be available so
|
---|
115 | that the one we are considering is available."""
|
---|
116 | for otherNumber in othersAvailable:
|
---|
117 | if otherNumber in occupiedGateNumbers:
|
---|
118 | return False
|
---|
119 | return True
|
---|
120 |
|
---|
121 | #--------------------------------------------------------------------------------------
|
---|
122 |
|
---|
123 | def getAvilableIf(othersAvailable = []):
|
---|
124 | """Get a function that determines if a gate is available based on the
|
---|
125 | statuses of other gates."""
|
---|
126 | return lambda gates, occupiedGateNumbers: availableIf(occupiedGateNumbers,
|
---|
127 | othersAvailable =
|
---|
128 | othersAvailable)
|
---|
129 |
|
---|
130 | #--------------------------------------------------------------------------------------
|
---|
131 |
|
---|
132 | # The gates at LHBP
|
---|
133 | lhbpGates = Gates()
|
---|
134 |
|
---|
135 | lhbpGates.add(Gate("1", "1", "S"))
|
---|
136 | lhbpGates.add(Gate("2", "1", "S"))
|
---|
137 | lhbpGates.add(Gate("3", "1", "S"))
|
---|
138 | lhbpGates.add(Gate("4", "1", "S"))
|
---|
139 | lhbpGates.add(Gate("5", "1", "S"))
|
---|
140 | lhbpGates.add(Gate("6", "1", "S"))
|
---|
141 | lhbpGates.add(Gate("25", "1", "S"))
|
---|
142 | lhbpGates.add(Gate("26", "1", "S"))
|
---|
143 | lhbpGates.add(Gate("27", "1", "S"))
|
---|
144 | lhbpGates.addSpace()
|
---|
145 |
|
---|
146 | lhbpGates.add(Gate("31", "2B", "G"))
|
---|
147 | lhbpGates.add(Gate("32", "2B", "G"))
|
---|
148 | lhbpGates.add(Gate("33", "2B", "G"))
|
---|
149 | lhbpGates.addNewColumn()
|
---|
150 |
|
---|
151 | lhbpGates.add(Gate("34", "2B", "G"))
|
---|
152 | lhbpGates.add(Gate("35", "2B", "G"))
|
---|
153 | lhbpGates.add(Gate("36", "2B", "G"))
|
---|
154 | lhbpGates.add(Gate("37", "2B", "G"))
|
---|
155 | lhbpGates.add(Gate("38", "2B", "G"))
|
---|
156 | lhbpGates.add(Gate("39", "2B", "G"))
|
---|
157 | lhbpGates.addSpace()
|
---|
158 |
|
---|
159 | lhbpGates.add(Gate("42", "2A", "G"))
|
---|
160 | lhbpGates.add(Gate("43", "2A", "G"))
|
---|
161 | lhbpGates.add(Gate("44", "2A", "G"))
|
---|
162 | lhbpGates.add(Gate("45", "2A", "G"))
|
---|
163 | lhbpGates.addNewColumn()
|
---|
164 |
|
---|
165 | lhbpGates.add(Gate("107", "1", "S"))
|
---|
166 | lhbpGates.add(Gate("108", "1", "S"))
|
---|
167 | lhbpGates.add(Gate("109", "1", "S"))
|
---|
168 | lhbpGates.add(Gate("R110", "1", "S",
|
---|
169 | availableFn = getAvilableIf(othersAvailable = ["R111"])))
|
---|
170 | lhbpGates.add(Gate("R111", "1", "S",
|
---|
171 | availableFn = getAvilableIf(othersAvailable = ["R110", "R112"])))
|
---|
172 | lhbpGates.add(Gate("R112", "1", "S",
|
---|
173 | availableFn = getAvilableIf(othersAvailable = ["R111"])))
|
---|
174 | lhbpGates.add(Gate("R113", "1", "S",
|
---|
175 | availableFn = getAvilableIf(othersAvailable = ["R114"])))
|
---|
176 | lhbpGates.add(Gate("R114", "1", "S",
|
---|
177 | availableFn = getAvilableIf(othersAvailable = ["R113"])))
|
---|
178 | lhbpGates.add(Gate("R115", "1", "S"))
|
---|
179 | lhbpGates.add(Gate("R116", "1", "S"))
|
---|
180 | lhbpGates.add(Gate("R117", "1", "S"))
|
---|
181 | lhbpGates.addNewColumn()
|
---|
182 |
|
---|
183 | lhbpGates.add(Gate("R210", "2A", "S",
|
---|
184 | availableFn = getAvilableIf(othersAvailable = ["R212A"])))
|
---|
185 | lhbpGates.add(Gate("R211", "2A", "S",
|
---|
186 | availableFn = getAvilableIf(othersAvailable = ["R212A"])))
|
---|
187 | lhbpGates.add(Gate("R212", "2A", "S",
|
---|
188 | availableFn = getAvilableIf(othersAvailable = ["R212A"])))
|
---|
189 | lhbpGates.add(Gate("R212A", "2A", "S",
|
---|
190 | availableFn = getAvilableIf(othersAvailable = ["R210", "R211", "R212"])))
|
---|
191 | lhbpGates.addSpace()
|
---|
192 |
|
---|
193 | lhbpGates.add(Gate("R220", "2B", "S"))
|
---|
194 | lhbpGates.add(Gate("R221", "2B", "S"))
|
---|
195 | lhbpGates.add(Gate("R222", "2B", "S"))
|
---|
196 | lhbpGates.add(Gate("R223", "2B", "S"))
|
---|
197 | lhbpGates.addSpace()
|
---|
198 |
|
---|
199 | lhbpGates.add(Gate("R224", "2A", "R"))
|
---|
200 | lhbpGates.add(Gate("R225", "2A", "S"))
|
---|
201 | lhbpGates.add(Gate("R226", "2A", "S"))
|
---|
202 | lhbpGates.add(Gate("R227", "2A", "S"))
|
---|
203 | lhbpGates.addNewColumn()
|
---|
204 |
|
---|
205 | lhbpGates.add(Gate("R270", "2A", "S"))
|
---|
206 | lhbpGates.add(Gate("R271", "2A", "S"))
|
---|
207 | lhbpGates.add(Gate("R272", "2A", "S"))
|
---|
208 | lhbpGates.add(Gate("R274", "2A", "S"))
|
---|
209 | lhbpGates.add(Gate("R275", "2A", "S"))
|
---|
210 | lhbpGates.add(Gate("R276", "2A", "S"))
|
---|
211 | lhbpGates.add(Gate("R277", "2A", "S"))
|
---|
212 | lhbpGates.add(Gate("R278", "2A", "S",
|
---|
213 | availableFn = getAvilableIf(othersAvailable = ["R278A"])))
|
---|
214 | lhbpGates.add(Gate("R278A", "2A", "S",
|
---|
215 | availableFn = getAvilableIf(othersAvailable = ["R278", "R279"])))
|
---|
216 | lhbpGates.add(Gate("R279", "2A", "S",
|
---|
217 | availableFn = getAvilableIf(othersAvailable = ["R278A"])))
|
---|