Ejemplo n.º 1
0
        public Population(Population pop)
        {
            population = new int[pop.population.Length][];
            fitness = new Tuple<int,int>[pop.fitness.Length];
            for (int i = 0; i < pop.population.Length; i++)
            {
                var tuple = (Tuple<int,int>)pop.fitness[i];
                fitness[i] = new Tuple<int, int>(tuple.Item1, tuple.Item2);
                population[i] = (int[]) pop.population[i].Clone();

            }
        }
Ejemplo n.º 2
0
        private Population previous; // previous population

        #endregion Fields

        #region Constructors

        public BRKGA(int n, int p, int _pe, int _pm, bool[] capturedBadges)
        {
            // Error check:
            if (n == 0) { throw new Exception("Chromosome size equals zero."); }
            if (pop == 0) { throw new Exception("Population size equals zero."); }
            if (popElite == 0) { throw new Exception("Elite-set size equals zero."); }
            if (popElite > pop) { throw new Exception("Elite-set size greater than population size (pe > p)."); }
            if (popMutant > pop) { throw new Exception("Mutant-set size (pm) greater than population size (p)."); }
            if (popElite + popMutant > pop) { throw new Exception("elite + mutant sets greater than population size (p)."); }

            // Initialize and decode each chromosome of the current population, then copy to previous:
            // Allocate:
            current = new Population(n, p);

            // Initialize:
            Initialize(capturedBadges);

            // Then just copy to previous:
            previous = new Population(current);
        }