Beispiel #1
0
        public static void DisplayAllNeighbours(Node nodeToDisplay, string nodeType)
        {
            Console.Write("Neighbours of " + nodeType + " :\n");
            int i = 1;

            foreach (Node neighbour in nodeToDisplay.GetNeighbours())
            {
                DebugFunctions.DisplayNodeInfoInConsole(neighbour, "Neighbour " + i);
                i++;
            }
        }
Beispiel #2
0
        public double findDistanceToStartCH(NodeForPathfinding startingNode)
        {
            // Console.Write("FINDING DISTANCE TO START FOR NODE " + this.uniqueNumber + " . STARTING NODE IS : " + startingNode.uniqueNumber + "\n");
            double             distanceToStart = 0;
            NodeForPathfinding currentNode     = this;
            NodeForPathfinding nextPredecessor = this.predecessor;
            bool foundStartingNode             = false;

            while (!foundStartingNode)
            {
                // DebugFunctions.DisplayNodeInfoInConsole(currentNode, "currentNode");
                // DebugFunctions.DisplayNodeInfoInConsole(nextPredecessor, "nextPredecessor");
                // DebugFunctions.DisplayLinksOfNode(currentNode, "currentNode");
                Link linkBetweenNodes = currentNode.links.Find(Link => Link.nodes[0].uniqueNumber == nextPredecessor.uniqueNumber || Link.nodes[1].uniqueNumber == nextPredecessor.uniqueNumber);
                // we use linkBetweenNodes.cost/ linkBetweenNodes.cost just to have "1", but to make sure that the link exist. It will make an error if it doesnt.
                try { distanceToStart = distanceToStart + linkBetweenNodes.cost; }
                catch
                {
                    Console.Write("\nERROR : LINK MISSING FROM A CERTAIN NODE\n");
                    DebugFunctions.DisplayNodeInfoInConsole(currentNode, "currentNode");
                    DebugFunctions.DisplayLinksOfNode(currentNode, "currentNode");
                    DebugFunctions.DisplayNodeInfoInConsole(nextPredecessor, "nextPredecessor");
                    DebugFunctions.DisplayLinksOfNode(nextPredecessor, "nextPredecessor");
                }
                if (nextPredecessor == startingNode)
                {
                    foundStartingNode = true;
                }
                else
                {
                    currentNode     = nextPredecessor;
                    nextPredecessor = currentNode.predecessor;
                }
            }

            return(distanceToStart);
        }