示例#1
0
        public void partial_evaluation_with_variables(string text, string simplified)
        {
            var visitor = new EvalVisitor(name => name == "X" ? 5.0 : (double?)null);

            Node n = new Analyser().Analyse(new StringTokenizer(text));
            var  s = visitor.VisitNode(n);

            Assert.That(s.ToString(), Is.EqualTo(simplified));
        }
示例#2
0
        public void test_evaluation(string text, double expectedResult)
        {
            Node n = new Analyser().Analyse(new StringTokenizer(text));

            EvalVisitor visitor = new EvalVisitor();
            var         c       = (ConstantNode)visitor.VisitNode(n);

            Assert.That(c.Value, Is.EqualTo(expectedResult));
        }
示例#3
0
        public void test_evaluation(string text, double expectedResult)
        {
            Node n1 = new Analyser().Analyse(new StringTokenizer(text));
            Node n2 = new Analyser().Analyse(new StringTokenizer(text));

            MutationVisitor mutationVisitor = new MutationVisitor(mutationRate: 1);

            mutationVisitor.Mutate(ref n2);

            EvalVisitor visitor = new EvalVisitor();

            visitor.VisitNode(n1);
            double result1 = visitor.Result;

            visitor.VisitNode(n2);
            double result2 = visitor.Result;

            Assert.That(result1, Is.Not.EqualTo(result2));
        }
        public void test_evaluation(string text, string text2)
        {
            Node   n  = new Analyser().Analyse(new StringTokenizer(text));
            Node   n2 = new Analyser().Analyse(new StringTokenizer(text2));
            Random r  = new Random(7);

            SwapGenomeVisitor genomeSwapper = new SwapGenomeVisitor();
            Node n3 = genomeSwapper.SwapGenome(n, n2, r.Next(n.Count), r.Next(n2.Count));

            EvalVisitor visitor = new EvalVisitor();

            visitor.VisitNode(n2);
            double result = visitor.Result;

            visitor.VisitNode(n3);
            double resultBase = visitor.Result;

            Assert.That(result, Is.Not.EqualTo(resultBase));
        }
        public void test_evaluation(string text, double expectedResult)
        {
            Node n = new Analyser().Analyse(new StringTokenizer(text));

            EvalVisitor visitor = new EvalVisitor();

            visitor.VisitNode(n);
            double result = visitor.Result;

            Assert.That(result, Is.EqualTo(expectedResult));
        }
示例#6
0
        private double test_function(Node n)
        {
            double fitness = 0;

            foreach (var value in _values)
            {
                variableSetVisitor.SetVariable(n, "A", value[0]);
                variableSetVisitor.SetVariable(n, "B", value[1]);
                evalVisitor.VisitNode(n);
                fitness -= Math.Abs(value[2] - evalVisitor.Result);
            }
            return(fitness);
        }
示例#7
0
        public void with_variables(string text, double expectedResult)
        {
            Dictionary <string, double> vars = new Dictionary <string, double>();

            vars.Add("X", 5);
            vars.Add("Y", 7);

            var visitor = new EvalVisitor(vars);

            Node n = new Analyser().Analyse(new StringTokenizer(text));
            var  c = (ConstantNode)visitor.VisitNode(n);

            Assert.That(c.Value, Is.EqualTo(expectedResult));
        }
        public void test_evaluation_with_var(string text, double expectedResult)
        {
            Node n = new Analyser().Analyse(new StringTokenizer(text));

            VariableSetVisitor setVisitor = new VariableSetVisitor();

            setVisitor.SetVariable(n, "a", 3.0);

            EvalVisitor visitor = new EvalVisitor();

            visitor.VisitNode(n);

            double result = visitor.Result;

            Assert.That(result, Is.EqualTo(expectedResult));
        }