Ejemplo n.º 1
0
        private static int[] ChooseFemaleFathers(SimParams par, Population pop,
                                                 int[] vacant, List <int> notVacant, int[] maleFathers)
        {
            /*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[] Probability = Enumerable.Repeat(0f, par.NumBirds).ToArray();
            float[] Probs       = ReproductiveProbability(par, pop, PotentialFathers);
            for (int i = 0; i < PotentialFathers.Count; i++)
            {
                Probability[PotentialFathers[i]] = Probs[i];
            }

            //pick fathers
            int[]         Fathers = new int[vacant.Length];
            HashSet <int> UnavailableNoMateFather;

            if (par.LocalBreeding)
            {
                for (int i = 0; i < Fathers.Length; i++)
                {
                    UnavailableNoMateFather = Unavailable;
                    UnavailableNoMateFather.Remove(maleFathers[i]);
                    Fathers[i] = Locations.GetLocalBirds(par, pop, vacant[i],
                                                         UnavailableNoMateFather, probs: Probability)[0];
                }
            }
            else
            {
                float[] PotenProbs = new float[PotentialFathers.Count];
                for (int i = 0; i < PotenProbs.Length; i++)
                {
                    PotenProbs[i] = Probability[PotentialFathers[i]];
                }
                float[] PotenProbsTemp;
                //List<int> PotentialFathersNoMateFather;
                for (int i = 0; i < vacant.Length; i++)
                {
                    //PotentialFathersNoMateFather = PotentialFathers.ToList();
                    //PotentialFathersNoMateFather.Remove(MaleFathers[i]);
                    PotenProbsTemp = PotenProbs.ToArray();
                    PotenProbsTemp[maleFathers[i]] = 0;

                    /*for(int j=0;j<PotenProbs.Length;j++){
                     *  PotenProbs[j] = Probability[PotentialFathers[j]];
                     * }*/
                    Fathers[i] = PotentialFathers[par.RandomSampleUnequal(PotenProbsTemp, 1, true)[0]];
                }
            }
            return(Fathers);
        }