Exemple #1
0
        public TaxiEdge(TaxiNode startNode, TaxiNode endNode, bool isRunway, XPlaneAircraftCategory maxSize, string linkName)
        {
            StartNode = startNode;
            EndNode   = endNode;

            IsRunway    = isRunway;
            MaxCategory = maxSize;
            LinkName    = linkName;

            ActiveForRunways = new List <string>();
            ActiveZone       = false;

            ReverseEdge = null;
        }
Exemple #2
0
        /// <summary>
        /// Find the chain of TaxiNodes that represent this runway
        /// </summary>
        /// <param name="taxiNodes"></param>
        /// <param name="taxiEdges"></param>
        /// <returns></returns>
        private List <TaxiNode> FindNodeChain(IEnumerable <TaxiNode> taxiNodes, IEnumerable <TaxiEdge> taxiEdges)
        {
            List <TaxiNode> nodes = new List <TaxiNode>();

            // Start with the node nearest to the runway lat/lon
            TaxiNode currentNode = NearestNode;

            nodes.Add(currentNode);
            ulong previousNodeId = 0;

            do
            {
                // Now find an edge that is marked as 'runway' and that starts at the current node, but does not lead to the previous node
                IEnumerable <TaxiEdge> edgesToNext = taxiEdges.Where(e => e.IsRunway && (e.StartNode.Id == currentNode.Id && e.EndNode.Id != previousNodeId));
                if (edgesToNext.Count() == 0)
                {
                    break;
                }

                TaxiEdge edgeToNext = edgesToNext.First();
                if (edgesToNext.Count() > 1)
                {
                    double maxDeviation = double.MaxValue;

                    foreach (TaxiEdge candidate in edgesToNext)
                    {
                        double deviation = VortexMath.TurnAngle(this.Bearing, VortexMath.BearingRadians(currentNode, candidate.EndNode));
                        if (deviation < maxDeviation)
                        {
                            edgeToNext   = candidate;
                            maxDeviation = deviation;
                        }
                    }
                }

                // Keep the current Id as the previous Id
                previousNodeId = currentNode.Id;

                // And get the new current node
                currentNode = taxiNodes.Single(n => n.Id == edgeToNext.EndNode.Id);
                if (currentNode != null)
                {
                    nodes.Add(currentNode);
                }
            }while (currentNode != null);

            return(nodes);
        }
Exemple #3
0
        private void ReadTaxiEdgeOperations(string line)
        {
            string[] tokens   = line.Split(_splitters, StringSplitOptions.RemoveEmptyEntries);
            string[] rwys     = tokens[2].Split(',');
            TaxiEdge lastEdge = _edges.Last();

            lastEdge.ActiveZone = true;
            lastEdge.ActiveForRunways.AddRange(rwys);
            lastEdge.ActiveForRunways = lastEdge.ActiveForRunways.Distinct().ToList();
            if (lastEdge.ReverseEdge != null)
            {
                lastEdge.ReverseEdge.ActiveZone = true;
                lastEdge.ReverseEdge.ActiveForRunways.AddRange(rwys);
                lastEdge.ReverseEdge.ActiveForRunways = lastEdge.ReverseEdge.ActiveForRunways.Distinct().ToList();
            }
        }
Exemple #4
0
        private void FindExits()
        {
            ExitGroups.Clear();
            TaxiNode groupStartNode = null;

            // First, group all nodes
            foreach (TaxiNode node in RunwayNodes)
            {
                foreach (TaxiEdge edge in node.IncomingEdges)
                {
                    if (edge.IsRunway)
                    {
                        continue;
                    }

                    if (edge.ReverseEdge == null)
                    {
                        continue;
                    }

                    TaxiEdge actualEdge = edge.ReverseEdge;
                    double   exitAngle  = VortexMath.TurnAngle(actualEdge.Bearing, Bearing);

                    if (Math.Abs(exitAngle) > VortexMath.Deg135Rad)
                    {
                        continue;
                    }

                    if (groupStartNode == null)
                    {
                        groupStartNode = node;
                        ExitGroups.Add(node, new List <ExitPoint>());
                    }

                    double landingLengthUsed = VortexMath.DistanceKM(DisplacedNode, node);  // 'distance used' actually

                    if (VortexMath.DistanceKM(groupStartNode, node) < 0.200)
                    {
                        ExitGroups[groupStartNode].Add(new ExitPoint()
                        {
                            OffRunwayNode = actualEdge.EndNode, OnRunwayNode = node, LandingLengthUsed = landingLengthUsed, TurnAngle = exitAngle
                        });
                    }
                    else
                    {
                        // add to new group
                        groupStartNode = node;
                        ExitGroups.Add(node, new List <ExitPoint>());
                        ExitGroups[groupStartNode].Add(new ExitPoint()
                        {
                            OffRunwayNode = actualEdge.EndNode, OnRunwayNode = node, LandingLengthUsed = landingLengthUsed, TurnAngle = exitAngle
                        });
                    }
                }
            }

            if (ExitGroups.Count == 0)
            {
                return; // todo: add warning
            }
            // Then pick groups based upon distance
            List <ExitPoint> minimumExit = null;
            List <ExitPoint> mediumExit  = null;
            List <ExitPoint> longExit    = null;
            List <ExitPoint> maxExit     = null;

            foreach (KeyValuePair <TaxiNode, List <ExitPoint> > exitGroup in ExitGroups.OrderBy(eg => eg.Value.First().LandingLengthUsed))
            {
                if (minimumExit == null || minimumExit.First().LandingLengthUsed < VortexMath.Feet4000Km)
                {
                    minimumExit = exitGroup.Value;
                }
                else if (mediumExit == null || mediumExit.First().LandingLengthUsed < VortexMath.Feet5000Km)
                {
                    mediumExit = exitGroup.Value;
                }
                else if (longExit == null || longExit.First().LandingLengthUsed < VortexMath.Feet6500Km)
                {
                    longExit = exitGroup.Value;
                }
                else
                {
                    maxExit = exitGroup.Value;
                }
            }

            ExitGroups.Clear();
            if (minimumExit != null)
            {
                ExitGroups.Add(minimumExit.First().OnRunwayNode, minimumExit);
            }
            if (mediumExit != null)
            {
                ExitGroups.Add(mediumExit.First().OnRunwayNode, mediumExit);
            }
            if (longExit != null)
            {
                ExitGroups.Add(longExit.First().OnRunwayNode, longExit);
            }
            if (maxExit != null)
            {
                ExitGroups.Add(maxExit.First().OnRunwayNode, maxExit);
            }

            foreach (var result in ExitGroups)
            {
                Logger.Log($"{Designator} Group: {result.Key.Id}");

                ExitPoint right = result.Value.Where(ep => ep.TurnAngle > 0).OrderBy(ep => ep.TurnAngle).FirstOrDefault();
                ExitPoint left  = result.Value.Where(ep => ep.TurnAngle < 0).OrderByDescending(ep => ep.TurnAngle).FirstOrDefault();
                ExitGroups[result.Key].Clear();

                if (right != null)
                {
                    Logger.Log($" Right Exit: {right.OnRunwayNode.Id}->{right.OffRunwayNode.Id} {right.TurnAngle * VortexMath.Rad2Deg:0.0} {right.LandingLengthUsed * VortexMath.KmToFoot:0}ft");
                    ExitGroups[result.Key].Add(right);
                }

                if (left != null)
                {
                    Logger.Log($" Left  Exit: {left.OnRunwayNode.Id}->{left.OffRunwayNode.Id} {left.TurnAngle * VortexMath.Rad2Deg:0.0} {left.LandingLengthUsed * VortexMath.KmToFoot:0}ft");
                    ExitGroups[result.Key].Add(left);
                }
            }
        }
Exemple #5
0
        public void DetermineTaxiOutLocation(IEnumerable <TaxiNode> taxiNodes)
        {
            double   shortestDistance      = double.MaxValue;
            double   bestPushBackLatitude  = 0;
            double   bestPushBackLongitude = 0;
            TaxiNode firstAfterPush        = null;
            TaxiNode alternateAfterPush    = null;
            TaxiNode fallback = null;

            // For gates use the indicated bearings (push back), for others add 180 degrees for straight out
            // Then convert to -180...180 range
            double adjustedBearing = (LocationType == StartUpLocationType.Gate) ? Bearing : (Bearing + Math.PI);

            if (adjustedBearing > Math.PI)
            {
                adjustedBearing -= (VortexMath.PI2);
            }

            // Compute the distance (arbitrary units) from each taxi node to the start location
            foreach (TaxiNode node in taxiNodes)
            {
                node.TemporaryDistance = VortexMath.DistanceKM(node, this);
            }

            // Select the 25 nearest, then from those select only the ones that are in the 180 degree arc of the direction
            // we intend to move in from the startpoint
            // todo: make both 25 and 180 parameters
            IEnumerable <TaxiNode> selectedNodes = taxiNodes.OrderBy(v => v.TemporaryDistance).Take(25);

            fallback = selectedNodes.First();

            if (fallback.TemporaryDistance < 0.0025)
            {
                // There is a atc taxi node really close to the parking, try to build pushback path from there
                if (fallback.IncomingEdges.Count == 1)
                {
                    TaxiEdge theEdge = fallback.IncomingEdges.FirstOrDefault();
                    if (theEdge != null)
                    {
                        fallback = theEdge.StartNode;
                        while (fallback.TemporaryDistance < 0.150 && fallback.IncomingEdges.Count <= 2)
                        {
                            TaxiEdge nextEdge = fallback.IncomingEdges.FirstOrDefault(e => e.StartNode != theEdge.EndNode);
                            if (nextEdge == null)
                            {
                                break;
                            }

                            // This catches the cases at the end of an apron where the only
                            // link is the actual taxipath already
                            if (VortexMath.AbsTurnAngle(theEdge.Bearing, nextEdge.Bearing) > VortexMath.Deg060Rad)
                            {
                                break;
                            }

                            // todo: each node should be added to the parking as 'push back trajectory'
                            fallback = nextEdge.StartNode;
                            theEdge  = nextEdge;
                        }

                        NearestNode            = fallback;
                        AlternateAfterPushBack = null;
                        PushBackLatitude       = fallback.Latitude;
                        PushBackLongitude      = fallback.Longitude;
                        return;
                    }
                }
            }


            selectedNodes = selectedNodes.Where(v => Math.Abs(adjustedBearing - VortexMath.BearingRadians(v, this)) < VortexMath.PI05);

            // For each qualifying node
            // Todo: check this part for tie downs
            foreach (TaxiNode v in selectedNodes)
            {
                // Look at each link coming into it from other nodes
                foreach (TaxiEdge incoming in v.IncomingEdges)
                {
                    double pushBackLatitude  = 0;
                    double pushBackLongitude = 0;

                    // Now find where the 'start point outgoing line' intersects with the taxi link we are currently checking
                    if (!VortexMath.Intersection(Latitude, Longitude, adjustedBearing,
                                                 incoming.StartNode.Latitude, incoming.StartNode.Longitude, incoming.Bearing,
                                                 ref pushBackLatitude, ref pushBackLongitude))
                    {
                        // If computation fails, try again but now with the link in the other direction.
                        // Ignoring one way links here, I just want a push back target for now that's close to A link.
                        if (!VortexMath.Intersection(Latitude, Longitude, adjustedBearing,
                                                     incoming.StartNode.Latitude, incoming.StartNode.Longitude, incoming.Bearing + Math.PI,
                                                     ref pushBackLatitude, ref pushBackLongitude))
                        {
                            // Lines might be parallel, can't find intersection, skip
                            continue;
                        }
                    }

                    // Great Circles cross twice, if we found the one on the back of the earth, convert it to the
                    // one on the airport
                    // Todo: check might fail for airports on the -180/+180 longitude line
                    if (Math.Abs(pushBackLongitude - Longitude) > 0.25 * Math.PI)
                    {
                        pushBackLatitude   = -pushBackLatitude;
                        pushBackLongitude += VortexMath.PI;
                        if (pushBackLongitude > VortexMath.PI)
                        {
                            pushBackLongitude -= VortexMath.PI2;
                        }
                    }

                    // To find the best spot we must know if the found intersection is actually
                    // on the link or if it is somewhere outside the actual link. These are
                    // still usefull in some cases
                    bool foundTargetIsOutsideSegment = false;

                    // Todo: check might fail for airports on the -180/+180 longitude line
                    if (pushBackLatitude - incoming.StartNode.Latitude > 0)
                    {
                        if (v.Latitude - pushBackLatitude <= 0)
                        {
                            foundTargetIsOutsideSegment = true;
                        }
                    }
                    else if (v.Latitude - pushBackLatitude > 0)
                    {
                        foundTargetIsOutsideSegment = true;
                    }

                    if (pushBackLongitude - incoming.StartNode.Longitude > 0)
                    {
                        if (v.Longitude - pushBackLongitude <= 0)
                        {
                            foundTargetIsOutsideSegment = true;
                        }
                    }
                    else if (v.Longitude - pushBackLongitude > 0)
                    {
                        foundTargetIsOutsideSegment = true;
                    }

                    // Ignore links where the taxiout line intercepts at too sharp of an angle if it is
                    // also outside the actual link.
                    // todo: Maybe ignore these links right away, saves a lot of calculations
                    double interceptAngleSharpness = Math.Abs(VortexMath.PI05 - Math.Abs((adjustedBearing - incoming.Bearing) % Math.PI)) / Math.PI;
                    if (foundTargetIsOutsideSegment && interceptAngleSharpness > 0.4)
                    {
                        continue;
                    }

                    // for the found location keep track of the distance to it from the start point
                    // also keep track of the distances to both nodes of the link we are inspecting now
                    double pushDistance   = 0.0;
                    double distanceSource = VortexMath.DistancePyth(incoming.StartNode.Latitude, incoming.StartNode.Longitude, pushBackLatitude, pushBackLongitude);
                    double distanceDest   = VortexMath.DistancePyth(v.Latitude, v.Longitude, pushBackLatitude, pushBackLongitude);

                    // If the found point is outside the link, add the distance to the nearest node of
                    // the link times 2 as a penalty to the actual distance. This prevents pushback point
                    // candidates that sneak up on the start because of a slight angle in remote link
                    // from being accepted as best.
                    TaxiNode nearestVertexIfPushBackOutsideSegment = null;
                    if (foundTargetIsOutsideSegment)
                    {
                        if (distanceSource < distanceDest)
                        {
                            pushDistance = distanceSource * 2.0;
                            nearestVertexIfPushBackOutsideSegment = incoming.StartNode;
                        }
                        else
                        {
                            pushDistance = distanceDest * 2.0;
                            nearestVertexIfPushBackOutsideSegment = v;
                        }
                    }

                    // How far is the candidate from the start point?
                    pushDistance += VortexMath.DistancePyth(Latitude, Longitude, pushBackLatitude, pushBackLongitude);

                    // See if it is a better candidate
                    if (pushDistance < shortestDistance)
                    {
                        bestPushBackLatitude  = pushBackLatitude;
                        bestPushBackLongitude = pushBackLongitude;
                        shortestDistance      = pushDistance;

                        // Setting things up for the path calculation that will follow later
                        if (foundTargetIsOutsideSegment)
                        {
                            // The taxi out route will start with a push to the best candidate
                            // Then move to the 'firstAfterPush' node and from there follow
                            // the 'shortest' path to the runway
                            firstAfterPush     = nearestVertexIfPushBackOutsideSegment;
                            alternateAfterPush = null;
                        }
                        else
                        {
                            // The taxi out route will start with a push to the best candidate
                            // Then, if the second node in the find 'shortest' path is the alternate
                            // the first point will be skipped. If the second point is not the alternate,
                            // the 'firstAfterPush' will be the first indeed and after that the found
                            // route will be followed.
                            if (distanceSource < distanceDest)
                            {
                                firstAfterPush     = incoming.StartNode;
                                alternateAfterPush = v;
                            }
                            else
                            {
                                firstAfterPush     = v;
                                alternateAfterPush = incoming.StartNode;
                            }
                        }
                    }
                }
            }

            // All candiates have been considered, post processing the winner:
            if (shortestDistance < double.MaxValue)
            {
                // If there is one, check if it is not too far away from the start. This catches cases where
                // a gate at the end of an apron with heading parallel to the apron entry would get a best
                // target on the taxiway outside the apron.
                double actualDistance = VortexMath.DistanceKM(Latitude, Longitude, bestPushBackLatitude, bestPushBackLongitude);
                if (actualDistance > 0.25)
                {
                    // Fix this by pushing to the end point of the entry link
                    // (If that is actually the nearest node to the parking, but alas...
                    //  this is the default WT3 behaviour anyway)
                    NearestNode            = selectedNodes.First();
                    AlternateAfterPushBack = null;
                    PushBackLatitude       = NearestNode.Latitude;
                    PushBackLongitude      = NearestNode.Longitude;
                }
                else
                {
                    // Store the results in the startpoint
                    PushBackLatitude       = bestPushBackLatitude;
                    PushBackLongitude      = bestPushBackLongitude;
                    NearestNode            = firstAfterPush;
                    AlternateAfterPushBack = alternateAfterPush;
                }
            }
            else
            {
                // Crude fallback to defautl WT behavoit if nothing was found.
                NearestNode            = fallback;
                AlternateAfterPushBack = null;
                PushBackLatitude       = NearestNode.Latitude;
                PushBackLongitude      = NearestNode.Longitude;
            }
        }
Exemple #6
0
        private void ReadTaxiEdge(string line)
        {
            string[] tokens   = line.Split(_splitters, StringSplitOptions.RemoveEmptyEntries);
            uint     va       = uint.Parse(tokens[1]);
            uint     vb       = uint.Parse(tokens[2]);
            bool     isRunway = (tokens[4][0] != 't'); // taxiway_X or runway
            bool     isTwoWay = (tokens[3][0] == 't'); // oneway or twoway

            XPlaneAircraftCategory maxSize;

            if (isRunway || tokens[4].Length < 9)
            {
                maxSize = (XPlaneAircraftCategory.Max - 1);
            }
            else
            {
                maxSize = (XPlaneAircraftCategory)(tokens[4][8] - 'A');
            }

            string linkName = tokens.Length > 5 ? string.Join(" ", tokens.Skip(5)) : "";

            TaxiNode startNode = _nodeDict[va];
            TaxiNode endNode   = _nodeDict[vb];

            TaxiEdge outgoingEdge = _edges.SingleOrDefault(e => (e.StartNode.Id == va && e.EndNode.Id == vb));

            if (outgoingEdge != null)
            {
                // todo: report warning
                outgoingEdge.MaxCategory = (XPlaneAircraftCategory)Math.Max((int)outgoingEdge.MaxCategory, (int)maxSize);
            }
            else
            {
                outgoingEdge = new TaxiEdge(startNode, endNode, isRunway, maxSize, linkName);
                _edges.Add(outgoingEdge);
            }

            TaxiEdge incomingEdge = null;

            if (isTwoWay)
            {
                incomingEdge = _edges.SingleOrDefault(e => (e.StartNode.Id == vb && e.EndNode.Id == va));
                if (incomingEdge != null)
                {
                    // todo: report warning
                    incomingEdge.MaxCategory = (XPlaneAircraftCategory)Math.Max((int)incomingEdge.MaxCategory, (int)maxSize);
                }
                else
                {
                    incomingEdge = new TaxiEdge(endNode, startNode, isRunway, maxSize, linkName);
                    _edges.Add(incomingEdge);

                    incomingEdge.ReverseEdge = outgoingEdge;
                    outgoingEdge.ReverseEdge = incomingEdge;
                }
            }

            endNode.AddEdgeFrom(outgoingEdge);
            if (isTwoWay)
            {
                startNode.AddEdgeFrom(incomingEdge);
            }
        }
 public void AddEdgeFrom(TaxiEdge edge)
 {
     IncomingEdges.Add(edge);
 }