Exemplo n.º 1
0
        public void TestPerformOptimization()
        {
            TestIntegerEvaluableState initial = new TestIntegerEvaluableState(2);
            TestIntegerEvaluableState result;

            List <TestIntegerEvaluableState> states         = new List <TestIntegerEvaluableState>();
            List <TestIntegerEvaluableState> expectedStates = new List <TestIntegerEvaluableState>();

            for (int i = 3; i <= 100; i++)
            {
                expectedStates.Add(new TestIntegerEvaluableState(i));
            }

            void eventCallback(object sender, ClimberStepEvent <TestIntegerEvaluableState, int> args)
            {
                states.Add(args.CurrentState);
            };

            climber.ClimberStepPerformedEvent += eventCallback;

            result = climber.Optimize(initial);

            Assert.AreEqual(100, result.Value);
            Assert.AreEqual(expectedStates.Count, states.Count);

            for (int i = 0; i < states.Count; i++)
            {
                Assert.IsTrue(states[i].CompareTo(expectedStates[i]) == 0);
            }
        }
Exemplo n.º 2
0
        public void TestPerformOptimizationReturnsLocalExtrema()
        {
            TestIntegerEvaluableState initial = new TestIntegerEvaluableState(2);
            TestIntegerEvaluableState result;

            generator = new TestIntegerLocalMaximaSuccessorGenerator();
            picker    = new ClimberSuccessorSelector <TestIntegerEvaluableState, int>(generator, comparer);
            algorithm = new LocalClimberAlgorithm <TestIntegerEvaluableState, int>(picker);
            climber   = new ClimberConfiguration <TestIntegerEvaluableState, int>()
                        .ComparesUsing(comparer)
                        .GeneratesSuccessorsWith(generator)
                        .Build();

            result = climber.Optimize(initial);

            Assert.AreEqual(50, result.Value);
        }