public void Launch(TreeSearchResult Search, PointOfInterest point)
 {
     _search = Search;
     _point = point;
     BuildList();
     Show();
 }
 public void Launch(TreeSearchResult Search, PointOfInterest point)
 {
     _search = Search;
     _point  = point;
     BuildList();
     Show();
 }
        public void BreakWalls(IReshapeAbleMaze reshapeAble)
        {
            TreeSearchResult <MazePosition> tree = this.GetSearchTree(reshapeAble);

            // closes all the doors of the Maze, to open them based on the tree
            reshapeAble.CloseAllDoors();
            Stack <State <MazePosition> > positions = new Stack <State <MazePosition> >();

            positions.Push(tree.GetRoot());
            // farthest will eventioally be the End Position of the maze
            State <MazePosition> farthest = tree.GetRoot();

            while (positions.Count > 0)
            {
                State <MazePosition> pos = positions.Pop();
                ICollection <State <MazePosition> > children
                    = tree.getAllChildrenOf(pos);
                foreach (State <MazePosition> child in children)
                {
                    // open the door between pos and it's child
                    reshapeAble.ChangeDoorStateBetween(pos.TState, child.TState,
                                                       DoorState.Opened);
                    positions.Push(child);
                    if (child.Distance > farthest.Distance)
                    {
                        // found a farer state
                        if (reshapeAble.ChangeEndPosition(child.TState))
                        {
                            farthest = child;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void перейтиККодуToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tvAspects.SelectedNode == null)
                {
                    return;
                }
                PointOfInterest pt = Adapter.GetPointByNode(tvAspects.SelectedNode);
                if ((pt?.Context?.Count ?? 0) == 0)
                {
                    return;
                }
                string           fileName = Manager.GetFullFilePath(pt.FileName);
                PointOfInterest  Tree     = ide.IsDocumentOpen(fileName) ? treeManager.GetTree(fileName, ide.GetDocument(fileName)) : treeManager.GetTree(fileName);
                TreeSearchResult Search   = TreeSearchEngine.FindPointInTree2(Tree, pt, treeManager.GetText(fileName));
                if (Search.Count == 0)
                {
                    SetStatus(string.Format(Strings.CannotFindPoint, pt.Title));
                }
                else if (Search.Singular && (ModifierKeys != Keys.Control))
                {
                    //update point anchor if similarity != 1
                    string path = Manager.GetFullFilePath(pt.FileName);
                    ide.NavigateToFileAndPosition(path, Search[0].Location.StartLine, Search[0].Location.StartColumn);
                    SetStatus("");
                }
                else
                {
                    if (Search.Count >= 2)
                    {
                        int d1 = TreeSearchOptions.Equility - Search.GetTotalMatch(0);
                        int d2 = TreeSearchOptions.Equility - Search.GetTotalMatch(1);
                        //float near = Math.Max(pt.NearG, pt.NearL);
                        //float threshold = ((near + 4) / 5 + 1) / 2; //hardcoded
                        //if (Search._result[0].TotalMatch > threshold*TreeSearchOptions.Equility && Search._result[1].TotalMatch < threshold * TreeSearchOptions.Equility)
                        if (d2 != 0 && d2 >= d1 * 2 && (ModifierKeys != Keys.Control))
                        {
                            string path = Manager.GetFullFilePath(pt.FileName);
                            ide.NavigateToFileAndPosition(path, Search[0].Location.StartLine, Search[0].Location.StartColumn);
                            SetStatus("");
                            return;
                        }
                    }

                    fmSelectPoint.Launch(Search, pt);
                    SetStatus("");
                }
            }
            catch (Exception exc)
            {
                ExceptionInfoHelper.ShowInfo(exc);
            }
        }
Beispiel #5
0
        private static void ProcessInputFile(string BaseDir, string inputFile)
        {
            AspectManager AM = new AspectManager();
            ParserWrapper pw = _parser._pool.GetParserWrapper();

            AM.WorkingAspect = AM.DeserializeAspect(inputFile, pw);
            _parser._pool.ReleaseParserWrapper(pw);
            int             TotalNodes = AM.WorkingAspect.Items.Count;
            int             NotFound   = 0;
            int             Errors     = 0;
            int             Found      = 0;
            int             NotChanged = 0;
            TreeManager     TM         = new TreeManager();
            PointOfInterest NewAspect  = new PointOfInterest();
            Semaphore       S          = new Semaphore(1, 1);
            int             counter    = 0;

            Parallel.For(0, AM.WorkingAspect.Items.Count, (i) =>
                         //for (int i = 0; i < AM.WorkingAspect.Items.Count; ++i)
            {
                Interlocked.Increment(ref counter);
                if (counter % 10 == 0)
                {
                    S.WaitOne();
                    Console.Write("\rNodes left: " + (AM.WorkingAspect.Items.Count - counter) + "        ");
                    S.Release();
                }
                try
                {
                    PointOfInterest Pt      = AM.WorkingAspect.Items[i];
                    PointOfInterest Root    = TM.GetTree(BaseDir + Pt.FileName);
                    string text             = TM.GetText(BaseDir + Pt.FileName);
                    TreeSearchResult Search = TreeSearchEngine.FindPointInTree2(Root, Pt, text);
                    if (Search.Count == 0)
                    {
                        Interlocked.Increment(ref NotFound);
                    }
                    else if (Search.Singular)
                    {
                        if (Search.GetNodeSimilarity(0) == 1)
                        {
                            Interlocked.Increment(ref NotChanged);
                            return;
                            //continue;
                        }
                        else
                        {
                            Interlocked.Increment(ref Found);
                            AM.WorkingAspect.Items[i].Title = "+ " + AM.WorkingAspect.Items[i].Title;
                        }
                    }
                    else
                    {
                        if (Search.Count >= 2)
                        {
                            float d1 = 1 - Search.GetNodeSimilarity(0);
                            float d2 = 1 - Search.GetNodeSimilarity(1);
                            //float near = Math.Max(Pt.NearG, Pt.NearL);
                            //float threshold = ((near + 4) / 5 + 1) /2 ; //hardcoded
                            //if (Search.GetNodeSimilarity(0) >= threshold && Search.GetNodeSimilarity(1) < threshold)
                            if (d2 != 0 && d2 >= d1 * 2)
                            {
                                Interlocked.Increment(ref Found);
                                AM.WorkingAspect.Items[i].Title = "+ " + AM.WorkingAspect.Items[i].Title;
                                //return;
                                //continue;
                            }
                        }
                    }
                    S.WaitOne();
                    NewAspect.Items.Add(AM.WorkingAspect.Items[i]);
                    S.Release();
                }
                catch (Exception e)
                {
                    S.WaitOne();
                    Console.WriteLine(e.Message);
                    Errors += 1;
                    S.Release();
                }
            }
                         );
            AM.WorkingAspect = NewAspect;
            int Ambiguous = AM.WorkingAspect.Items.Count - Found;

            AM.SerializeAspect(inputFile, true);
            File.WriteAllText(inputFile + ".report.txt", "Total: " + TotalNodes + ", Not changed: " + NotChanged + ", found: " + Found + ", Not found: " + NotFound + ", errors: " + Errors + ", ambiguous: " + Ambiguous);
            Console.Write("\rNodes left: 0        ");
            Console.WriteLine();
        }