Пример #1
0
 public bool AlreadyVisited(Declaration decl)
 {
     return(!Visited.Add(decl));
 }
Пример #2
0
 public virtual bool AlreadyVisited(CppSharp.AST.Type type)
 {
     return(!Visited.Add(type));
 }
Пример #3
0
 public bool AlreadyVisited(Type type)
 {
     return(!Visited.Add(type));
 }
Пример #4
0
        public Result Run(Request request)
        {
            if (IsValidRequest(request))
            {
                return(null);
            }

            Init();
            var result = new Result();

            Map     = request.Map;
            Battery = new Battery {
                Status = request.Battery
            };
            CurrentCoordinate  = request.Start;
            PreviousCoordinate = CurrentCoordinate;
            CurrentFacing      = (Facing)Enum.Parse(typeof(Facing), request.Start.Facing);
            Visited.Add(new Coordinate {
                X = CurrentCoordinate.X, Y = CurrentCoordinate.Y
            });

            for (int i = 0; i < request.Commands.Length; i++)
            {
                CurrentAction = (Action)Enum.Parse(typeof(Action), request.Commands[i]);
                ExecCommand();

                if (IsObstacle())
                {
                    CurrentCoordinate        = PreviousCoordinate;
                    IsRunningBackOffStrategy = true;
                    for (int j = 0; j < AlternativeActions.Path.Length; j++)
                    {
                        if (IsRunningBackOffStrategy)
                        {
                            for (int k = 0; k < AlternativeActions.Path[j].Length; k++)
                            {
                                CurrentAction = (Action)Enum.Parse(typeof(Action), AlternativeActions.Path[j][k]);
                                ExecCommand();
                            }

                            if (!IsObstacle())
                            {
                                IsRunningBackOffStrategy = false;
                                break;
                            }
                            else
                            {
                                CurrentCoordinate        = PreviousCoordinate;
                                IsRunningBackOffStrategy = true;
                            }
                        }
                    }
                }
            }

            result.Visited = Visited.OrderBy(m => m.X).ThenBy(m => m.Y).ToList();
            result.Cleaned = Cleaned.OrderBy(m => m.X).ThenBy(m => m.Y).ToList();
            result.Final   = new Position {
                X = CurrentCoordinate.X, Y = CurrentCoordinate.Y, Facing = CurrentFacing.ToString()
            };
            result.Battery = Battery.Status;

            return(result);
        }
Пример #5
0
 public bool AlreadyVisited(Stmt stmt)
 {
     return(!Visited.Add(stmt));
 }
Пример #6
0
            public override void FindPaths()
            {
                var evalQueue = new ConcurrentQueue <ulong[]>();

                evalQueue.Enqueue(new ulong[] { TargetObject });
                while (evalQueue.Count > 0)
                {
                    if (Stop)
                    {
                        break;
                    }

                    // Level-synchronized BFS: process each frontier in parallel
                    Parallel.ForEach(evalQueue, chain =>
                    {
                        if (chain.Length > MaxDepth)
                        {
                            return;
                        }

                        var current = chain[0];

                        // TODO Check if it's necessary to reduce synchronization around 'Visited'
                        lock (Visited)
                        {
                            if (Visited.Contains(current))
                            {
                                return;
                            }

                            Visited.Add(current);
                        }

                        lock (this)
                        {
                            AddPathIfRootReached(current, chain);
                        }

                        // Turns out ClrMD's heap operations are not thread-safe because the underlying
                        // memory data reader is not thread-safe (WAT?!?). So we have to lock here around
                        // the heap index operations, and that slows everything down to a crawl because
                        // there are some large objects where EnumerateRefsOfObject takes >1000ms.
                        // Throw in one or two of those, and the parallel version runs much slower than
                        // the sequential one.
                        // TODO See if this can be improved, filed an issue on https://github.com/Microsoft/dotnetsamples/issues/21
                        List <ulong> refs;
                        lock (Index)
                        {
                            refs = Index.FindRefs(current).ToList();
                        }

                        Parallel.ForEach(refs, referencingObj =>
                        {
                            var newChain = new ulong[chain.Length + 1];
                            newChain[0]  = referencingObj;
                            Array.Copy(chain, 0, newChain, 1, chain.Length);
                            evalQueue.Enqueue(newChain);
                        });
                    });
                }
            }
Пример #7
0
 private void Initialize()
 {
     Visited.Add(Origin, default);
     Stack.Push(Origin);
 }
 private void Initialize()
 {
     Visited.Add(Origin, default);
     Queue.Enqueue(Origin);
 }