Exemple #1
0
        internal Organism <T> GetRandMember(VRandom rng)
        {
            //int index = rng.RandInt(members.Count);
            //int id = members[index];
            //return pop.GetMember(id);

            //creates a vector to store the probablity distribution
            Vector pd = new Vector(members.Count);

            //uses the fitness of each member as the weight
            for (int i = 0; i < pd.Length; i++)
            {
                var mem = pop.GetMember(members[i]);
                pd[i] = mem.Fitness;
            }

            //returns a random member based on fitness
            int index = rng.SampleDesc(pd);
            int id    = members[index];

            return(pop.GetMember(id));
        }