public void TestGPTemplate()
        {
            GPSolutionDefinition holder = new GPSolutionDefinition(config);

            /*
             * vou simular um template com 4 formulas(nodes) e 2 variaveis numéricas
             * f1(NODE,NUMBER)
             * F2(NODE,NODE)
             * F3
             * F4(NUMBER)
             */
            SemanticaList listaFormulas = CriaListaDefault(holder);

            //Lista Numerica
            SemanticaList listaNumerica = CriaListaNumerica(holder);

            //Templates: possuem propriedades evolutivas, cada uma apontando para uma lista de semantica
            GPTemplate template = CreateTestTemplate(config, listaFormulas, listaNumerica);

            GPSolution solution = template.CreateRandomSolution();

            Assert.IsNotNull(solution);
            GPAbstractNode p1 = solution.GetValue("prop1");

            Assert.IsNotNull(p1);
            GPAbstractNode p2 = solution.GetValue("prop2");

            Assert.IsNotNull(p2);
            GPAbstractNode p3 = solution.GetValue("prop3");

            Assert.IsNotNull(p3);
            GPAbstractNode p4 = solution.GetValue("prop4");

            Assert.IsNotNull(p4);

            GPAbstractNode n1 = solution.GetValue("number1");

            Assert.IsNotNull(n1);
            GPAbstractNode n2 = solution.GetValue("number2");

            Assert.IsNotNull(n2);


            GPAbstractNode clonep1 = p1.Clone();

            Assert.IsNotNull(clonep1);
            Assert.IsFalse(clonep1 == p1);
            Assert.IsTrue(clonep1.ToString() == p1.ToString());

            GPSolution cloneSolution = solution.Clone();
            GPSolution solution2     = template.CreateRandomSolution();

            GPSolution childSolution2 = null;
            GPSolution childSolution  = solution.CreateChildWith(solution2, out childSolution2);

            Assert.IsNotNull(childSolution);
            Assert.IsNotNull(childSolution2);
        }
Пример #2
0
        public string GetValueAsString(string var)
        {
            GPAbstractNode node = GetValue(var);

            if (node == null)
            {
                return("");
            }
            return(node.ToString());
        }
        public void TestaGPCriacaoPelaLista()
        {
            GPPool pool = new GPPool(config);

            string listDefault = "default";
            GPSolutionDefinition definition    = CreateSampleDefinition(listDefault);
            SemanticaList        listaFormulas = CriaListaDefault(definition);
            SemanticaList        listSemantic  = definition.GetListByName(listDefault);

            listSemantic.maxLevels = 3;
            listSemantic.minLevels = 2;
            GPAbstractNode nodeRandom = listSemantic.CreateRandomNode(config, false);

            Assert.IsNotNull(nodeRandom);
            string toString = nodeRandom.ToString();

            Assert.IsTrue(nodeRandom.SizeLevel() >= listSemantic.minLevels && nodeRandom.SizeLevel() <= listSemantic.maxLevels, "SizeLevel:" + nodeRandom.SizeLevel());
        }