AirportSequencing.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python
  2. from aman.config.RunwaySequencing import RunwaySequencing
  3. class AirportSequencing:
  4. def __init__(self, icao : str):
  5. self.Airport = icao
  6. self.ActiveArrivalRunways = []
  7. self.RunwayDependencies = []
  8. self.UseMustShallMay = True
  9. def clearData(self):
  10. self.ActiveArrivalRunways.clear()
  11. self.RunwayDependencies.clear()
  12. def activateRunway(self, runway : RunwaySequencing):
  13. for active in self.ActiveArrivalRunways:
  14. if active.Runway.Name == runway.Runway.Name:
  15. self.ActiveArrivalRunways[runway.Runway.Name] = runway
  16. return
  17. self.ActiveArrivalRunways.append(runway)
  18. def runwayIndex(self, identifier : str):
  19. for i in range(0, len(self.ActiveArrivalRunways)):
  20. if self.ActiveArrivalRunways[i].Runway.Name == identifier:
  21. return i
  22. return -1
  23. def deactivateRunway(self, identifier : str):
  24. index = self.runwayIndex(identifier)
  25. if 0 <= index:
  26. self.ActiveArrivalRunways.pop(index)
  27. # remove the dependencies
  28. for i in range(self.RunwayDependencies - 1, -1, -1):
  29. if index == self.RunwayDependencies[i][0] or index == self.RunwayDependencies[i][1]:
  30. self.RunwayDependencies.pop(i)
  31. def addDependency(self, first : str, second : str):
  32. idxFirst = self.runwayIndex(first)
  33. idxSecond = self.runwayIndex(second)
  34. if 0 > idxFirst or 0 > idxSecond:
  35. return
  36. foundFirst = False
  37. foundSecond = False
  38. for dependency in self.RunwayDependencies:
  39. if idxFirst == dependency[0] and idxSecond == dependency[1]:
  40. foundFirst = True
  41. elif idxFirst == dependency[1] and idxSecond == dependency[0]:
  42. foundSecond = True
  43. if False == foundFirst:
  44. self.RunwayDependencies.append([ idxFirst, idxSecond ])
  45. if False == foundSecond:
  46. self.RunwayDependencies.append([ idxSecond, idxFirst ])
  47. def removeDependency(self, first : str, second : str):
  48. idxFirst = self.runwayIndex(first)
  49. idxSecond = self.runwayIndex(second)
  50. if 0 > idxFirst or 0 > idxSecond:
  51. return
  52. for i in range(self.RunwayDependencies - 1, -1, -1):
  53. dependency = self.RunwayDependencies[i]
  54. # check for all the pairs
  55. if idxFirst == dependency[0] and idxSecond == dependency[1]:
  56. self.RunwayDependencies.pop(i)
  57. elif idxSecond == dependency[0] and idxSecond == dependency[0]:
  58. self.RunwayDependencies.pop(i)
  59. def findRunway(self, identifier : str):
  60. for runway in self.ActiveArrivalRunways:
  61. if runway.Runway.Name == identifier:
  62. return runway
  63. return None
  64. def findDependentRunways(self, identifier : str):
  65. # runway is unknown
  66. index = self.runwayIndex(identifier)
  67. if 0 > index:
  68. return []
  69. # search the dependency pair
  70. dependencies = [self.ActiveArrivalRunways[self.RunwayDependencies[i][1]] for i in range(0, len(self.RunwayDependencies)) if index == self.RunwayDependencies[i][0]]
  71. return dependencies