Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }