Exemplo n.º 1
0
        public void AddTest()
        {
            FixedSizeStack<int> stack = new FixedSizeStack<int>(1);
            stack.Add(1, score: 0);
            Assert.IsTrue(stack.Elements.Contains(1));

            stack.Add(2, score: 100);
            Assert.IsTrue(stack.Elements.Contains(1));
            Assert.IsFalse(stack.Elements.Contains(2));

            stack.Add(3, score: -1);
            Assert.IsTrue(stack.Elements.Contains(3));
            Assert.IsFalse(stack.Elements.Contains(1));
        }
Exemplo n.º 2
0
        // Serialize the state and put in the 'undo' stack;
        public string GetStateSerialized()
        {
            string json = this.state.Serialize();

            stateStack.Add(json);
            stateStatckIndex = 0;
            return(json);
        }
Exemplo n.º 3
0
        FixedSizeStack<Image> NearestNeighbor(Image image)
        {
            FixedSizeStack<Image> fss = new FixedSizeStack<Image>(_NbNeighbor);
            int startIndex = 0;
            int endIndex = _nbImage;

            if (SemiRandomNeighbor)
            {
                int nbElementsToTest = _NbNeighbor * NeighborScaleFactor;
                Random gen = new Random();
                startIndex = gen.Next(0, _nbImage - nbElementsToTest);
                endIndex = startIndex + nbElementsToTest;
            }

            double norme = image.Norm;
            int nbImageBlockedByTriangleSpeedUp = 0;

            for (int i = startIndex; i < endIndex; i++)
            {
                if (UseTriangleSpeedUp && fss.IsFull)
                {
                    double d = Math.Abs(_normes[i] - norme);
                    // This image can never be added to stack
                    if (d > fss.MaxScore)
                    {
                        nbImageBlockedByTriangleSpeedUp++;
                        continue;
                    }
                }

                double dist = image.Distance(_images[i]);
                fss.Add(_images[i], dist);
            }
            if (Debug) Console.WriteLine("nbImageBlockedByTriangleSpeedUp:" + nbImageBlockedByTriangleSpeedUp);

            return fss;
        }