Пример #1
0
        public void CanTranslateTest1()
        {
            var list = new List <IGenoTypeNode>
            {
                new SquareRoot(),
                new Multiplication(),
                new Plus(),
                new Minus(),
                new FeatureTerminal("a"),
                new FeatureTerminal("b"),
                new FeatureTerminal("c"),
                new FeatureTerminal("d")
            };

            var phenoTypeTree = new GeneExpression.PhenoTypeTree(list);

            var expresssion = phenoTypeTree.ToString();

            Assert.Equal("SQRT(((a+b)*(c-d)))", expresssion);
        }
Пример #2
0
        public void CanTranslateTest3()
        {
            var randomGenerator = new UniformRandomGenerator();

            var possibleFunctions = new List <IGenoTypeNode>
            {
                new SquareRoot(),
                new Multiplication(),
                new Division(),
                new Plus(),
                new Minus(),
                new Minimum(),
                new Maximum(),
                new Not(),
                new Exp(),
                new Sinus(),
                new Cosinus()
            };

            var possibleTerminals = new List <IGenoTypeNode>
            {
                new FeatureTerminal("a"),
                new FeatureTerminal("b"),
                new FeatureTerminal("c"),
                new FeatureTerminal("d")
            };

            var eaGeneExpressionParameters = new EaGeneExpressionParameters(20, possibleFunctions, possibleTerminals);
            var parameterTerminalFactory   = new ParameterTerminalFactory(eaGeneExpressionParameters, randomGenerator);
            var genoTypeFactory            = new GenoTypeFactory(eaGeneExpressionParameters, randomGenerator, parameterTerminalFactory);

            eaGeneExpressionParameters.ParameterTypeInteger = true;
            eaGeneExpressionParameters.ConstantProbability  = 0;

            var genoType      = genoTypeFactory.GetGenoType();
            var phenoTypeTree = new GeneExpression.PhenoTypeTree(genoType.GenoTypeNodes);

            var expresssion = phenoTypeTree.ToString();
        }
Пример #3
0
        public void CanCrossover()
        {
            var listLeft = new List <IGenoTypeNode>
            {
                new SquareRoot(),
                new Multiplication(),
                new Plus(),
                new Minus(),
                new FeatureTerminal("a"),
                new FeatureTerminal("b"),
                new FeatureTerminal("c"),
                new FeatureTerminal("d")
            };

            var listRight = new List <IGenoTypeNode>
            {
                new Sinus(),
                new Multiplication(),
                new Division(),
                new Minus(),
                new FeatureTerminal("a1"),
                new FeatureTerminal("b1"),
                new FeatureTerminal("c1"),
                new FeatureTerminal("d1")
            };

            var possibleFunctions = new List <IGenoTypeNode>
            {
                new SquareRoot(),
                new Multiplication(),
                new Plus(),
                new Minus()
            };

            var possibleTerminals = new List <IGenoTypeNode>
            {
                new FeatureTerminal("a"),
                new FeatureTerminal("b"),
                new FeatureTerminal("c"),
                new FeatureTerminal("d")
            };

            var eaGeneExpressionParameters =
                new EaGeneExpressionParameters(4, possibleFunctions, possibleTerminals)
            {
                CrossoverProbability = 1.0
            };

            IGenoType left = new GeneExpression.GenoType {
                GenoTypeNodes = listLeft
            };
            IGenoType right = new GeneExpression.GenoType {
                GenoTypeNodes = listRight
            };
            var randomGenerator        = new UniformRandomGenerator();
            var genotypeCrossoverator1 = new GenoTypeCrossoveratorBasic1(randomGenerator, eaGeneExpressionParameters);

            var phenoTypeTreeLeft1  = new GeneExpression.PhenoTypeTree(left.GenoTypeNodes);
            var phenoTypeTreeRight1 = new GeneExpression.PhenoTypeTree(right.GenoTypeNodes);

            genotypeCrossoverator1.PerformCrossover(ref left, ref right);

            var phenoTypeTreeLeft2  = new GeneExpression.PhenoTypeTree(left.GenoTypeNodes);
            var phenoTypeTreeRight2 = new GeneExpression.PhenoTypeTree(right.GenoTypeNodes);

            Assert.NotEqual(phenoTypeTreeLeft1, phenoTypeTreeLeft2);
            Assert.NotEqual(phenoTypeTreeRight1, phenoTypeTreeRight2);
        }