Beispiel #1
0
        public List <Coordinate> GetShortestPath(Coordinate start, Coordinate goal)
        {
            HashSet <Coordinate> visited = new HashSet <Coordinate>();
            Dictionary <Coordinate, Coordinate> parents     = new Dictionary <Coordinate, Coordinate>();
            Dictionary <Coordinate, double>     gScore      = new Dictionary <Coordinate, double>();
            HeapPriorityQueue <Coordinate>      fScoreQueue = new HeapPriorityQueue <Coordinate>(rows * cols);

            parents[start] = start;
            gScore.Add(start, 0);
            fScoreQueue.Enqueue(start, gScore[start] + Heuristic(start, goal));
            while (fScoreQueue.Count() != 0)
            {
                Coordinate current = fScoreQueue.Dequeue();
                Console.Out.WriteLine("");
                Console.Out.WriteLine("Current = " + current.ToString());
                Console.Out.WriteLine("Visited = " + visited.ToString());
                Console.Out.WriteLine("Parents = " + parents.ToString());
                Console.Out.WriteLine("gScore = " + gScore.ToString());
                Console.Out.WriteLine("fScoreQueue = " + fScoreQueue.ToString());
                if (current == goal)
                {
                    return(ReconstructPath(parents, goal));
                }

                visited.Add(start);
                foreach (Coordinate neighbor in board[current.row, current.col].GetNeighborCoordinates())
                {
                    if (visited.Contains(neighbor))
                    {
                        continue;
                    }
                    double newGScore = gScore[current] + Distance(current, neighbor);
                    if (!fScoreQueue.Contains(neighbor))
                    {
                        parents[neighbor] = current;
                        gScore[neighbor]  = newGScore;
                        fScoreQueue.Enqueue(neighbor, newGScore + Heuristic(neighbor, goal));
                    }
                    else if (newGScore < gScore[neighbor])
                    {
                        parents[neighbor] = current;
                        gScore[neighbor]  = newGScore;
                        fScoreQueue.UpdatePriority(neighbor, newGScore + Heuristic(neighbor, goal));
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        public List<Coordinate> GetShortestPath(Coordinate start, Coordinate goal)
        {
            HashSet<Coordinate> visited = new HashSet<Coordinate>();
            Dictionary<Coordinate, Coordinate> parents = new Dictionary<Coordinate, Coordinate>();
            Dictionary<Coordinate, double> gScore = new Dictionary<Coordinate, double>();
            HeapPriorityQueue<Coordinate> fScoreQueue = new HeapPriorityQueue<Coordinate>(rows * cols);
            parents[start] = start;
            gScore.Add(start, 0);
            fScoreQueue.Enqueue(start, gScore[start] + Heuristic(start, goal));
            while (fScoreQueue.Count() != 0)
            {
                Coordinate current = fScoreQueue.Dequeue();
                Console.Out.WriteLine("");
                Console.Out.WriteLine("Current = " + current.ToString());
                Console.Out.WriteLine("Visited = " + visited.ToString());
                Console.Out.WriteLine("Parents = " + parents.ToString());
                Console.Out.WriteLine("gScore = " + gScore.ToString());
                Console.Out.WriteLine("fScoreQueue = " + fScoreQueue.ToString());
                if (current == goal)
                {
                    return ReconstructPath(parents, goal);
                }

                visited.Add(start);
                foreach (Coordinate neighbor in board[current.row,current.col].GetNeighborCoordinates())
                {
                    if (visited.Contains(neighbor)) continue;
                    double newGScore = gScore[current] + Distance(current, neighbor);
                    if (!fScoreQueue.Contains(neighbor))
                    {
                        parents[neighbor] = current;
                        gScore[neighbor] = newGScore;
                        fScoreQueue.Enqueue(neighbor, newGScore + Heuristic(neighbor, goal));
                    }
                    else if (newGScore < gScore[neighbor])
                    {
                        parents[neighbor] = current;
                        gScore[neighbor] = newGScore;
                        fScoreQueue.UpdatePriority(neighbor, newGScore + Heuristic(neighbor, goal));
                    }

                }
            }

            return null;
        }
        public static List<Coordinate> GetShortestPath(Board board, Coordinate start, Coordinate goal)
        {
            HashSet<Coordinate> visited = new HashSet<Coordinate>();
            Dictionary<Coordinate, Coordinate> parents = new Dictionary<Coordinate, Coordinate>();
            Dictionary<Coordinate, double> gScore = new Dictionary<Coordinate, double>();
            HeapPriorityQueue<Coordinate> fScoreQueue = new HeapPriorityQueue<Coordinate>(board.MaxSize());
            parents[start] = start;
            gScore.Add(start, 0);
            fScoreQueue.Enqueue(start, gScore[start] + Heuristic(start, goal));
            while (fScoreQueue.Count() != 0)
            {
                Coordinate current = fScoreQueue.Dequeue();
                //Console.WriteLine("Current = " + current.ToString());
                if (current.Equals(goal))
                {
                    Console.WriteLine("FOUND GOAL!!!");
                    return ReconstructPath(parents, goal);
                }

                visited.Add(current);
                List<Coordinate> neighbors = board.GetNeighbors(current);
                foreach (Coordinate neighbor in neighbors)
                {
                    if (visited.Contains(neighbor)) continue;
                    if (!board.GetSquare(neighbor).IsTraversable()) continue;
                    double newGScore = gScore[current] + Distance(current, neighbor);
                    if (!fScoreQueue.Contains(neighbor))
                    {
                        parents[neighbor] = current;
                        gScore[neighbor] = newGScore;
                        fScoreQueue.Enqueue(neighbor, newGScore + Heuristic(neighbor, goal));
                    }
                    else if (newGScore < gScore[neighbor])
                    {
                        parents[neighbor] = current;
                        gScore[neighbor] = newGScore;
                        fScoreQueue.UpdatePriority(neighbor, newGScore + Heuristic(neighbor, goal));
                    }

                }
            }

            return null;
        }
        /// <summary>
        /// Manages, Tracks, and Logs all Operations
        /// </summary>
        /// <param name="settings">The Configuration File to be used</param>
        /// <param name="basedirectory">The Full Path to the base directory the Service is going to use</param>
        public QueueManager(ConfigurationSettings settings, string basedirectory)
        {
            queuedOperations = new HeapPriorityQueue <OperationContext>();
            repositories     = settings.Repositories.ToDictionary(x => x.Name);
            OperationContextFactory.SetRepositories(repositories);

            RunningOperations    = new ObservableCollection <OperationContext>();
            CanceledOperations   = new ObservableCollection <OperationContext>();
            FailedOperations     = new ObservableCollection <OperationContext>();
            SuccessfulOperations = new ObservableCollection <OperationContext>();
            RetriedOperations    = new ObservableCollection <OperationContext>();

            RunningOperations.CollectionChanged    += (sender, args) => { OnCollectionChanged(new PropertyChangedEventArgs(nameof(RunningOperations)), args); };
            CanceledOperations.CollectionChanged   += (sender, args) => { OnCollectionChanged(new PropertyChangedEventArgs(nameof(CanceledOperations)), args); };
            FailedOperations.CollectionChanged     += (sender, args) => { OnCollectionChanged(new PropertyChangedEventArgs(nameof(FailedOperations)), args); };
            SuccessfulOperations.CollectionChanged += (sender, args) => { OnCollectionChanged(new PropertyChangedEventArgs(nameof(SuccessfulOperations)), args); };
            RetriedOperations.CollectionChanged    += (sender, args) => { OnCollectionChanged(new PropertyChangedEventArgs(nameof(RetriedOperations)), args); };

            cancellationTokens            = new Dictionary <string, CancellationTokenSource>();
            TotalOperationsRun            = 0;
            requestsPostponedForADay      = 0;
            requestsDelayedForConcurrency = 0;
            datedOperations = new Dictionary <string, Dictionary <int, int> >();
            baseDirectory   = basedirectory;
            Settings        = settings;

            if (!Directory.Exists(baseDirectory + @"Logs\"))
            {
                Directory.CreateDirectory(baseDirectory + @"Logs\", FilePermissions.CreateDirectoryPermissions());
            }

            WriteCurrentStatus();
            UpdateConfigurationFile(settings);
            string harvesterStartFileName = $@"{basedirectory}Logs\Harvester Start - {DateTime.Now:yyyy-MM-dd}.txt";

            File.WriteAllText(harvesterStartFileName, "Total Operations: " + queuedOperations.Count());
            File.SetAccessControl(harvesterStartFileName, FilePermissions.CreateFilePermissions());
        }