Exemple #1
0
        private void Immigration(int year)
        {
            int[] ageGroups = new int[10];
            for (int i = 0; i < 10; i++)
            {
                ageGroups[i] = 0;
            }
            Stopwatch SW = new Stopwatch();

            SW.Start();
            var noncit = GetNonCitizensCount();

            //Immigration
            if (Chances.GetNonResidentalPOpulation(year + 1, Method.statistical) - noncit > 0)
            {
                for (int i = 0; i < Chances.GetNonResidentalPOpulation(year + 1, Method.analytical) - noncit; i++)
                {
                    Person newPerson = Person.InitialNewPerson(this);
                    citizens.Add(newPerson);
                    if (imigrationLogs)
                    {
                        ageGroups[Convert.ToInt32(newPerson.age / 10)]++;
                    }
                }
            }
            else
            {
                int removed = 0;
                for (int i = citizens.Count - 1; i > 0; i--)
                {
                    if (citizens[i].state == State.nonresident)
                    {
                        citizens.RemoveAt(i);
                        removed++;
                        if (removed >= noncit - Chances.GetNonResidentalPOpulation(year + 1))
                        {
                            break;
                        }
                    }
                }
            }
            SW.Stop();
            Console.WriteLine("New Immigrants: " + SW.ElapsedMilliseconds);
            SW.Reset();
            if (imigrationLogs)
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("Age Group " + i * 10 + " - " + (i * 10 + 9) + " : " + ageGroups[i]);
                }
            }
        }
Exemple #2
0
        static public Population CreateInitialPopulation(int year)
        {
            //Residents
            Population result = new Population();

            for (int i = 0; i < MaximulAgeInInitialPopulation; i++)
            {
                int NumberOfPersons = Chances.GetNumberOfPeople(Gender.male, year, i);
                for (int j = 0; j < NumberOfPersons; j++)
                {
                    result.citizens.Add(Person.Initial(Gender.male, i));
                    result.CurrentId++;
                }

                NumberOfPersons = Chances.GetNumberOfPeople(Gender.female, year, i);
                for (int j = 0; j < NumberOfPersons; j++)
                {
                    result.citizens.Add(Person.Initial(Gender.female, i));
                    result.CurrentId++;
                }
            }
            result.ReWriteCHarasteristics(year);


            //Non-residents
            int NonResidents = Chances.GetNonResidentalPOpulation(year, method: Method.statistical);

            for (int j = 0; j < NonResidents; j++)
            {
                result.citizens.Add(Person.Initial(result));
            }
            Dictionary <Tuple <int, Gender>, int> set = new Dictionary <Tuple <int, Gender>, int>();

            List <Gender> genders = new List <Gender>()
            {
                Gender.male, Gender.female
            };


            //Determine widowed ;( persons
            for (int a = MinimumMarriageAgeInitialPopultion; a < MaximulAgeInInitialPopulation; a++)
            {
                int           age = a;
                GenderYearAge genderYearAgeM = new GenderYearAge(Gender.male, year, age);
                GenderYearAge genderYearAgeF = new GenderYearAge(Gender.female, year, age);
                List <Person> peopleM, peopleF;
                if (a < AgeOfOldPeopleInitialPopulation)
                {
                    peopleM = result.citizens.FindAll(x => x.gender == Gender.male && x.state == State.resident && x.age == a);
                    peopleF = result.citizens.FindAll(x => x.gender == Gender.female && x.state == State.resident && x.age == a);
                }
                else
                {
                    peopleM = result.citizens.FindAll(x => x.gender == Gender.male && x.state == State.resident && (x.age == a || x.age == a + AgeGroupSize));
                    peopleF = result.citizens.FindAll(x => x.gender == Gender.female && x.state == State.resident && (x.age == a || x.age == a + AgeGroupSize));
                }

                for (int i = 0; i < Chances.Widowed[genderYearAgeM.ToInt()]; i++)
                {
                    peopleM[i].RelationshipStatus = MarriageStatus.widowed;
                }
                for (int i = 0; i < Chances.Widowed[genderYearAgeF.ToInt()]; i++)
                {
                    peopleF[i].RelationshipStatus = MarriageStatus.widowed;
                }
            }

            //Determine divorced people
            for (int a = MinimumMarriageAgeInitialPopultion; a < MaximulAgeInInitialPopulation; a++)
            {
                int           age = a;
                GenderYearAge genderYearAgeM = new GenderYearAge(Gender.male, year, age);
                GenderYearAge genderYearAgeF = new GenderYearAge(Gender.female, year, age);
                List <Person> peopleM, peopleF;
                if (a < AgeOfOldPeopleInitialPopulation)
                {
                    peopleM = result.citizens.FindAll(x => x.gender == Gender.male && x.state == State.resident && x.age == a && x.RelationshipStatus == MarriageStatus.single);
                    peopleF = result.citizens.FindAll(x => x.gender == Gender.female && x.state == State.resident && x.age == a && x.RelationshipStatus == MarriageStatus.single);
                }
                else
                {
                    peopleM = result.citizens.FindAll(x => x.gender == Gender.male && x.state == State.resident && (x.age == a || x.age == a + 10));
                    peopleF = result.citizens.FindAll(x => x.gender == Gender.female && x.state == State.resident && (x.age == a || x.age == a + 10));
                }
                for (int i = 0; i < Chances.Divorced[genderYearAgeM.ToInt()]; i++)
                {
                    peopleM[i].RelationshipStatus = MarriageStatus.divorced;
                }
                for (int i = 0; i < Chances.Divorced[genderYearAgeF.ToInt()]; i++)
                {
                    peopleF[i].RelationshipStatus = MarriageStatus.divorced;
                }
            }

            //Determine Married people
            for (int a = MinimumMarriageAgeInitialPopultion; a < MaximulAgeInInitialPopulation; a++)
            {
                int           age            = a;
                GenderYearAge genderYearAgeM = new GenderYearAge(Gender.male, year, age);
                List <Person> peopleM        = result.citizens.FindAll(x => x.gender == Gender.male && x.age == a &&
                                                                       x.RelationshipStatus == MarriageStatus.single && x.state == State.resident);
                List <Person> Spouses       = new List <Person>();
                int           AgeDifference = 0;
                do
                {
                    Spouses = result.citizens.FindAll(x => (x.age <= a + AgeDifference &&
                                                            x.age >= a - AgeDifference) && x.RelationshipStatus == MarriageStatus.single && x.gender == Gender.female);
                    AgeDifference++;
                }while (Spouses.Count < peopleM.Count);
                for (int i = 0; i < Math.Min(Chances.Married[genderYearAgeM.ToInt()], peopleM.Count); i++)
                {
                    var spouse = Spouses[i];
                    peopleM[i].Marry(spouse);
                }
            }


            // Male Resident + Females Non-residents marriages
            ResidentNonResidentMarriages(result, year, true);

            // Female Resident + Males Non-residents marriages
            ResidentNonResidentMarriages(result, year, false);



            return(result);
        }