Exemple #1
0
        public void TestIntQueueUpdatePriority()
        {
            StablePriorityQueue <Node> stableQueue = new StablePriorityQueue <Node>(100);
            Node n1 = new Node();
            Node n2 = new Node();
            Node n3 = new Node();
            Node n4 = new Node();

            stableQueue.Enqueue(n1, 1);
            stableQueue.Enqueue(n2, 1);
            stableQueue.Enqueue(n3, 1);
            stableQueue.Enqueue(n4, 1);
            Node node = stableQueue.First;

            Assert.IsTrue(node == n1);
            stableQueue.UpdatePriority(n1, 1);
            node = stableQueue.First;
            Assert.IsTrue(node == n1);
            stableQueue.UpdatePriority(n1, 2);
            node = stableQueue.First;
            Assert.IsTrue(node == n2);
            stableQueue.UpdatePriority(n1, 1);
            node = stableQueue.First;
            Assert.IsTrue(node == n1);
            stableQueue.Dequeue();
            node = stableQueue.First;
            Assert.IsTrue(node == n2);
            stableQueue.Dequeue();
            node = stableQueue.First;
            Assert.IsTrue(node == n3);
        }
Exemple #2
0
            public void Update()
            {
                int count = 0;

                using (new LockWait(ref _lock_message))
                {
                    count = processesPerFrame == -1? _queue.count : Math.Min(processesPerFrame, _queue.count);
                    if (count == 0)
                    {
                        return;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        var node = _queue.Dequeue();
                        _list.Remove(node);
                        Message message;
                        if (excuteMap.TryGetValue(node, out message))
                        {
                            _tmp.Enqueue(message);
                        }
                    }
                    if (_list.Count > 0)
                    {
                        for (int i = _list.Count - 1; i >= 0; i--)
                        {
                            _queue.UpdatePriority(_list[i], _list[i].priority - 1);
                        }
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    var message = _tmp.Dequeue();
                    HandleMessage(message);
                }
            }
Exemple #3
0
    public void UpdatePriority(T item, float priority)
    {
        try
        {
            SimpleNode updateMe = GetExistingNode(item);

            queue.UpdatePriority(updateMe, priority);
        }
        catch (InvalidOperationException ex)
        {
            throw new InvalidOperationException("Cannot call UpdatePriority () on a node which is not enqueued: " + item, ex);
        }
    }
            public void Update()
            {
                int             count = 0;
                Queue <Message> _tmp  = Framework.GlobalAllocate <Queue <Message> >();

                using (new LockWait(ref _lock_message))
                {
                    count = processesPerFrame == -1 ? _priorityQueue.count : Math.Min(processesPerFrame, _priorityQueue.count);
                    if (count == 0)
                    {
                        return;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        StablePriorityQueueNode node = _priorityQueue.Dequeue();
                        Message message;
                        if (excuteMap.TryGetValue(node, out message))
                        {
                            _tmp.Enqueue(message);
                            excuteMap.Remove(node);
                        }
                        _updatelist.Remove(node);
                        node.GlobalRecyle();
                    }
                    if (_updatelist.Count > 0)
                    {
                        for (int i = _updatelist.Count - 1; i >= 0; i--)
                        {
                            _priorityQueue.UpdatePriority(_updatelist[i], _updatelist[i].priority - 1);
                        }
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    var message = _tmp.Dequeue();
                    HandleMessage(message);
                }
                _tmp.GlobalRecyle();
            }
        private static void Update_OPTICS(ref Dictionary <PointD, Tuple <bool, double?> > DictionnaryOfOPTICS, List <PointD> list_of_neighbors, PointD point, ref StablePriorityQueue <PointDQueue> seeds, double epsilon, int min_points)
        {
            double?core_dist = Core_distance(DictionnaryOfOPTICS, point, epsilon, min_points);

            foreach (PointD O in list_of_neighbors)
            {
                if (DictionnaryOfOPTICS[O].Item1 == false)
                {
                    double?reachability = Reachability_distance(DictionnaryOfOPTICS, point, O, epsilon, min_points);
                    if (DictionnaryOfOPTICS[O].Item2 == null)
                    {
                        DictionnaryOfOPTICS[O] = new Tuple <bool, double?>(DictionnaryOfOPTICS[O].Item1, reachability);
                        seeds.Enqueue(new PointDQueue(O.X, O.Y), (float)reachability);
                    }
                    else if (reachability < DictionnaryOfOPTICS[O].Item2)
                    {
                        DictionnaryOfOPTICS[O] = new Tuple <bool, double?>(DictionnaryOfOPTICS[O].Item1, reachability);
                        seeds.UpdatePriority(new PointDQueue(O.X, O.Y), (float)reachability);
                    }
                }
            }
        }