Exemple #1
0
        //Birth
        private static int[] ChooseMaleFathers(SimParams par, Population pop,
                                               int[] vacant, List <int> notVacant)
        {
            /*Picks fathers to sire chicks into vacancies,
             * Uses only living males.
             * It is likely for high quality males to sire multiple
             * offspring in one sim step for both local and global scopes*/

            //Remove songless birds from notVacant, and mark all not in that list as unavailable
            HashSet <int> PotentialFathersTemp = new HashSet <int>(notVacant.Where(x => pop.SyllableRepertoire[x] > 0));
            HashSet <int> Unavailable          = new HashSet <int>(Enumerable.Range(0, par.NumBirds));

            Unavailable.ExceptWith(PotentialFathersTemp);
            //Get the probabilities
            List <int> PotentialFathers = PotentialFathersTemp.ToList();

            float[] Probs = ReproductiveProbability(par, pop, PotentialFathers);


            //pick fathers
            int[] Fathers = new int[vacant.Length];
            if (par.LocalBreeding)
            {
                float[] Probability = Enumerable.Repeat(0f, par.NumBirds).ToArray();
                for (int i = 0; i < PotentialFathers.Count; i++)
                {
                    Probability[PotentialFathers[i]] = Probs[i];
                }

                for (int i = 0; i < Fathers.Length; i++)
                {
                    Fathers[i] = Locations.GetLocalBirds(par, pop, vacant[i],
                                                         Unavailable, probs: Probability)[0];
                }
            }
            else
            {
                //float[] PotenProbs = new float[PotentialFathers.Count];
                int[] FatherIndex;
                //for(int i=0;i<PotenProbs.Length;i++){
                //    PotenProbs[i] = Probability[PotentialFathers[i]];
                //}
                FatherIndex = par.RandomSampleUnequal(Probs, vacant.Length, true);
                for (int i = 0; i < Fathers.Length; i++)
                {
                    Fathers[i] = PotentialFathers[FatherIndex[i]];
                }
            }


            int[] lol = new int[Fathers.Length];
            for (int i = 0; i < Fathers.Length; i++)
            {
                lol[i] = pop.SyllableRepertoire[Fathers[i]];
            }
            return(Fathers);
        }
Exemple #2
0
        //Getting tutors, the original runs faster, but cannot get more than one tutor
        private static int[] ChooseTutors(SimParams par, Population pop,
                                          List <int> learners, List <int> notVacant)
        {
            //Picks tutos that are alive, not chicks, and not songless,
            //Males can tutor multiple learners

            /*remove chicks and songless birds + any Misc, mark all excluded
             * birds as unavailable*/
            HashSet <int> PotentialTutorsTemp = new HashSet <int>(notVacant.Where(x => pop.Age[x] > 0));

            PotentialTutorsTemp.ExceptWith(PotentialTutorsTemp.Where(x => pop.SyllableRepertoire[x] == 0).ToArray());

            //pick Tutors
            int[] Tutors = new int[learners.Count];
            if (par.LocalTutor)
            {
                //Set up unavailable for local testing
                HashSet <int> Unavailable = new HashSet <int>(Enumerable.Range(0, par.NumBirds));
                Unavailable.ExceptWith(PotentialTutorsTemp);
                for (int i = 0; i < learners.Count; i++)
                {
                    if (par.SocialCues)
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable, 1, pop.Bred)[0];
                    }
                    else
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable)[0];
                    }
                }
            }
            else  //drawn individually so no learner is his own tutor
            {
                List <int> PotentialTutors;
                for (int i = 0; i < learners.Count; i++)
                {
                    PotentialTutors = PotentialTutorsTemp.ToList();
                    PotentialTutors.Remove(learners[i]);

                    if (par.SocialCues)
                    {
                        float[] TutorProbs = new float[PotentialTutors.Count];
                        for (int j = 0; j < TutorProbs.Length; j++)
                        {
                            TutorProbs[j] = pop.Bred[PotentialTutors[j]];
                        }
                        Tutors[i] = PotentialTutors[par.RandomSampleUnequal(TutorProbs, 1)[0]];
                    }
                    else
                    {
                        Tutors[i] = PotentialTutors[par.RandomSampleEqualReplace(PotentialTutors, 1)[0]];
                    }
                }
            }
            return(Tutors);
        }
Exemple #3
0
        private static List <int>[] ChooseMultipleTutors(SimParams par, Population pop,
                                                         List <int> learners, List <int> notVacant, int numTutors)
        {
            /*remove chicks and songless birds + any Misc, mark all excluded
             * birds as unavailable*/
            HashSet <int> PotentialTutorsTemp = new HashSet <int>(notVacant.Where(x => pop.Age[x] > 0));

            PotentialTutorsTemp.ExceptWith(PotentialTutorsTemp.Where(x => pop.SyllableRepertoire[x] == 0).ToArray());
            List <int>[] Tutors = new List <int> [learners.Count];

            if (par.LocalTutor)
            {
                HashSet <int> Unavailable = new HashSet <int>(Enumerable.Range(0, par.NumBirds));
                Unavailable.ExceptWith(PotentialTutorsTemp);
                for (int i = 0; i < learners.Count; i++)
                {
                    if (par.SocialCues)
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable, numTutors, pop.Bred).ToList();
                    }
                    else
                    {
                        Tutors[i] = Locations.GetLocalBirds(par, pop, learners[i], Unavailable, numTutors).ToList();
                    }
                }
            }
            else
            {
                List <int> PotentialTutors;
                for (int i = 0; i < learners.Count; i++)
                {
                    PotentialTutors = PotentialTutorsTemp.ToList();
                    PotentialTutors.Remove(learners[i]);
                    if (par.SocialCues)
                    {
                        float[] TutorProbs = new float[PotentialTutors.Count];
                        for (int j = 0; j < TutorProbs.Length; j++)
                        {
                            TutorProbs[j] = pop.Bred[PotentialTutors[j]];
                        }
                        int[] ChosenIndex = par.RandomSampleUnequal(TutorProbs, numTutors);
                        for (int j = 0; j < numTutors; j++)
                        {
                            ChosenIndex[j] = PotentialTutors[ChosenIndex[j]];
                        }
                        Tutors[i] = ChosenIndex.ToList();
                    }
                    else
                    {
                        Tutors[i] = par.RandomSampleEqualNoReplace(PotentialTutors, numTutors).ToList();
                    }
                }
            }
            return(Tutors);
        }