AirportSequencing.py 3.3 KB

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