Пример #1
0
        /// <summary>
        /// 该函数为对外接口,负责接收新到的tuple
        /// </summary>
        /// <param name="newTuple"></param>
        public void ReceiveNewTupe(ITuple newTuple)
        {
            newTuple.ArrivalStep = currentStep;
            newTuple.DepartStep  = ComputeDepartStep();
            newTuple.IsOutlier   = false;

            if (SendingEventToOutside)
            {
                Event anEvent = new Event(GetType().ToString(), EventType.NewTupleArrive);
                anEvent.AddAttribute(EventAttributeType.Tuple, newTuple);
                EventDistributor.GetInstance().SendEvent(anEvent);
            }
            //目前一步一个tuple,故可以如此赋值
            CODTuple newCODTuple = new CODTuple(newTuple);

            if (ShouldWindowSlide())
            {
                SlideWindow();
            }

            //Arrive函数是否要在窗口弹出之前执行呢?我觉得是在之后,因为窗口的定义为”总是维护最近的n个object“
            //而arrive应当是以window之内作为执行范围的,若在窗口弹出前执行,岂不是Arrive的执行范围变成了n+1? 所以我将Arrive放在这里
            Arrive(newCODTuple, currentStep);

            AddTupleIntoWindow(newCODTuple);
            currentStep++;
        }
Пример #2
0
        public void AssignKNearestPreceedingNeighboursToTuple(CODTuple newTuple, List <CODTuple> neighbours)
        {
            Dictionary <int, int> k_NearestNeighbour = new Dictionary <int, int>();

            for (int i = 0; i < neighbourThreshold && i < neighbours.Count; i++)
            {
                int neighbourID, neighbourExpTime;
                neighbourID      = neighbours.ElementAt(i).tuple.ID;
                neighbourExpTime = neighbours.ElementAt(i).tuple.DepartStep;
                k_NearestNeighbour.Add(neighbourID, neighbourExpTime);
            }
            newTuple.preceedingNeighboursExpTime = k_NearestNeighbour;
        }
Пример #3
0
        protected void Insert(CODTuple q)
        {
            /*if (q.numberOfSucceedingNeighbour > neighbourThreshold)
             * {
             *  throw new Exception("错误,将SafeInlier插入了");
             * }*/
            CODEvent newCODEvent = new CODEvent(q, q.FindMinExpTime());

            if (newCODEvent.eventTrigger.eventTime != int.MaxValue)
            {
                CODEventQueue.Add(newCODEvent);
                CODEventQueue.Sort(new CODEventComparor());
            }
        }
Пример #4
0
        /// <summary>
        /// 先RangeQuery,再将Tuple加入window
        /// </summary>
        /// <param name="newCODTuple"></param>
        /// <param name="currentStep"></param>
        public void Arrive(CODTuple newCODTuple, int currentStep)
        {
            long            st         = DateTime.Now.Ticks;
            List <CODTuple> neighbours = RangeQuery(newCODTuple.tuple, range, neighbourThreshold);

            TimeUsedByQueryRange += (DateTime.Now.Ticks - st) / (10000000.0);
            for (int i = 0; i < neighbours.Count; i++)
            {
                CODTuple q = neighbours.ElementAt(i);
                q.numberOfSucceedingNeighbour++;

                if (q.numberOfSucceedingNeighbour == neighbourThreshold)
                {
                    SafeInlierCount++;
                }

                if (q.tuple.IsOutlier && (q.numberOfSucceedingNeighbour + q.preceedingNeighboursExpTime.Count == neighbourThreshold))
                {
                    //由于EventQueue不能通知原本是Outlier的邻居,故原本是Outlier的tuple仍然可能保存着已过期的邻居,这里就是删除可能的已过期前驱邻居,保证正确性
                    q.ValidatePrecList(currentStep);
                    if (q.numberOfSucceedingNeighbour + q.preceedingNeighboursExpTime.Count == neighbourThreshold)
                    {
                        RemoveFromOutlier(q.tuple);

                        if (q.preceedingNeighboursExpTime.Count > 0)
                        {
                            Insert(q);
                        }
                    }
                }
            }
            AssignKNearestPreceedingNeighboursToTuple(newCODTuple, neighbours);

            ///
            if (newCODTuple.preceedingNeighboursExpTime.Count < neighbourThreshold)
            {
                AddToOutlier(newCODTuple.tuple);
            }
            else
            {
                Insert(newCODTuple);
            }
            //AddTupleIntoWindow(newCODTuple); //在ReceiveTuple中调用加入Window的动作
        }
Пример #5
0
        public void DepartureNotDuplicateCompute(CODTuple oldTuple, int currentStep)
        {
            CODEvent x = FindMin();

            while (x != null && x.eventTrigger.eventTime < currentStep)
            {
                x = ExtractMin();
            }

            x = FindMin();
            if (x != null)
            {
                while (x.eventTrigger.eventTime == currentStep && FindMin() != null)
                {
                    if (FindMin().codTuple.preceedingNeighboursExpTime.Keys.Contains(oldTuple.tuple.ID))
                    {
                        x = ExtractMin();
                        ExtractCount++;
                        x.codTuple.DeleteFromPreceedingExpTime(oldTuple.tuple.ID);

                        if (x.codTuple.numberOfSucceedingNeighbour + x.codTuple.preceedingNeighboursExpTime.Count < neighbourThreshold)
                        {
                            AddToOutlier(x.codTuple.tuple);
                        }
                        else if (x.codTuple.numberOfSucceedingNeighbour < neighbourThreshold)
                        {
                            //update the event time for next check
                            Insert(x.codTuple);
                        }
                        else if (x.codTuple.numberOfSucceedingNeighbour >= neighbourThreshold)
                        {
                            SavedCount++;
                        }
                        x = FindMin();
                    }
                    else
                    {
                        MisCalTimeCount++;
                        break;
                    }
                }
            }
        }
Пример #6
0
        public void SlideWindow()
        {
            for (int i = 0; i < _slideSpan; i++)
            {
                CODTuple oldTuple = window.Dequeue();
                if (SendingEventToOutside)
                {
                    Event anEvent = new Event("Object Depart", EventType.OldTupleDepart);
                    anEvent.AddAttribute(EventAttributeType.TupleID, oldTuple.tuple.ID);
                    anEvent.AddAttribute(EventAttributeType.Tuple, oldTuple.tuple);
                    EventDistributor.GetInstance().SendEvent(anEvent);
                }
                //Departure(oldTuple, currentStep);
                DepartureNotIncludingSafeInlier(oldTuple, currentStep);
                //DepartureWithNotConsiderSlideSpan(oldTuple, currentStep);
            }

            if (SendingEventToOutside)
            {
                Event e = new Event("window has just Slided", EventType.WindowSlide);
                EventDistributor.GetInstance().SendEvent(e);
            }
        }
Пример #7
0
        public void DepartureWithNotConsiderSlideSpan(CODTuple oldTuple, int currentStep)
        {
            CODEvent x = FindMin();

            if (x != null)
            {
                while (x.eventTrigger.eventTime == currentStep && FindMin() != null)
                {
                    x = ExtractMin();
                    ExtractCount++;
                    if (x.codTuple.preceedingNeighboursExpTime.Keys.Contains(oldTuple.tuple.ID))
                    {
                        x.codTuple.DeleteFromPreceedingExpTime(oldTuple.tuple.ID);

                        if (x.codTuple.numberOfSucceedingNeighbour + x.codTuple.preceedingNeighboursExpTime.Count < neighbourThreshold)
                        {
                            AddToOutlier(x.codTuple.tuple);
                        }
                        else
                        {
                            //update the event time for next check
                            Insert(x.codTuple);
                        }
                        x = FindMin();
                    }
                    else
                    {
                        //把x加回去
                        CODEventQueue.Add(x);
                    }
                }
            }

            //free the memory
            oldTuple.Dispose();
        }
Пример #8
0
 public void AddTupleIntoWindow(CODTuple newTuple)
 {
     window.Enqueue(newTuple);
 }
Пример #9
0
 public CODEvent(CODTuple t, CODEventTrigger e)
 {
     codTuple     = t;
     eventTrigger = e;
 }