コード例 #1
0
        internal double Decay(double drate, double rem)
        {
            //defines the sorting order for the species members
            Comparison <Int32> comp = delegate(int x, int y)
            {
                Organism <T> m1 = pop.GetMember(x);
                Organism <T> m2 = pop.GetMember(y);
                return(m1.CompareTo(m2));
            };

            //sorts the members by fitness
            members.Sort(comp);

            ////determins the number of creatures left alive
            //int nalive = (int)Math.Floor(drate * members.Count);
            //nalive = members.Count - (nalive + 1);
            //if (nalive < 1) nalive = 1;

            //determins the number of creatures that should die
            double dead  = drate * members.Count;
            int    ndead = (int)dead.Floor();

            rem = rem + dead.Frac();

            //updates the count if the remainder is more than one
            if (rem >= 1.0)
            {
                ndead = ndead + 1;
                rem   = rem - 1.0;
            }

            //uses the dead count to determin how many are left alive
            int nalive = members.Count - ndead;

            //removes the members whose fitness is too low
            for (int i = members.Count - 1; i >= nalive; i--)
            {
                int index = members[i];
                pop.MarkForDeath(index);
                members.RemoveAt(i);
            }

            return(rem);
        }