90 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/env python
 | |
| 
 | |
| from aman.config.RunwaySequencing import RunwaySequencing
 | |
| 
 | |
| class AirportSequencing:
 | |
|     def __init__(self, icao : str):
 | |
|         self.ActiveArrivalRunways = []
 | |
|         self.RunwayDependencies = []
 | |
| 
 | |
|     def clearData(self):
 | |
|         self.ActiveArrivalRunways.clear()
 | |
|         self.RunwayDependencies.clear()
 | |
| 
 | |
|     def activateRunway(self, runway : RunwaySequencing):
 | |
|         for active in self.ActiveArrivalRunways:
 | |
|             if active.Runway.Name == runway.Runway.Name:
 | |
|                 self.ActiveArrivalRunways[runway.Runway.Name] = runway
 | |
|                 return
 | |
|         self.ActiveArrivalRunways.append(runway)
 | |
| 
 | |
|     def runwayIndex(self, identifier : str):
 | |
|         for i in range(0, len(self.ActiveArrivalRunways)):
 | |
|             if self.ActiveArrivalRunways[i].Runway.Name == identifier:
 | |
|                 return i
 | |
|         return -1
 | |
| 
 | |
|     def deactivateRunway(self, identifier : str):
 | |
|         index = self.runwayIndex(identifier)
 | |
|         if 0 <= index:
 | |
|             self.ActiveArrivalRunways.pop(index)
 | |
| 
 | |
|             # remove the dependencies
 | |
|             for i in range(self.RunwayDependencies - 1, -1, -1):
 | |
|                 if index == self.RunwayDependencies[i][0] or index == self.RunwayDependencies[i][1]:
 | |
|                     self.RunwayDependencies.pop(i)
 | |
| 
 | |
|     def addDependency(self, first : str, second : str):
 | |
|         idxFirst = self.runwayIndex(first)
 | |
|         idxSecond = self.runwayIndex(second)
 | |
|         if 0 > idxFirst or 0 > idxSecond:
 | |
|             return
 | |
| 
 | |
|         foundFirst = False
 | |
|         foundSecond = False
 | |
|         for dependency in self.RunwayDependencies:
 | |
|             if idxFirst == dependency[0] and idxSecond == dependency[1]:
 | |
|                 foundFirst = True
 | |
|             elif idxFirst == dependency[1] and idxSecond == dependency[0]:
 | |
|                 foundSecond = True
 | |
| 
 | |
|         if False == foundFirst:
 | |
|             self.RunwayDependencies.append([ idxFirst, idxSecond ])
 | |
|         if False == foundSecond:
 | |
|             self.RunwayDependencies.append([ idxSecond, idxFirst ])
 | |
| 
 | |
|     def removeDependency(self, first : str, second : str):
 | |
|         idxFirst = self.runwayIndex(first)
 | |
|         idxSecond = self.runwayIndex(second)
 | |
|         if 0 > idxFirst or 0 > idxSecond:
 | |
|             return
 | |
| 
 | |
|         for i in range(self.RunwayDependencies - 1, -1, -1):
 | |
|             dependency = self.RunwayDependencies[i]
 | |
| 
 | |
|             # check for all the pairs
 | |
|             if idxFirst == dependency[0] and idxSecond == dependency[1]:
 | |
|                 self.RunwayDependencies.pop(i)
 | |
|             elif idxSecond == dependency[0] and idxSecond == dependency[0]:
 | |
|                 self.RunwayDependencies.pop(i)
 | |
| 
 | |
|     def findRunway(self, identifier : str):
 | |
|         for runway in self.ActiveArrivalRunways:
 | |
|             if runway.Runway.Name == identifier:
 | |
|                 return runway
 | |
|         return None
 | |
| 
 | |
|     def findDependentRunways(self, identifier : str):
 | |
|         # runway is unknown
 | |
|         index = self.runwayIndex(identifier)
 | |
|         if 0 > index:
 | |
|             return []
 | |
| 
 | |
|         # search the dependency pair
 | |
|         dependencies = []
 | |
|         for dependency in self.RunwayDependencies:
 | |
|             if index == dependency[0] and not self.ActiveArrivalRunways[dependency[1]] in dependencies:
 | |
|                 dependencies.append(self.ActiveArrivalRunways[dependency[1]])
 | |
| 
 | |
|         return dependencies
 |