Example #1
0
    public void EvaluateFitness()
    {
        //DebugLogPopulation();

        //testPop = new List<Chromossome>();

        /**
         * for (int i = 0; i < population.Count; i++)
         * {
         *  testPop.Add(population[i]);
         * }
         * /**/

        for (int i = 0; i < population.Count; i++)
        {
            float       __tempFitness     = 0;
            Chromossome __tempChromossome = population[i];
            int[][]     __simulatedMap    = CellularAutomata.SimulateMap(__tempChromossome.GetMap(), 5);
            __simulatedMap = CellularAutomata.FillExclaves(__simulatedMap); //by doing this we end up having only the largest cave area

            //first we calculate the fitness from Fill Ratio
            float __fill = CellularAutomata.GetFilledPercentage(__simulatedMap);
            __tempFitness += (1 - (Mathf.Abs(fillTarget - __fill))) * fitnessBaseValue;

            //now we calculate the fitness based on points
            for (int j = 0; j < fitnessPoints.Length; j++)
            {
                if (__simulatedMap[(int)fitnessPoints[j].y][(int)fitnessPoints[j].x] == 0)
                {
                    __tempFitness += fitnessBaseValue * fitnessPointsWeight;
                }
            }

            __tempChromossome.fitness = __tempFitness;

            population[i] = __tempChromossome;
        }

        /**
         * for (int i = 0; i < population.Count; i++)
         * {
         *  Debug.Log(testPop[i] == population[i]);
         * }
         * /**/

        //DebugLogPopulation();
    }