//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); }
//Functions for getting the ages public static int[] InitialAgeDistribution(SimParams par) { int[] AgeGroup; if (par.AgeDeath) { float[] AgeRates = GetAgeRates(par); AgeGroup = GetAgeGroup(par, AgeRates); } else { List <int> AgeRange = Enumerable.Range(0, par.MaxAge + 1).ToList(); AgeGroup = par.RandomSampleEqualReplace(AgeRange, par.NumBirds); } return(AgeGroup); }
public static int[] GetGlobalBirds(SimParams par, Population pop, int learner, List <int> potentialBirds, int numBirds = 1) { int[] Birds; List <int> PotentialBirds = potentialBirds.ToList(); PotentialBirds.Remove(learner); if (numBirds == 1) { Birds = par.RandomSampleEqualReplace(PotentialBirds, numBirds); } else { Birds = par.RandomSampleEqualNoReplace(PotentialBirds, numBirds); } return(Birds); }
//Getting local and global birds public static int[] GetLocalBirds(SimParams par, Population pop, int target, HashSet <int> unavailable, int numBirds = 1, float[] probs = null) { //pick Tutors locally int[] Birds = new int[numBirds]; int[] UsableInd; UsableInd = LocalSearch(par, pop, target, unavailable, numBirds).ToArray(); //return the right number of birds if (UsableInd.Length == numBirds)//only numTutors choice(s) { return(UsableInd); } else //Multiple choices { if (probs != null)//unequal probabilities { int[] Index; float[] Prob = new float[UsableInd.Length]; for (int j = 0; j < UsableInd.Length; j++) { Prob[j] = probs[UsableInd[j]]; } Index = par.RandomSampleUnequal(Prob, numBirds, false); for (int j = 0; j < numBirds; j++) { Birds[j] = UsableInd[Index[j]]; } return(Birds); } if (numBirds == 1)//can use the faster with replace { Birds[0] = UsableInd[par.RandomSampleEqualReplace(UsableInd.ToList(), 1)[0]]; return(Birds); }//need the slower without replace Birds = par.RandomSampleEqualNoReplace(UsableInd.ToList(), numBirds); return(Birds); } }