Ejemplo n.º 1
0
        public void SoftHillClimbingSearchQ()
        {
            QueenProblem problem      = new QueenProblem(8);
            var          searchMethod = new SoftHillClimbingFirstSearch(problem);
            DateTime     date         = DateTime.Now;

            searchMethod.Run();
            TreeNode currentNode = problem.Destination as TreeNode;

            int counter = 0;

            while (currentNode != null)
            {
                currentNode = currentNode.Parent;
                counter++;
            }

            Assert.Equal(9, counter);
            Assert.Equal(41, searchMethod.InspectedNodes);
        }
Ejemplo n.º 2
0
        public void SoftHillClimbingCrypto()
        {
            CryptoArithmProblem problem = new CryptoArithmProblem();
            var      searchMethod       = new SoftHillClimbingFirstSearch(problem);
            DateTime date = DateTime.Now;
            ConstraintConfiguration startConfiguration = (ConstraintConfiguration)problem.FirstNodes[0].Data;

            searchMethod.Run();
            Assert.Equal(1, problem.SolutionList.Count);
            ConstraintConfiguration endConfiguration = (ConstraintConfiguration)problem.SolutionList[0].Data;
            var variables = endConfiguration.Variables;

            Assert.Equal(1, variables[0].Value);
            Assert.Equal(0, variables[1].Value);
            Assert.Equal(6, variables[2].Value);
            Assert.Equal(2, variables[3].Value);
            Assert.Equal(1, variables[4].Value);
            Assert.Equal(5, variables[5].Value);
            Assert.Equal(1, variables[6].Value);
            Assert.Equal(2, variables[7].Value);
            Assert.Equal(1, variables[8].Value);
        }