robust error handling to avoid later crashes

This commit is contained in:
Sven Czarnian
2021-12-19 13:06:03 +01:00
parent 91683ec899
commit fc84aab0f2
3 changed files with 23 additions and 5 deletions

View File

@@ -27,6 +27,9 @@ class Ant:
# Implements function (5)
def heuristicInformation(self, current : int):
_, eta, _ = self.RunwayManager.selectArrivalRunway(self.Nodes[current], self.Configuration.EarliestArrivalTime)
if None == eta:
return -1.0
inboundDelay = eta - self.Nodes[current].Inbound.InitialArrivalTime
# calculate the fraction with a mix of the unused runway time and the delay of single aircrafts
@@ -54,6 +57,10 @@ class Ant:
if False == self.InboundSelected[i]:
weights.append(self.heuristicInformation(i) / (pheromoneScale or 1))
# something was wrong in the runway selection
if -1.0 in weights:
return None
total = sum(weights)
cumdist = list(itertools.accumulate(weights)) + [total]
candidateIndex = bisect.bisect(cumdist, random.random() * total)