private void BuildFamilyStructure(Family family, int ageCategoryMale, int ageCategoryFemale)
 {
     var persons = family.Persons;
     // if the age category for the female is 
     var father = ageCategoryMale < 99 ? GetParent(persons, Sex.Male) : null;
     var mother = ageCategoryFemale < 99 ? GetParent(persons, Sex.Female) : null;
     family.FemaleHead = mother;
     family.MaleHead = father;
     if (father != null && mother != null)
     {
         father.MaritalStatus = MaritalStatus.Married;
         mother.MaritalStatus = MaritalStatus.Married;
         family.MarriageDate = GetMarriageLengthBasedOnAges(father.Age, mother.Age);
     }
     List<Person> siblings = new List<Person>(persons.Count - 2);
     // build siblingList
     foreach (var person in persons)
     {
         if (person != father && person != mother)
         {
             person.Father = father;
             person.Mother = mother;
             siblings.Add(person);
         }
     }
     // Assign siblings
     foreach (var person in persons)
     {
         if (person != father && person != mother)
         {
             foreach (var sibling in siblings)
             {
                 if (sibling != person)
                 {
                     person.Siblings.Add(sibling);
                 }
             }
         }
     }
     //assign children
     if (father != null)
     {
         father.Children.AddRange(siblings);
         father.Spouse = mother;
     }
     if (mother != null)
     {
         mother.Children.AddRange(siblings);
         mother.Spouse = father;
     }
 }
        private void LoadPersons()
        {
            WriteToLog("Starting to Load Persons");
            var personRepo = Repository.GetRepository(RepositoryPerson);
            var familyRepo = Repository.GetRepository(RepositoryFamily);
            int personsWithNegativeFamilyIndex = 0;
            List<Family> toAddAfterwards = new List<Family>();
            using (var reader = new CsvReader(InitialPersonFile, true))
            {
                /* (Columns)
                00  personid,	pumiid, familyid,	dwellingid,	prov,	cmapust,	hhclass,	htype,	unitsp,	hhincp,
                10  ompp,	grosrtp,	rentp,	hhstat,	efstat,	efsize,	cfstat,	cfsize,	mscfinc,	cfincp,
                20  agep,	sexp,	marstp,	mob5p,	pr5p,	lfact71,	lfact,	hrswk,  lstwkp,	wkswk,
                30  fptwk,	preschp,	occ81p,	occ71p,	ind80p,	ind70p,	cowp,	hlosp,	hgrad,	psuv,
                40  psot,	trnuc,	dgree,	dgmfs,  ethnicor,	vismin,	abethnic,	duethnic,	geethnic,	scethnic,
                50  huethnic,	poethnic,	ukethnic,	crethnic,	grethnic,  itethnic,	prethnic,	jeethinc,	waethnic,	saethnic,
                60  chethnic,	fiethnic,	eaethnic,	blethnic,	birtplac,	citizens, yrimmig,	immigage,	offlang,	homelang,
                70  mothertg,	totincp,	wagesp,	selfip,	invstp,	oasgip,	cqppbp,	famalp,	chdcrp,	uicbnp,
                80  govtip,	retirp,	otincp,	hmainp,	tenurp,	rcondp,	valuep, room,	id;
                */
                // there is no header at the moment so we don't need to burn a line
                int columns;
                if (FilesContainHeaders)
                {
                    reader.LoadLine();
                }
                while (reader.LoadLine(out columns))
                {
                    if (columns >= 89)
                    {
                        int personid, familyid, dwellingid, hhstat, cfstat, agep, sexp, marstp, lfact, occ81p, ind80p, totincp, hlosp;
                        int dgmfs, psuv, psot, trnuc, dgree;
                        reader.Get(out personid, 0);
                        reader.Get(out familyid, 2);
                        reader.Get(out dwellingid, 3);
                        reader.Get(out hhstat, 13);
                        reader.Get(out cfstat, 16);
                        reader.Get(out agep, 20);
                        reader.Get(out sexp, 21);
                        reader.Get(out marstp, 22);
                        reader.Get(out lfact, 26);
                        reader.Get(out occ81p, 32);
                        reader.Get(out ind80p, 34);
                        reader.Get(out totincp, 71);
                        reader.Get(out hlosp, 37);
                        reader.Get(out dgmfs, 43);
                        reader.Get(out psuv, 39);
                        reader.Get(out psot, 40);
                        reader.Get(out trnuc, 41);
                        reader.Get(out dgree, 42);

                        Family personsFamily;
                        // if they are living alone create a new family for them
                        if (familyid < 0)
                        {
                            // if the person has no family and no dwelling just continue
                            // this would mean that they live in a collective
                            if (dwellingid < 0)
                            {
                                continue;
                            }
                            personsWithNegativeFamilyIndex++;
                            personsFamily = new Family();
                            toAddAfterwards.Add(personsFamily);
                        }
                        else if (!familyRepo.TryGet(familyid, out personsFamily))
                        {
                            // otherwise create the new family
                            personsFamily = new Family();
                            familyRepo.AddNew(familyid, personsFamily);
                        }
                        Person p;
                        //TODO:  Finish filling out the personal information for this individual
                        personRepo.AddNew(personid, (p = new Person() { Age = agep, Family = personsFamily, Living = true, Sex = sexp == 2 ? Sex.Male : Sex.Female }));
                        // add the person to their family
                        personsFamily.Persons.Add(p);
                    }
                }
                // fill in the rest
                foreach (var family in toAddAfterwards)
                {
                    familyRepo.AddNew(family);
                }
                WriteToLog("Total number of families loaded: " + familyRepo.Count);
                WriteToLog("Total number of persons loaded: " + personRepo.Count);
            }
        }
Esempio n. 3
0
 private List<Family> BuildIndividualPool(int deltaYear, Rand rand)
 {
     var pool = new List<Family>();
     // Index of data loaded in ILUTE standardized variables
     //	0		Census Metropolitian Area (CMA)
     //	1		Household Type
     //	2		Houshold Size
     //	3		Census Family Status
     //	4		Number of Persons in the Census Family
     //	5		Age
     //	6		Sex
     //	7		Legal Marital Status for individual (HISTORICAL INDICATOR)
     //	8		Highest Grade of Elementary/Sec School
     //	9		Highest Level of Schooling (note: non-univ = college)
     //	10		Trades and Other Non-University Certification (sec. cert = high school graduation, non univ = college)
     //	11		Highest Degree, Certificate or Diploma
     //	12		Major Field of Study
     //	13		Total Years of Schooling
     //	14		Mobility Status - 1 Year Ago (Place of Residence)
     //	15		Labour Force Activity
     //	16		Occupation (1980 Classification Basis)
     //	17		Industry (1980 Standard Industrial Classification)
     //	18		Total Income
     //	19		Wages and Salaries
     //	20		Tenure
     //	21		Monthly Gross Rent
     using (var reader = new CsvReader(YearlyIndividualsData[deltaYear]))
     {
         int columns;
         while (reader.LoadLine(out columns))
         {
             if (columns >= 22)
             {
                 int age, sex, maritalStatus;
                 // read in the age
                 reader.Get(out age, 5);
                 // make sure that this record is old enough before loading it in
                 if (age < Parent.AgeOfMaturity)
                 {
                     continue;
                 }
                 // get sex
                 reader.Get(out sex, 6);
                 reader.Get(out maritalStatus, 7);
                 var person = CreatePerson(rand.Take(), age, sex, maritalStatus);
                 if (person.MaritalStatus == MaritalStatus.Married)
                 {
                     person.MaritalStatus = MaritalStatus.Single;
                 }
                 var family = new Family();
                 family.Persons.Add(person);
                 pool.Add(family);
             }
         }
     }
     return pool;
 }
Esempio n. 4
0
 internal Family CloneFamily(Family family)
 {
     var newFamily = new Family();
     var newPersons = newFamily.Persons;
     var oldPersons = family.Persons;
     //clone all of the individuals to make a map
     foreach (var person in oldPersons)
     {
         var newPerson = new Person()
         {
             Age = person.Age,
             Sex = person.Sex,
             Family = newFamily,
             LabourForceStatus = person.LabourForceStatus,
             Spouse = person.Spouse,
             MaritalStatus = person.MaritalStatus
         };
         newPersons.Add(newPerson);
     }
     for (int i = 0; i < oldPersons.Count; i++)
     {
         // copy the children
         if (oldPersons[i].Children.Count > 0)
         {
             foreach (var child in oldPersons[i].Children)
             {
                 newPersons[i].Children.Add(newPersons[oldPersons.IndexOf(child)]);
             }
         }
         if (oldPersons[i].Siblings.Count > 0)
         {
             foreach (var child in oldPersons[i].Siblings)
             {
                 newPersons[i].Siblings.Add(newPersons[oldPersons.IndexOf(child)]);
             }
         }
     }
     return newFamily;
 }
Esempio n. 5
0
            private List<Family> BuildFamilyPool(int deltaYear, Rand rand)
            {
                var pool = new List<Family>();
                // Index of data loaded in ILUTE standardized variables
                //	0	icma		Census Metropolitian Area (CMA)
                //	1	icfstruc	Census Family Structure
                //	2	icfsize		Number of Persons in the Census Family
                //	3	inuchild	Number of Never-married S/D in CF at Home
                //	4	ichilda		No. of NevMar S/D in CF at Home < 6 Years of Age
                //	5	ichildb		No. of NevMar S/D in CF at Home 6-14 Years of Age
                //	6	ichildc		No. of NevMar S/D in CF at Home 15-17 Years of A
                //	7	ichildd		No. of NevMar S/D in CF at Home 18-24 Years of A
                //	8	ichilde		No. of NevMar S/D in CF at Home 25 Years or Over
                //	9	itotalc		Total Income of CF or Non-family Person
                //	10	inucfinc	No. of Income Recipients in CF or Non-family Per
                //	11	iwagesc		Wages and Salaries of CF or Non-family Person
                //	12	itotalm		Total Income of H/MCLP/MLP in CF
                //	13	iwagem		Wages and Salaries of H/MCLP/MLP in CF
                //	14	iagem		Age of H/MCLP/MLP/Male NF Person (85=85+)
                //	15	imarsthm	Hist. Comparison Legal Marital Status of Male - Husbands, Common Law Parent/Male Lone Parent or Male NonFam Person
                //	16	ihgradm		Highest Grade Elem/Sec. of H/MCLP/MLP/MNF Person ( ALL MALES)
                //	17	ihlosm		Highest Level of Sch. of H/MCLP/MLP or Male NFP (ALL MALES)
                //	18	itruncm		Trades/Other Non-univ. Cert. of H/MCLP/MLP/MNFP (sec. Cert = high school)
                //	19	idgmfsm		Major Field of Study of H/MCLP/MLP or Male NFP
                //	20	itotschm	Total Years of Schooling of H/MCLP/MLP or Male N
                //	21	imob1m		Mobility Status - 1 Year Ago of H/MCLP/MLP/MNFP
                //	22	ilfactm		LF Activity of H/MCLP/MLP or Male NF Person
                //	23	iocc80m		Occupation (1980 Class.) of H/MCLP/MLP/MNFP
                //	24	iind80m		Industry (1980 SIC) of H/MCLP/MLP/MNFP
                //	25	iagef		Age of W/FCLP/FLP/Female NF Person (85=85+)
                //	26	imarsthf	Hist. Comparison Legal Marital Status of Female - Wives, Common Law Parent/Female Lone Parent or Female NonFam Person
                //	27	itotalf		Total Income of W/FCLP/FLP in CF (ALL FEMALES)
                //	28	iwagef		Wages and Salaries of H/MCLP/MLP in CF
                //	29	ihgradf		Highest Grade Elem/Sec. of W/FCLP/FLP/FNF Person ( ALL FEMALES)
                //	30	ihlosf		Highest Level of Sch. of W/FCLP/FLP or Female NFP (ALL FEMALES)
                //	31	itruncm		Trades/Other Non-univ. Cert. of W/FCLP/FLP/FNFP (sec. Cert = high school)
                //	32	idgmfsf		Major Field of Study of W/FCLP/FLP or Female NFP
                //	33	itotschf    Total Years of Schooling of W/FCLP/FLP or Female NFP
                //	34	imob1f		Mobility Status - 1 Year Ago of W/FCLP/FLP/FNFP
                //	35	ilfactf		LF Activity of W/FCLP/FLP or Female NF Person
                //	36	iocc80f		Occupation (1980 Class.) of W/FCLP/FLP/FNFP
                //	37	iind80f		Industry (1980 SIC) of W/FCLP/FLP/FNFP
                //	38	itenurc		Tenure
                //	39	igrosrtc	Monthly Gross Rent

                using (var reader = new CsvReader(YearlyFamilyData[deltaYear], true))
                {
                    int columns;
                    List<Person> children = new List<Person>();
                    while (reader.LoadLine(out columns))
                    {
                        if (columns >= 39)
                        {
                            var createMale = false;
                            var createFemale = false;
                            int familyStructure, ageM, ageF, childrenA, childrenB, childrenC, childrenD, childrenE;
                            reader.Get(out familyStructure, 1);
                            reader.Get(out ageM, 14);
                            reader.Get(out ageF, 25);
                            if (familyStructure > 0 && familyStructure < 5)
                            {
                                createMale = createFemale = true;
                            }
                            else if (familyStructure == 5 && ageM != 99)
                            {
                                createMale = true;
                            }
                            else if (familyStructure == 6 && ageF != 99)
                            {
                                createFemale = true;
                            }
                            else
                            {
                                // this household record is invalid, just continue
                                continue;
                            }
                            // get the number of children
                            reader.Get(out childrenA, 4);
                            reader.Get(out childrenB, 5);
                            reader.Get(out childrenC, 6);
                            reader.Get(out childrenD, 7);
                            reader.Get(out childrenE, 8);
                            var family = new Family();
                            Person male = null, female = null;
                            if (createMale)
                            {
                                male = CreatePerson(0, AgeFromAdultAgeCategory(rand.Take(), ageM), 2, (createMale && createFemale ? 2 : 4));
                                family.Persons.Add(male);
                                male.Family = family;
                                family.MaleHead = male;
                            }
                            if (createFemale)
                            {
                                female = CreatePerson(0, AgeFromAdultAgeCategory(rand.Take(), ageF), 1, (createMale && createFemale ? 2 : 4));
                                family.Persons.Add(female);
                                female.Family = family;
                                family.FemaleHead = female;
                            }
                            if (male != null && female != null)
                            {
                                male.Spouse = female;
                                female.Spouse = male;
                            }
                            pool.Add(family);
                            // Create children for each age range rand.NextFloat = [0,1)
                            if (childrenA > 0 || childrenB > 0 || childrenC > 0 || childrenD > 0 || childrenE > 0)
                            {
                                for (int i = 0; i < childrenA; i++)
                                {
                                    children.Add(
                                        CreatePerson(0, (int)(0.0f + rand.Take() * 6.0f), rand.Take() < 0.5f ? 2 : 1, 4));
                                }
                                for (int i = 0; i < childrenB; i++)
                                {
                                    children.Add(
                                        CreatePerson(0, (int)(6.0f + rand.Take() * 9.0f), rand.Take() < 0.5f ? 2 : 1, 4));
                                }
                                for (int i = 0; i < childrenC; i++)
                                {
                                    children.Add(
                                        CreatePerson(0, (int)(15.0f + rand.Take() * 3.0f), rand.Take() < 0.5f ? 2 : 1, 4));
                                }
                                for (int i = 0; i < childrenD; i++)
                                {
                                    children.Add(
                                        CreatePerson(0, (int)(18.0f + rand.Take() * 7.0f), rand.Take() < 0.5f ? 2 : 1, 4));

                                }
                                for (int i = 0; i < childrenE; i++)
                                {
                                    children.Add(CreatePerson(0, 25, rand.Take() < 0.5f ? 2 : 1, 4));
                                }
                                male?.Children.AddRange(children);
                                female?.Children.AddRange(children);
                                foreach (var child in children)
                                {
                                    child.Father = male;
                                    child.Mother = female;
                                    child.Family = family;
                                    foreach (var otherChild in children)
                                    {
                                        if (child != otherChild)
                                        {
                                            child.Siblings.Add(otherChild);
                                        }
                                    }
                                    family.Persons.Add(child);
                                }
                                // now that everything is copied over we can release the children
                                children.Clear();
                            }
                        }
                    }
                }
                return pool;
            }
Esempio n. 6
0
 private bool CheckIfShouldDivorse(float pick, Family family, int currentYear)
 {
     var female = family.FemaleHead;
     var male = family.MaleHead;
     var yearsMarried = Math.Min(currentYear - family.MarriageDate.Year, DivorceData.Length - 1);
     // divorce data is already pre-processed to skip the division
     var baseSurvival = yearsMarried <= 0 ? 1.0f : DivorceData[yearsMarried];
     var coVariateVector = Math.Abs(male.Age - female.Age) < 5.0f ? WITHIN5YEARS : 0f;
     coVariateVector += GetHusbandCovariate(male, yearsMarried, currentYear);
     coVariateVector += GetWifeCovariate(female, yearsMarried, currentYear);
     if (currentYear - yearsMarried < 1950)
     {
         coVariateVector += HMARRIEDBEFORE1950S + WMARRIEDBEFORE1950S;
     }
     else if (currentYear - yearsMarried > 1980)
     {
         //TODO: yes this is 1980 even though the variable is called 1960PLUS
         coVariateVector += MARRIED1960PLUS;
     }
     var divorceProbability = Math.Max((1 - (float)Math.Pow(baseSurvival, Math.Exp(coVariateVector))) * DivorceParameter, 0.0f);
     DivorceProbability += divorceProbability;
     NumberOfTimes++;
     return (pick < divorceProbability);
 }
Esempio n. 7
0
 public void RemoveFamily(Family family)
 {
     Families.Remove(family);
     UpdateHouseholdType();
 }
Esempio n. 8
0
 private static void AddMotherAndBabyToNewFamily(Repository<Family> families, Person mother, Person baby, Family originalFamily)
 {
     // Baby family is setup later to reflect the mother's family
     Family newFamily = new Family();
     newFamily.Persons.Add(mother);
     newFamily.Persons.Add(baby);
     var household = originalFamily.Household;
     household?.Families.Add(newFamily);
     newFamily.Household = household;
     originalFamily.Persons.Remove(mother);
     mother.Family = newFamily;
     baby.Family = newFamily;
     newFamily.FemaleHead = mother;
     families.AddNew(newFamily);
 }
Esempio n. 9
0
 public void RemoveFamily(Family family)
 {
     Families.Remove(family);
     UpdateHouseholdType();
 }