예제 #1
0
        private TraveledPathData Search()
        {
            this.pathData = new TraveledPathData(root, goal);

            Vertex currentNode = root;
            do
            {
                List<Vertex> neighbours = this.graph.AdjacentVertices(currentNode);
                Double nextCost = double.PositiveInfinity;
                Vertex nextNode = null;
                Edge nextEdge = null;
                foreach (var x in neighbours)
                {
                    Edge edgeFromHeuristic = this.graph.HeuristicData.GetEdge(x, goal);

                    Edge possibleNextEdge = this.graph.GetEdge(currentNode, x);
                    double HOPCOST = edgeFromHeuristic.Weight;
                    if (HOPCOST < nextCost )//&& !this.pathData.TraveledEdges.Contains(possibleNextEdge))
                    {
                        nextNode = x;
                        nextEdge = possibleNextEdge;
                        nextCost = HOPCOST;
                    }
                }
                this.pathData.AddTraveledEdge(this.graph.GetEdge(nextEdge.VerticeFrom, nextEdge.VerticeTo));
                
                if (nextNode == this.goal)
                {
                    return this.pathData;
                }
                currentNode = nextNode;

            } while (true);
        }
예제 #2
0
        private TraveledPathData Search()
        {
            this.pathData = new TraveledPathData(root, goal);

            Vertex currentNode = root;

            do
            {
                List <Vertex> neighbours = this.graph.AdjacentVertices(currentNode);
                Double        nextCost   = double.PositiveInfinity;
                Vertex        nextNode   = null;
                Edge          nextEdge   = null;
                foreach (var x in neighbours)
                {
                    Edge edgeFromHeuristic = this.graph.HeuristicData.GetEdge(x, goal);

                    Edge   possibleNextEdge = this.graph.GetEdge(currentNode, x);
                    double HOPCOST          = edgeFromHeuristic.Weight;
                    if (HOPCOST < nextCost) //&& !this.pathData.TraveledEdges.Contains(possibleNextEdge))
                    {
                        nextNode = x;
                        nextEdge = possibleNextEdge;
                        nextCost = HOPCOST;
                    }
                }
                this.pathData.AddTraveledEdge(this.graph.GetEdge(nextEdge.VerticeFrom, nextEdge.VerticeTo));

                if (nextNode == this.goal)
                {
                    return(this.pathData);
                }
                currentNode = nextNode;
            } while (true);
        }
예제 #3
0
        private void WriteLogWithTraveledData(TraveledPathData data)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                SearchEventManager sem = data.EventManager;

                Logger.ClearLog();

                foreach (var searchEvent in sem.Events)
                {
                    Logger.WriteLogInfo(
                        searchEvent.EventMessage);
                }
                StringBuilder msg = new StringBuilder();

                Logger.WriteLogInfo(string.Format("Total edges EXPLORED in PATH: {0}", data.ExploredEdges.Count));
                foreach (var edge in data.ExploredEdges)
                {
                    msg.Append(edge + "=>");
                }
                Logger.WriteLogInfo(msg.ToString());
                msg.Clear();


                Logger.WriteLogInfo(string.Format("Total edges TRAVELED in PATH: {0}", data.TraveledEdges.Count));
                foreach (var vert in data.TraveledEdges)
                {
                    msg.Append(vert + "=>");
                }
                Logger.WriteLogInfo(msg.ToString());
                msg.Clear();

                Logger.WriteLogInfo("SHORTEST PATH:");

                var shortestPath = data.GetShortestPath();
                foreach (var edge in shortestPath)
                {
                    msg.Append(edge + "=>");
                }
                Logger.WriteLogInfo(msg.ToString());
            }));
        }