public static bool EvaluateFilterForStatement(EPServicesContext servicesContext, EventBean theEvent, AgentInstanceContext agentInstanceContext, FilterHandle filterHandle)
        {
            // context was created - reevaluate for the given event
            var callbacks = new ArrayDeque <FilterHandle>();

            servicesContext.FilterService.Evaluate(theEvent, callbacks, agentInstanceContext.StatementContext.StatementId);

            try
            {
                servicesContext.VariableService.SetLocalVersion();

                // sub-selects always go first
                if (callbacks.Any(handle => handle == filterHandle))
                {
                    return(true);
                }

                agentInstanceContext.EpStatementAgentInstanceHandle.InternalDispatch();
            }
            catch (Exception ex)
            {
                servicesContext.ExceptionHandlingService.HandleException(
                    ex, agentInstanceContext.EpStatementAgentInstanceHandle, ExceptionHandlerExceptionType.PROCESS,
                    theEvent);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The Graham Scan algorithm determines the points belonging to the convex hull in O(n lg n).
        /// </summary>
        /// <param name="points">set of points</param>
        /// <returns>points in the convex hull</returns>
        /// <seealso href="http://en.wikipedia.org/wiki/Graham_scan">Graham scan, Wikipedia</seealso>
        public static List <Point> GrahamScan(List <Point> points)
        {
            if (points.Count <= 3)
            {
                return(new List <Point>(points));
            }

            var ps = new List <Point>(points);

            ps.Sort(new CompareYThenX());
            ps.Sort(new PolarComparator(ps[0]));

            Deque <Point> hull = new ArrayDeque <Point>();

            hull.Push(ps[0]);
            hull.Push(ps[1]);
            hull.Push(ps[2]);

            for (int i = 3; i < points.Count; i++)
            {
                var top = hull.Pop();
                while (hull.Any() && !IsLeftTurn(hull.Peek(), top, ps[i]))
                {
                    top = hull.Pop();
                }
                hull.Push(top);
                hull.Push(ps[i]);
            }

            return(new List <Point>(hull));
        }
Exemplo n.º 3
0
        private static List <IAtomContainer> MakeCut(IBond cut, IAtomContainer mol, Dictionary <IAtom, int> idx, int[][] adjlist)
        {
            var beg = cut.Begin;
            var end = cut.End;

            var bvisit = new LinkedHashSet <IAtom>();
            var evisit = new LinkedHashSet <IAtom>();
            var queue  = new ArrayDeque <IAtom>();

            bvisit.Add(beg);
            evisit.Add(end);

            queue.Add(beg);
            bvisit.Add(end); // stop visits
            while (queue.Any())
            {
                var atom = queue.Poll();
                bvisit.Add(atom);
                foreach (var w in adjlist[idx[atom]])
                {
                    var nbr = mol.Atoms[w];
                    if (!bvisit.Contains(nbr))
                    {
                        queue.Add(nbr);
                    }
                }
            }
            bvisit.Remove(end);

            queue.Add(end);
            evisit.Add(beg); // stop visits
            while (queue.Any())
            {
                var atom = queue.Poll();
                evisit.Add(atom);
                foreach (var w in adjlist[idx[atom]])
                {
                    var nbr = mol.Atoms[w];
                    if (!evisit.Contains(nbr))
                    {
                        queue.Add(nbr);
                    }
                }
            }
            evisit.Remove(beg);

            var bldr  = mol.Builder;
            var bfrag = bldr.NewAtomContainer();
            var efrag = bldr.NewAtomContainer();

            int diff = bvisit.Count - evisit.Count;

            if (diff < -10)
            {
                evisit.Clear();
            }
            else if (diff > 10)
            {
                bvisit.Clear();
            }

            if (bvisit.Any())
            {
                bfrag.Atoms.Add(bldr.NewPseudoAtom());
                foreach (var atom in bvisit)
                {
                    bfrag.Atoms.Add(atom);
                }
                bfrag.AddBond(bfrag.Atoms[0], bfrag.Atoms[1], cut.Order);
                bfrag.Bonds[0].SetProperty(PropertyName_CutBond, cut);
            }

            if (evisit.Any())
            {
                efrag.Atoms.Add(bldr.NewPseudoAtom());
                foreach (var atom in evisit)
                {
                    efrag.Atoms.Add(atom);
                }
                efrag.AddBond(efrag.Atoms[0], efrag.Atoms[1], cut.Order);
                efrag.Bonds[0].SetProperty(PropertyName_CutBond, cut);
            }

            foreach (var bond in mol.Bonds)
            {
                var a1 = bond.Begin;
                var a2 = bond.End;
                if (bvisit.Contains(a1) && bvisit.Contains(a2))
                {
                    bfrag.Bonds.Add(bond);
                }
                else if (evisit.Contains(a1) && evisit.Contains(a2))
                {
                    efrag.Bonds.Add(bond);
                }
            }

            var res = new List <IAtomContainer>();

            if (!bfrag.IsEmpty())
            {
                res.Add(bfrag);
            }
            if (!efrag.IsEmpty())
            {
                res.Add(efrag);
            }
            return(res);
        }