internal void Enqueue(Action <Camera> queueAction, Camera camera, PriorityValue priority)
        {
            _queue.Enqueue(new ActionInfo(queueAction, true, _dispatcher, camera), new Priority(priority));

            if (_queue.Count > 1)
            {
                return;
            }

            ActionInfo result = null;

            result = _queue.Peek();
            //_queue.TryPeek(out result);
            if (result != null)
            {
                _queue.UpdatePriority(result, new Priority(PriorityValue.Critical));
                try
                {
                    result.Exec();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("message: {0}; stacktrace: {1}", e.Message, e.StackTrace);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// implmentation of the Search method.
        /// </summary>
        /// <param name="searchable"> the searching problem to search in. </param>
        /// <returns> Solution object that includes the nodes of the route from the initial node to the goal.</returns>
        public override Solution <T> Search(ISearchable <T> searchable)
        {
            ConcurrentPriorityQueue <State <T>, double> open = new ConcurrentPriorityQueue <State <T>, double>();

            closed = new HashSet <State <T> >();

            State <T> initialState = searchable.GetInitialState();

            open.Enqueue(initialState, 0);
            while (open.Count != 0)
            {
                State <T> node = open.Dequeue();
                evaluatedNodes++;
                if (node.Equals(searchable.GetGoalState()))
                {
                    return(new Solution <T>(BackTrace(searchable), GetNumberOfNodesEvaluated()));
                }

                closed.Add(node);
                foreach (State <T> adjacent in searchable.GetAllPossibleStates(node))
                {
                    if (!closed.Contains(adjacent) && !open.Contains(adjacent))
                    {
                        adjacent.CameFrom  = node;
                        adjacent.TotalCost = node.TotalCost + adjacent.Cost;
                        open.Enqueue(adjacent, adjacent.TotalCost);
                    }
                    else
                    {
                        if ((node.TotalCost + adjacent.Cost) < adjacent.TotalCost)
                        {
                            adjacent.CameFrom  = node;
                            adjacent.TotalCost = node.TotalCost + adjacent.Cost;

                            if (open.Contains(adjacent))
                            {
                                open.UpdatePriority(adjacent, adjacent.TotalCost);
                            }
                            else
                            {
                                closed.Remove(adjacent);
                                open.Enqueue(adjacent, adjacent.TotalCost);
                            }
                        }
                    }
                }
            }

            return(null);
        }