Ejemplo n.º 1
0
 public bool Equals(Node node)
 {
     if (this.location[0] == node.location[0] && this.location[1] == node.location[1])
         return true;
     else
         return false;
 }
Ejemplo n.º 2
0
 //Collision Detection
 //True = collision, false = geen collision
 public bool collisionDetection(Airplane airplane, Way way, Node targetNode)
 {
     foreach (Airplane collisionAirplane in airplanes)
     {
         collisionAirplane.hasCollision = false;
         if (!collisionAirplane.Equals(airplane) && collisionAirplane.isOnAirport()) // Eigen vliegtuig niet meerekenen & vliegtuig moet in bereik van Airport zijn.
         {
             if (collisionAirplane.navigator.currentWay.Equals(way))   // Een ander vliegtuig rijdt op dit moment op de weg
             {
                 if (collisionAirplane.navigator.currentWay.direction == 0)
                 {
                     if (targetNode == collisionAirplane.navigator.getTargetNode())
                     {
                         if (airplane.navigator.getDistanceToTargetNode(airplane.location) > collisionAirplane.navigator.getDistanceToTargetNode(collisionAirplane.location) && airplane.navigator.getDistanceToTargetNode(airplane.location) - collisionAirplane.navigator.getDistanceToTargetNode(collisionAirplane.location) < 150)
                         {
                             airplane.hasCollision = true;
                             return true;
                         }
                     }
                 }
                 if (collisionAirplane.navigator.currentWay.direction != 0)
                 {
                     if (airplane.navigator.getDistanceToTargetNode(airplane.location) > collisionAirplane.navigator.getDistanceToTargetNode(collisionAirplane.location) && airplane.navigator.getDistanceToTargetNode(airplane.location) - collisionAirplane.navigator.getDistanceToTargetNode(collisionAirplane.location) < 150)
                     {
                         airplane.hasCollision = true;
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 public bool hasNode(Node checkNode)
 {
     //Kijk of een node al in de route zit, tegengaan van circulaire routes
     if (this.local == checkNode) return true;
     if (this.previous == null) return false;
     return previous.hasNode(checkNode);
 }
Ejemplo n.º 4
0
        public Route previous; //De voorafgaande Route. Is null voor de eerste

        #endregion Fields

        #region Constructors

        public Route(Node newlocal, Route newPrevious, double newLength)
        {
            this.local = newlocal;
            this.previous = newPrevious;
            this.length = newLength;
            if (previous != null)
                this.length += previous.length;
        }
Ejemplo n.º 5
0
 public Way(Node node1, Node node2, int dir, string name)
 {
     this.nodeConnections[0] = node1;
     this.nodeConnections[1] = node2;
     node1.connections.Add(this);
     node2.connections.Add(this);
     this.direction = dir;
     this.name = name;
 }
Ejemplo n.º 6
0
 public static bool isBetweenNodes(Way way, Node node1, Node node2)
 {
     //Als node 1 en 2 de way bevatten, dan is way een verbinding tussen de twee nodes
     if (node1.checkConnection(way) && node2.checkConnection(way))
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 7
0
        public Route findRoute(Node startNode, Node endNode, Airplane airplane, Airport.Airport airport)
        {
            /*
             * Deze methode maakt een stapel aan met routes. Het pakt de bovenste route van deze stapel. Route heeft Node, vorige Route en lengte.
             * Zolang routes op stapel, blijf draaien. Voor iedere route check Node. Is Node endNode? Ja + lengte < kortste Route dan nieuwe kortste Route.
             * Anders kijk Ways bij Node. Als Node = Endnote of lengte Route > lengte beste Route niet opnieuw pushen.
             * Anders nieuwe Route maken met Node andere kant van Way. Resultaat is kortste Route van beginNode naar endNode.
            */

            foreach (Way w in airport.ways)
                w.weightedLength = w.length;

            Stack<Route> routes = new Stack<Route>();
            Route bestRoute = null;
            routes.Push(new Route(startNode, null, 0));
            while (routes.Count > 0)
            {
                Route route = routes.Pop();
                if (route.hasNode(endNode))
                {
                    if (bestRoute == null || route.length < bestRoute.length)
                    {
                        bestRoute = route;
                    }
                }
                IList<Way> connections = route.local.connections;
                foreach (Way connection in connections)
                {
                    if (!route.hasNode(endNode))
                    {
                        if (route.local.isDirectionAllowed(connection))
                        {
                            if (bestRoute == null || route.length <= bestRoute.length)
                            {
                                Node connectedNode = route.local.getConnectedNode(connection);

                                if (!route.hasNode(connectedNode))
                                {
                                    Route newRoute = new Route(connectedNode, route, connection.weightedLength);
                                    routes.Push(newRoute);      //Zet nieuwe Route op stack met Node andere kant connection
                                }
                            }
                            connection.weightedLength = connection.length;
                        }
                    }
                }
            }

            return bestRoute;
        }
Ejemplo n.º 8
0
        public List<Airplane> planesOnWayInDirection(Way targetway, Node startnode, Airplane source)
        {
            //Maakt een lijst aan met alle vliegtuigen die op een bepaalde weg gaan rijden, en waarbij ze in de richting rijden van startnode > andere node
            List<Airplane> returnlist = new List<Airplane>();

            foreach (Airplane airplane in airplanes)
            {
                if (source != airplane && airplane.navigator != null)
                {
                    if (airplane.navigator.hasWay(targetway))
                    {
                        Node othernode;
                        if (targetway.nodeConnections[0] == startnode)
                            othernode = targetway.nodeConnections[1];
                        else othernode = targetway.nodeConnections[0];
                        if (airplane.navigator.nodes.IndexOf(startnode) < airplane.navigator.nodes.IndexOf(othernode))
                            returnlist.Add(airplane);
                    }
                }
            }

            return returnlist;
        }
Ejemplo n.º 9
0
 public Runway(Node node1, Node node2, int dir, string name)
     : base(node1, node2, dir, name)
 {
 }
Ejemplo n.º 10
0
        /*
         * Permission requesters
         */
        public bool requestWayAccess(Airplane airplane, Way way, Node targetNode)
        {
            if (way != null)
            {
                List<Airplane> currentAirplaneList = new List<Airplane>();
                foreach (Airplane currentAirplane in airplanes)                 // Alle vliegtuigen bekijken
                {
                    if (!currentAirplane.Equals(airplane) && currentAirplane.isOnAirport()) // Eigen vliegtuig niet meerekenen & vliegtuig moet in bereik van Airport zijn.
                    {
                        if (currentAirplane.navigator.currentWay.Equals(way))   // Een ander vliegtuig rijdt op dit moment op de weg
                        {
                            currentAirplaneList.Add(currentAirplane);
                        }
                    }
                }

                if (way.direction != 0)
                {
                    if (currentAirplaneList.Count == 0)
                    {
                        return true;
                    }
                    if (currentAirplaneList.Count == 1)
                        if (currentAirplaneList[0].navigator.getDistanceToTargetNode(currentAirplaneList[0].location) < 700)
                            return true;                                    // Ruw, maar het werkt net zoals hiervoor
                    if (currentAirplaneList.Count == 2)
                        if (Math.Max(currentAirplaneList[0].navigator.getDistanceToTargetNode(currentAirplaneList[0].location), currentAirplaneList[0].navigator.getDistanceToTargetNode(currentAirplaneList[0].location)) < 700)
                            return true;
                    return false;
                }
                else if (!(way is Gate))
                {
                    if (!(way is Runway))
                    {
                    List<Airplane> sameNodeList = new List<Airplane>();
                    foreach (Airplane currentAirplaneListAirplane in currentAirplaneList)
                    {
                        if (currentAirplaneListAirplane.navigator.getTargetNode() != targetNode)
                            sameNodeList.Add(currentAirplaneListAirplane);
                    }

                    if (sameNodeList.Count == 0)
                        return true;
                    if (sameNodeList.Count == 1)
                        if (sameNodeList[0].navigator.getDistanceToTargetNode(sameNodeList[0].location) < 700)
                            return true;
                    if (sameNodeList.Count == 2)
                        if (Math.Max(sameNodeList[0].navigator.getDistanceToTargetNode(sameNodeList[0].location), sameNodeList[1].navigator.getDistanceToTargetNode(sameNodeList[1].location)) < 700)
                            return true;
                    }
                    else if (way is Runway)
                    {
                        if (currentAirplaneList.Count == 0)
                            return true;
                        return false;
                    }
                }

                else if (way is Gate)
                {
                    if (currentAirplaneList.Count == 0)
                        return true;
                }

                return false;
            }
            return false;
        }
Ejemplo n.º 11
0
 public bool listContainsNode(List<Node> nodeList, Node node)
 {
     for (int i = 0; i < nodeList.Count; i++)
     {
         if (nodeList[i].Equals(node))
             return true;
     }
     return false;
 }
Ejemplo n.º 12
0
        public List<Node[]> getNodeMatch(string type, List<int> directions, XmlDocument xmlDocument, List<Node> nodeList, List<string> names)
        {
            List<Node[]> NodeMatch = new List<Node[]>();
            XmlNodeList wayNodes = xmlDocument.SelectNodes("//" + type);
            int i = 0;
            directions.Clear();
            names.Clear();
            foreach (XmlNode xmlNode in wayNodes)
            {
                Node[] matches = new Node[2];
                int nodeX1 = int.Parse(xmlNode.Attributes["X1"].Value);
                int nodeX2 = int.Parse(xmlNode.Attributes["X2"].Value);
                int nodeY1 = int.Parse(xmlNode.Attributes["Y1"].Value);
                int nodeY2 = int.Parse(xmlNode.Attributes["Y2"].Value);
                int nodedir = int.Parse(xmlNode.Attributes["dir"].Value);
                string name = xmlNode.Attributes["name"].Value;
                Node firstNode = new Node(nodeX1, nodeY1);
                Node secondNode = new Node(nodeX2, nodeY2);
                if (!listContainsNode(nodeList, firstNode))
                {
                    nodeList.Add(firstNode);
                    matches[0] = firstNode;
                }
                else
                {
                    foreach (Node node in nodeList)
                    {
                        if (firstNode.Equals(node))
                            matches[0] = node;
                    }
                }
                if (!listContainsNode(nodeList, secondNode))
                {
                    nodeList.Add(secondNode);
                    matches[1] = secondNode;
                }
                else
                {
                    foreach (Node node in nodeList)
                    {
                        if (secondNode.Equals(node))
                            matches[1] = node;
                    }

                }
                if (matches.Count() == 2)
                {
                    NodeMatch.Add(matches);
                    directions.Add(nodedir);
                    names.Add(name);
                    i++;
                }
            }

            return NodeMatch;
        }
Ejemplo n.º 13
0
 public bool requestWayAccess(Airport.Airport airport, Way targetWay, Node targetNode)
 {
     if (airport.requestWayAccess(this, targetWay, targetNode))
     {
         navigator.permissions[navigator.targetNodeNumber] = Navigator.PermissionStatus.GRANTED;
         navigator.permissionCounter++;
         return true;
     }
     else
     {
         navigator.permissions[navigator.targetNodeNumber] = Navigator.PermissionStatus.REQUESTED;
         navigator.permissionCounter++;
         return false;
     }
 }
Ejemplo n.º 14
0
 public Gate(Node node1, Node node2, int dir, string name)
     : base(node1, node2, dir, name)
 {
 }