Пример #1
0
 static void Main ( string[] args )
 {
     string path = @"D:\CSharp\ProjectX\AVL2\Commands\Commands.txt";
     DateTime d = DateTime.Now;
     AVL<int> tree = new AVL<int>();
     RunCommands(tree , path);
     tree.Clear();
     TimeSpan elapse = DateTime.Now - d;
     Console.WriteLine(elapse.ToString());
 }
Пример #2
0
        public static void RunCommands ( AVL<int> tree , string path )
        {
            string[] lines = System.IO.File.ReadAllLines(path);
            foreach(string line in lines)
            {
                if(line.Contains("Insert:"))
                {
                    string onlyNum = line.Remove(0 , "Insert:".Length);
                    string[] numbers = onlyNum.Split(' ');
                    foreach(var item in numbers)
                    {
                        int num;
                        if(Int32.TryParse(item , out num))
                        {
                            tree.Insert(num);
                            Console.WriteLine($"Inserted {num}");
                        }
                    }
                }
                else if(line.Contains("Delete:"))
                {
                    string onlyNum = line.Remove(0 , "Delete:".Length);
                    string[] numbers = onlyNum.Split(' ');
                    foreach(var item in numbers)
                    {
                        int num;
                        if(Int32.TryParse(item , out num))
                        {
                            tree.Delete(num);
                            Console.WriteLine($"Deleted {num}");

                        }
                    }
                }
                else if(line.Contains("Find:"))
                {
                    string onlyNum = line.Remove(0 , "Find:".Length);
                    string[] numbers = onlyNum.Split(' ');
                    foreach(var item in numbers)
                    {
                        int num;
                        if(Int32.TryParse(item , out num))
                        {
                            if(tree.Find(num) != null)
                            {
                                Console.WriteLine($"Found {num}");
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private void Main_Load(object sender, EventArgs e)
        {
            tree = new AVL();

            tree.Initialize();

            string log = "Árvore Iniciada" + Environment.NewLine;

            txtLog.Text = log;

            //appPath = appPath + "\\" + TamanhoInteiro.ToString() + ".txt";
            appPath = appPath + "\\" + "100000 - Random.txt";
        }
Пример #4
0
        public void Rebalance_TestHeightThreeNodes()
        {
            // Arrange
            var avl = new AVL <int>();

            for (var i = 1; i < 10; i++)
            {
                avl.Insert(i);
            }

            // Assert
            Assert.AreEqual(3, avl.Root.Right.Height); // 6
        }
Пример #5
0
        public void Rebalance_SingleLeft()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            // Act
            avl.Insert(1);
            avl.Insert(2);
            avl.Insert(3);

            // Assert
            Assert.AreEqual(2, avl.Root.Value);
        }
Пример #6
0
        public void Height_RootRight()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            avl.Insert(1);
            avl.Insert(2);

            // Act
            // Assert
            Assert.AreEqual(2, avl.Root.Height);
            Assert.AreEqual(1, avl.Root.Right.Height);
        }
Пример #7
0
    static void Main(string[] args)
    {
        AVL <int> avl = new AVL <int>();

        for (int i = 50; i < 100; i++)
        {
            avl.Insert(i);
        }

        avl.DeleteMin();

        avl.EachInOrder(Console.WriteLine);
    }
Пример #8
0
        public void Rebalance_TestHeightFourNodes()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            for (int i = 1; i < 10; i++)
            {
                avl.Insert(i);
            }

            // Assert
            Assert.AreEqual(4, avl.Root.Height); // 4
        }
Пример #9
0
    static void Main(string[] args)
    {
        AVL <int> tree = new AVL <int>();

        tree.Insert(1);
        tree.Insert(2);
        tree.Insert(3);
        tree.Insert(4);
        tree.Insert(5);
        tree.Insert(6);

        Console.WriteLine();
    }
Пример #10
0
        static void Main(string[] args)
        {
            var gavlTree = new GenericAvlTree <int, string>();

            gavlTree.Insert(5, "5");
            gavlTree.Insert(3, "3");
            gavlTree.Insert(7, "7");
            gavlTree.Insert(2, "2");
            gavlTree.Insert(10, "10");
            gavlTree.Insert(8, "8");
            gavlTree.Insert(1, "1");
            gavlTree.Delete(10);

            foreach (var avlNode in gavlTree)
            {
                Console.WriteLine(avlNode);
            }


            AVL avlTree = new AVL();

            avlTree.Add(5);
            avlTree.Add(3);
            avlTree.Add(7);
            avlTree.Add(2);
            avlTree.Add(10);
            avlTree.Add(8);
            avlTree.Add(1);
            avlTree.Delete(10);
            avlTree.DisplayTree();

            RedBlackTree rbTree = new RedBlackTree();

            rbTree.Insert(5);
            rbTree.Insert(3);
            rbTree.Insert(7);
            rbTree.Insert(1);
            rbTree.Insert(9);
            rbTree.Insert(-1);
            rbTree.Insert(11);
            rbTree.Insert(6);
            rbTree.DisplayTree();
            rbTree.Delete(-1);
            rbTree.DisplayTree();
            rbTree.Delete(9);
            rbTree.DisplayTree();
            rbTree.Delete(5);
            rbTree.DisplayTree();

            Console.ReadLine();
        }
Пример #11
0
    static void Main(string[] args)
    {
        AVL <int> tree = new AVL <int>();

        tree.Insert(1);
        tree.Insert(2);
        tree.Insert(3);
        tree.Insert(4);
        tree.Insert(5);
        tree.Insert(6);
        tree.Insert(10);
        //tree.Insert(5);
        //tree.Insert(8);
    }
Пример #12
0
    public void Delete_Root_EmptyTree()
    {
        AVL <int> avl = new AVL <int>();

        // Act
        avl.Delete(5);
        List <int> result = new List <int>();

        avl.EachInOrder(result.Add);

        // Assert
        int[] expectedNodes = new int[] { };
        CollectionAssert.AreEqual(expectedNodes, result.ToArray());
    }
Пример #13
0
        /// <summary>
        /// Find objects using a template matching technique.
        /// </summary>
        void FindObjects()
        {
            //mr?? 这里并没有用 Nullable; Object2D是class;
            var foundObjects = new List <Object2D>();

            // Use data from parameters object. Reducing ranges of parameters must be performed
            // to avoid exceptions.

            //mr?? 这个AVL方法与AVS中的同名Fiter相比较, 参数有区别.
            AVL.LocateMultipleObjects_Edges(sourceImage,                                          //输入图像
                                            edgeModel,                                            //mr?? 模板数据 这里的edgeModel并没有使用SafeNullable<T>类型
                                            0,                                                    //最小金字塔值
                                            Math.Max(0.1f, parameters.EdgeThresholdLevel),        //边界强度最小值
                                            EdgePolarityMode.Ignore,                              //不指定边界极性
                                            EdgeNoiseLevel.High,                                  //设置为High表示模板与图像中的待查找目标差别较大, 设置为Low表示差别较小
                                            false,                                                //是否匹配出现图像边缘的目标, false表示不用匹配
                                            Math.Max(0, Math.Min(1.0f, parameters.MinimalScore)), //有效目标的最低匹配得分
                                            Math.Max(0.1f, parameters.MinimalDistances),          //目标间最小距离
                                            foundObjects                                          //输出找到的所有目标
                                            );

            // Draw rectangles on an image to show results.

            using (var previewImage = new Image(sourceImage))
            {
                if (parameters.DrawResultsOnPreview)
                {
                    foreach (var match in foundObjects)
                    {
                        //mr:: 在找到目标的外部画矩形框. match是Object2D类型, match.Match是Rectangle2D类型
                        AVL.DrawRectangle(previewImage, match.Match, Pixel.Red, new DrawingStyle());
                    }
                }

                if (previewImagebox.Image != null)
                {
                    previewImagebox.Image.Dispose();
                }

                //mr:: 生成System.Drawing.Bitmap对象,显示在pictureBox中.
                previewImagebox.Image = previewImage.CreateBitmap();
            }

            //mr?? https://www.fab-image.com/en/home/
            if (edgeModelDesigner.ReferenceFrame != null)
            {
                //mr::输出目标在原图像上的坐标位置 (Exact position of the model object in the image.)
                referenceLabel.Text = "Frame: " + edgeModelDesigner.ReferenceFrame.Value;
            }
        }
Пример #14
0
        public void Rebalance_TestHeightTwoNodes()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            for (int i = 1; i < 10; i++)
            {
                avl.Insert(i);
            }

            // Assert
            Assert.AreEqual(2, avl.Root.Left.Height);        // 2
            Assert.AreEqual(2, avl.Root.Right.Right.Height); // 8
        }
Пример #15
0
        public void Performance_Insert_Contains()
        {
            var avl = new AVL <int>();

            for (int i = 0; i < 100000; i++)
            {
                avl.Insert(i);
            }

            for (int i = 0; i < 100000; i++)
            {
                Assert.IsTrue(avl.Contains(i));
            }
        }
Пример #16
0
 internal void CheckNode(AVL <int> .Node node)
 {
     Assert.True(node.Balance <= 1 && node.Balance >= -1);
     if (node.Left != null)
     {
         Assert.True(node.Left.CompareTo(node) < 0);
         CheckNode(node.Left);
     }
     if (node.Right != null)
     {
         Assert.True(node.Right.CompareTo(node) >= 0);
         CheckNode(node.Right);
     }
 }
Пример #17
0
        public void Add_Random()
        {
            AVL <int> tree   = new AVL <int>();
            Random    random = new Random();

            for (int i = 0; i < 1000; ++i)
            {
                tree.Add(random.Next(1000000));
                Assert.IsTrue(tree.CheckAVL());
                List <int> list    = tree.InOrder();
                List <int> control = new List <int>(list);
                control.Sort();
                CollectionAssert.AreEqual(control, list);
            }
        }
        /// <summary>
        /// Finds bounding box of blister on image
        /// </summary>
        private void LocateBlister(Image inImage, out Rectangle2D?blisterBoundingBox)
        {
            Segment2D?horizontalBorder, verticalBorder;

            AVL.FitSegmentToEdges(inImage, verticalFittingMap, scanParams, Selection.Best, null, 0.1f, null, out verticalBorder);

            AVL.FitSegmentToEdges(inImage, horizontalFittingMap, scanParams, Selection.Best, null, 0.1f, null, out horizontalBorder);

            if (horizontalBorder.HasValue && verticalBorder.HasValue)
            {
                CreateBlisterRectangleFromBorders(verticalBorder, horizontalBorder, out blisterBoundingBox);
                return;
            }
            blisterBoundingBox = null;
        }
Пример #19
0
        public void Contains_ExistingElement_ShouldReturnTrue()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            avl.Insert(2);
            avl.Insert(1);
            avl.Insert(3);

            // Act
            // Assert
            Assert.IsTrue(avl.Contains(1));
            Assert.IsTrue(avl.Contains(2));
            Assert.IsTrue(avl.Contains(3));
        }
Пример #20
0
        public void Contains_NonExistingElement_ShouldReturnFalse()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            avl.Insert(2);
            avl.Insert(1);
            avl.Insert(3);

            // Act
            bool contains = avl.Contains(5);

            // Assert
            Assert.IsFalse(contains);
        }
Пример #21
0
 public bool buscar(AVL root, string nick)
 {
     if (buscarR(nick, root.raiz) != null)
     {
         if (buscarR(nick, root.raiz).nickname == nick)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Пример #22
0
    public void DeleteMin_Empty_Tree_Should_Work_Correctly()
    {
        // Arrange
        AVL <int> avl = new AVL <int>();

        // Act
        avl.DeleteMin();
        List <int> nodes = new List <int>();

        avl.EachInOrder(nodes.Add);

        // Assert
        int[] expectedNodes = new int[] { };
        CollectionAssert.AreEqual(expectedNodes, nodes);
    }
Пример #23
0
    public void InsertarAVL(AVL root, string nick, string pass, string correo)
    {
        nodoAVL nuevo    = new nodoAVL(nick, pass, correo);
        ABB     nuevoABB = new ABB();

        nuevo.sigABB = nuevoABB;
        if (root.raiz == null)
        {
            root.raiz = nuevo;
        }
        else
        {
            root.raiz = InsertarAVLR(root.raiz, nuevo);
        }
    }
Пример #24
0
        public void TraverseInOrder_AfterSingleInsert()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            avl.Insert(1);

            // Act
            List <int> nodes = new List <int>();

            avl.EachInOrder(nodes.Add);

            // Assert
            int[] expectedNodes = new int[] { 1 };
            CollectionAssert.AreEqual(expectedNodes, nodes);
        }
Пример #25
0
    static void Main(string[] args)
    {
        AVL <int> avl = new AVL <int>();

        for (int i = 1; i < 10; i++)
        {
            avl.Insert(i);
        }

        avl.Delete(4);
        avl.Delete(2);
        avl.Delete(1);
        avl.EachInOrder(x => Console.Write(x + " "));
        var root = avl.Root;
        //Console.WriteLine(root.Value);
    }
Пример #26
0
        public void Rebalance_DoubleLeft()
        {
            // Arrange
            AVL <int> avl = new AVL <int>();

            // Act
            avl.Insert(5);
            avl.Insert(7);
            avl.Insert(6);

            // Assert
            Assert.AreEqual(6, avl.Root.Value);
            Assert.AreEqual(2, avl.Root.Height);
            Assert.AreEqual(1, avl.Root.Left.Height);
            Assert.AreEqual(1, avl.Root.Right.Height);
        }
Пример #27
0
 public Persona(string password, string mail, string conectado = "1")
 {
     this.password = password;
     this.mail     = mail;
     if (conectado.Equals("1"))
     {
         this.conectado = true;
     }
     else
     {
         this.conectado = false;
     }
     juegos    = new ListaD <Juego> ();
     contactos = new AVL <Persona>();
     //juegos = new Lista<Juego>();
 }
Пример #28
0
    static void Main(string[] args)
    {
        AVL <int> avl = new AVL <int>();

        for (int i = 1; i < 10; i++)
        {
            avl.Insert(i);
        }

        avl.Delete(4);

        var root = avl.Root;

        //Assert.AreEqual(5, root.Value);
        //Assert.AreEqual(4, root.Height);
    }
Пример #29
0
        /// <summary>
        /// Initializes the GasketInspector
        /// </summary>
        /// <param name="templateImage">Image with template gasket</param>
        public static void Init(Image templateImage)
        {
            Box modelBoundingBox;

            AVL.CreateBox(new Location(30, 185), Anchor2D.TopLeft, 100, 125, out modelBoundingBox);

            using (var modelRegion = new Region())
            {
                AVL.CreateBoxRegion(modelBoundingBox, templateImage.Width, templateImage.Height, modelRegion);

                AVL.CreateEdgeModel(templateImage, modelRegion, null, 0, null, 0.0f, 35.0f, 15.0f, 0.0f, 360.0f, 1.0f, 1.0f,
                                    1.0f, 1.0f, 1.0f, edgeModel);
            }

            isInitialized = true;
        }
Пример #30
0
        public void Rebalance_DoubleRight()
        {
            // Arrange
            var avl = new AVL <int>();

            // Act
            avl.Insert(5);
            avl.Insert(2);
            avl.Insert(4);

            // Assert
            Assert.AreEqual(4, avl.Root.Value);
            Assert.AreEqual(2, avl.Root.Height);
            Assert.AreEqual(1, avl.Root.Left.Height);
            Assert.AreEqual(1, avl.Root.Right.Height);
        }
Пример #31
0
        public void Insert10Keys_ContainsNotInsertedKey_ReturnsFalse()
        {
            int[] keys          = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int   noInsertedKey = 123456;

            AVL tree = new AVL();

            for (int i = 0; i < 10; i++)
            {
                tree.Insert(keys[i]);
            }

            bool containsKey = tree.ContainsKey(noInsertedKey);

            Assert.IsFalse(containsKey);
        }
        /// <summary>
        /// Performs inspection on blister image
        /// </summary>
        /// <param name="ioImage">Image which will be inspected, and on which results will be drawn</param>
        public void DoInspection(Image ioImage)
        {
            if (isFirstTime)
            {
                CreateScanningMaps(ioImage);
                isFirstTime = false;
            }

            Rectangle2D?blisterBoundingBox;

            LocateBlister(ioImage, out blisterBoundingBox);

            if (!blisterBoundingBox.HasValue)
            {
                throw new ApplicationException("Couldn't locate blister on image!");
            }

            PreprocessBlisterImage(ref ioImage, blisterBoundingBox.Value);

            var correctCircles   = new List <Circle2D>();
            var incorrectCircles = new List <Circle2D>();

            foreach (var point in referencePoints)
            {
                Rectangle2D inspectionRect;
                AVL.CreateRectangle(point, Anchor2D.MiddleCenter, 0.0f, 102.0f, 102.0f, out inspectionRect);

                bool isPresent;
                AVL.CheckPresence_PixelAmount(ioImage, new ShapeRegion(inspectionRect, RectangularRoiMask.Ellipse), null,
                                              HSxColorModel.HSV, 26,
                                              52, 42, null, 62, null, 0.8f, 1.0f, out isPresent);

                Circle2D pillSpot;
                AVL.CreateCircle(point, Anchor2D.MiddleCenter, 62.0f, out pillSpot);

                if (isPresent)
                {
                    correctCircles.Add(pillSpot);
                }
                else
                {
                    incorrectCircles.Add(pillSpot);
                }
            }

            DrawResults(ioImage, correctCircles, incorrectCircles);
        }