Esempio n. 1
0
    public void EvaluationTest()
    {
        Vector <float> externalEvaluations = Vector <float> .Build.DenseOfArray(new float[2] {
            1.0f, 0.0f
        });

        geneSeed.Evaluation(externalEvaluations, "max");
        Assert.AreEqual(0, geneSeed.GetBestIndividualIndex());
        geneSeed.Evaluation(externalEvaluations, "min");
    }
Esempio n. 2
0
    public void SelectionTest()
    {
        int size = 3;

        float[] arr = new float[size];
        for (int i = 0; i < size; i++)
        {
            arr[i] = 1.0f;
        }
        arr[size - 1] = 2.0f;
        Vector <float> externalEvaluations = Vector <float> .Build.DenseOfArray(arr);

        Genetic gene = new Genetic(seed, null, size, 3, 0.1f, 0.34f, 0.34f);

        gene.Evaluation(externalEvaluations, "max");
        Debug.Log(gene.GetPopulation());
        gene.Selection();
        Debug.Log(gene.GetPopulation());
    }
Esempio n. 3
0
    public void SaveTest()
    {
        Vector <float> externalEvaluations = Vector <float> .Build.DenseOfArray(new float[2] {
            0.0f, 1.0f
        });

        geneRndGenerator.Evaluation(externalEvaluations, "max");
        geneRndGenerator.SaveGeneration();
        float[,] floatArr = new float[geneRndGenerator.individualSize, geneRndGenerator.populationSize];

        float[] floatArrBest = new float[geneRndGenerator.individualSize];

        geneRndGenerator.LoadGeneration(1, floatArr);
        geneRndGenerator.LoadBest(1, floatArrBest);

        Matrix <float> result = Matrix <float> .Build.DenseOfArray(floatArr);

        Vector <float> resultBest = Vector <float> .Build.DenseOfArray(floatArrBest);

        Assert.AreEqual(geneRndGenerator.GetPopulation(), result);
        Assert.AreEqual(geneRndGenerator.GetBestIndividual(), resultBest);
        Debug.Log(geneRndGenerator.GetPopulation());
        Debug.Log(result);
    }