adapt the code to split up predictions form the inbounds
This commit is contained in:
@@ -9,26 +9,27 @@ import itertools
|
||||
|
||||
from aman.sys.aco.Configuration import Configuration
|
||||
from aman.sys.aco.RunwayManager import RunwayManager
|
||||
from aman.types.Inbound import Inbound
|
||||
from aman.sys.aco.Node import Node
|
||||
|
||||
# This class implements a single ant of the following paper:
|
||||
# https://sci-hub.mksa.top/10.1109/cec.2019.8790135
|
||||
class Ant:
|
||||
def __init__(self, pheromoneTable : np.array, configuration : Configuration):
|
||||
def __init__(self, pheromoneTable : np.array, configuration : Configuration, nodes):
|
||||
self.Configuration = configuration
|
||||
self.Nodes = nodes
|
||||
self.RunwayManager = RunwayManager(self.Configuration)
|
||||
self.InboundSelected = [ False ] * len(self.Configuration.Inbounds)
|
||||
self.InboundScore = np.zeros([ len(self.Configuration.Inbounds), 1 ])
|
||||
self.InboundSelected = [ False ] * len(self.Nodes)
|
||||
self.InboundScore = np.zeros([ len(self.Nodes), 1 ])
|
||||
self.PheromoneMatrix = pheromoneTable
|
||||
self.SequenceDelay = timedelta(seconds = 0)
|
||||
self.Sequence = None
|
||||
|
||||
def qualifyDelay(delay, inbound, runway):
|
||||
def qualifyDelay(delay, node, runway):
|
||||
if 0.0 > delay.total_seconds():
|
||||
delay = timedelta(seconds = 0)
|
||||
|
||||
# calculate the heuristic scaling to punish increased delays for single inbounds
|
||||
scaledDelay = delay.total_seconds() / inbound.ArrivalCandidates[runway.Name].MaximumTimeToLose.total_seconds()
|
||||
scaledDelay = delay.total_seconds() / node.ArrivalCandidates[runway.Name].MaximumTimeToLose.total_seconds()
|
||||
return max(1.0 / (99.0 * (scaledDelay ** 2) + 1), 0.01)
|
||||
|
||||
# Implements function (5), but adapted to the following logic:
|
||||
@@ -37,8 +38,8 @@ class Ant:
|
||||
# - Calculates a ratio between the inbound delay and the unused runway time
|
||||
# - Weight the overall ratio based on maximum time to lose to punish high time to lose rates while other flights are gaining time
|
||||
def heuristicInformation(self, preceeding : int, current : int):
|
||||
rwy, eta, unusedRunwayTime = self.RunwayManager.selectArrivalRunway(self.Configuration.Inbounds[current], True, self.Configuration.EarliestArrivalTime)
|
||||
inboundDelay = eta - self.Configuration.Inbounds[current].ArrivalCandidates[rwy.Name].InitialArrivalTime
|
||||
rwy, eta, unusedRunwayTime = self.RunwayManager.selectArrivalRunway(self.Nodes[current], True, self.Configuration.EarliestArrivalTime)
|
||||
inboundDelay = eta - self.Nodes[current].ArrivalCandidates[rwy.Name].InitialArrivalTime
|
||||
if 0.0 > inboundDelay.total_seconds():
|
||||
inboundDelay = timedelta(seconds = 0)
|
||||
|
||||
@@ -49,7 +50,7 @@ class Ant:
|
||||
fraction /= 60.0
|
||||
|
||||
# calculate the heuristic scaling to punish increased delays for single inbounds
|
||||
weight = Ant.qualifyDelay(inboundDelay, self.Configuration.Inbounds[current], rwy)
|
||||
weight = Ant.qualifyDelay(inboundDelay, self.Nodes[current], rwy)
|
||||
|
||||
return weight * self.PheromoneMatrix[preceeding, current] * ((1.0 / (fraction or 1)) ** self.Configuration.Beta)
|
||||
|
||||
@@ -86,18 +87,19 @@ class Ant:
|
||||
|
||||
return None
|
||||
|
||||
def associateInbound(self, inbound : Inbound, earliestArrivalTime : datetime):
|
||||
def associateInbound(self, node : Node, earliestArrivalTime : datetime):
|
||||
# prepare the statistics
|
||||
rwy, eta, _ = self.RunwayManager.selectArrivalRunway(inbound, True, self.Configuration.EarliestArrivalTime)
|
||||
rwy, eta, _ = self.RunwayManager.selectArrivalRunway(node, True, self.Configuration.EarliestArrivalTime)
|
||||
eta = max(earliestArrivalTime, eta)
|
||||
|
||||
inbound.PlannedRunway = rwy
|
||||
inbound.PlannedStar = inbound.ArrivalCandidates[rwy.Name].Star
|
||||
inbound.PlannedArrivalTime = eta
|
||||
inbound.InitialArrivalTime = inbound.ArrivalCandidates[rwy.Name].InitialArrivalTime
|
||||
self.RunwayManager.RunwayInbounds[rwy.Name] = inbound
|
||||
node.Inbound.PlannedRunway = rwy
|
||||
node.Inbound.PlannedStar = node.ArrivalCandidates[rwy.Name].Star
|
||||
node.Inbound.PlannedArrivalTime = eta
|
||||
node.Inbound.PlannedArrivalRoute = node.ArrivalCandidates[rwy.Name].ArrivalRoute
|
||||
node.Inbound.InitialArrivalTime = node.ArrivalCandidates[rwy.Name].InitialArrivalTime
|
||||
self.RunwayManager.RunwayInbounds[rwy.Name] = node
|
||||
|
||||
delay = inbound.PlannedArrivalTime - inbound.InitialArrivalTime
|
||||
delay = node.Inbound.PlannedArrivalTime - node.Inbound.InitialArrivalTime
|
||||
if 0.0 < delay.total_seconds():
|
||||
return delay, rwy
|
||||
else:
|
||||
@@ -108,8 +110,8 @@ class Ant:
|
||||
|
||||
# select the first inbound
|
||||
self.InboundSelected[first] = True
|
||||
delay, rwy = self.associateInbound(self.Configuration.Inbounds[first], self.Configuration.EarliestArrivalTime)
|
||||
self.InboundScore[0] = Ant.qualifyDelay(delay, self.Configuration.Inbounds[first], rwy)
|
||||
delay, rwy = self.associateInbound(self.Nodes[first], self.Configuration.EarliestArrivalTime)
|
||||
self.InboundScore[0] = Ant.qualifyDelay(delay, self.Nodes[first], rwy)
|
||||
self.Sequence.append(first)
|
||||
self.SequenceDelay += delay
|
||||
|
||||
@@ -119,9 +121,9 @@ class Ant:
|
||||
break
|
||||
|
||||
self.InboundSelected[index] = True
|
||||
delay, rwy = self.associateInbound(self.Configuration.Inbounds[index], self.Configuration.EarliestArrivalTime)
|
||||
delay, rwy = self.associateInbound(self.Nodes[index], self.Configuration.EarliestArrivalTime)
|
||||
self.SequenceDelay += delay
|
||||
self.InboundScore[len(self.Sequence)] = Ant.qualifyDelay(delay, self.Configuration.Inbounds[index], rwy)
|
||||
self.InboundScore[len(self.Sequence)] = Ant.qualifyDelay(delay, self.Nodes[index], rwy)
|
||||
self.Sequence.append(index)
|
||||
|
||||
# update the local pheromone
|
||||
@@ -130,7 +132,7 @@ class Ant:
|
||||
self.PheromoneMatrix[self.Sequence[-2], self.Sequence[-1]] = max(self.Configuration.ThetaZero, update)
|
||||
|
||||
# validate that nothing went wrong
|
||||
if len(self.Sequence) != len(self.Configuration.Inbounds):
|
||||
if len(self.Sequence) != len(self.Nodes):
|
||||
self.SequenceDelay = None
|
||||
self.SequenceScore = None
|
||||
self.Sequence = None
|
||||
|
||||
Reference in New Issue
Block a user