private void LoadDwellings()
 {
     WriteToLog("Starting to Load Dwellings/Households");
     var householdRepo = Repository.GetRepository(RepositoryHousehold);
     var dwellingRepo = Repository.GetRepository(RepositoryDwellings);
     var initialDate = new Date(InitialYear, 0);
     var zoneSystem = Repository.GetRepository(ZoneSystem);
     using (var reader = new CsvReader(InitialHouseholdFile, true))
     {
         int columns;
         if (FilesContainHeaders)
         {
             reader.LoadLine();
         }
         while (reader.LoadLine(out columns))
         {
             /*
             int dwellingid, pumhid, ctcode, tts96, prov, urbru, cmapust, weight, hhinda, hhindb, hhpera, hhperb1, hhperb2, hhperd, hhpere,
                 hhperf, hhperg, hhperh, hhsize, hhcomp, hhnonfam, hhnuef, hhnuldg, hhnuempi, hhnutoti, hhmsinc, hhempinc, hhnetinv,
                 hhgovinc, hhotinc, hhtotinc, dtypeh, builth, tenurh, morg, rcondh, room, heath, fuelhh, valueh, grosrth, renth, omph,
                 mppit,hmage, hmsex, hmmarst, hmefamst, hmbirtpl, hmethnic, hmimmig, hhmotg, hmofflg, hmmob5, hmhlos, hmocc81, hmlfact,
                 hmcow, hmwkswk, hmfptwk, hmmsinc, hmempinc, hmnetinv, hmgovinc, hmotinc, hmtotinc, spage, spsex, spbirtpl, spethnic,
                 spmotg, spofflg, spimmig, spmob5, sphlos, spocc81, splfact, spcow, spwkswk, spfptwk, spmsinc, spempinc, spnetinv, spgovinc,
                 spotinc, sptotinc, efsize, efadult, efpersgh, efpersa, efpersb, efpersc, efpersd, efcomp, efnuempi, efnutoti, efloinc,
                 efmsinc, efempinc, efnetinv, efgovinc, efotinc, eftotinc, id;
             */
             if (columns > 39)
             {
                 int dwellingid, ctcode, hhcomp, dtype, tenur, rooms, value;
                 reader.Get(out dwellingid, 0);
                 reader.Get(out ctcode, 2);
                 reader.Get(out hhcomp, 19);
                 reader.Get(out dtype, 31);
                 reader.Get(out tenur, 33);
                 reader.Get(out rooms, 36);
                 reader.Get(out value, 39);
                 Household h = new Household();
                 Dwelling d = new Dwelling();
                 householdRepo.AddNew(dwellingid, h);
                 dwellingRepo.AddNew(dwellingid, d);
                 h.Dwelling = d;
                 h.HouseholdType = ConvertHouseholdType(hhcomp);
                 d.Exists = true;
                 d.Zone = zoneSystem.GetFlatIndex(ctcode);
                 d.Rooms = rooms;
                 d.Value = new Money(value, initialDate);
                 h.Tenure = ConvertTenureFromCensus(tenur);
             }
         }
     }
 }
Exemplo n.º 2
0
            internal void Execute(int deltaYear, Repository<Household> householdRepository, Repository<Family> familyRepository, Repository<Person> personRepo)
            {
                // get the pool of individuals to use
                List<Family> familyPool = null, individualPool = null;
                var familySeed = (uint)(Parent.RandomGenerator.Take() * uint.MaxValue);
                var individualSeed = (uint)(Parent.RandomGenerator.Take() * uint.MaxValue);
                Parallel.Invoke(
                    () =>
                    {
                        Rand rand = new Rand(familySeed);
                        familyPool = BuildFamilyPool(deltaYear, rand);
                    }, () =>
                    {
                        Rand rand = new Rand(individualSeed);
                        individualPool = BuildIndividualPool(deltaYear, rand);
                    });
                var targetPersons = (int)(Parent.NumberOfImmigrantsBySimulationYear[deltaYear + (RegionNumber - 1) * 20] * Scale);
                Repository.GetRepository(Parent.LogSource).WriteToLog($"Number of persons to add in {Name} in {deltaYear} target additions are {targetPersons}.");
                Parent.RandomGenerator.ExecuteWithProvider((rand) =>
                {
                    while (targetPersons > 0)
                    {
                        float chance = rand.Take();
                        float acc = 0.0f;
                        int householdType = 0;
                        for (; acc < chance; householdType++)
                        {
                            acc += Parent.HouseholdTypeData[deltaYear * 5 + CMA * 100 + householdType];
                        }
                        Household household = new Household();
                        switch (householdType)
                        {
                            default:
                            case 1:
                                {
                                    household.HouseholdType = HouseholdComposition.SingleIndividuals;
                                    household.Families.Add(GetFamilyFromPool(individualPool, rand.Take()));
                                }
                                break;
                            case 2:
                                {
                                    household.HouseholdType = HouseholdComposition.MultiIndividuals;
                                    // create at least 2 individuals
                                    household.Families.Add(GetFamilyFromPool(individualPool, rand.Take()));
                                    do
                                    {
                                        household.Families.Add(GetFamilyFromPool(individualPool, rand.Take()));
                                    } while (rand.Take() < ProbabilityOfAdditionalMultiIndividuals);
                                }
                                break;
                            case 3:
                                {
                                    household.HouseholdType = HouseholdComposition.SingleFamily;
                                    household.Families.Add(GetFamilyFromPool(familyPool, rand.Take()));
                                }
                                break;
                            case 4:
                                {
                                    household.HouseholdType = HouseholdComposition.SingleFamilyIndividuals;
                                    household.Families.Add(GetFamilyFromPool(familyPool, rand.Take()));
                                    //TODO: Assumption is that there is only 1 additional individual
                                    household.Families.Add(GetFamilyFromPool(individualPool, rand.Take()));
                                }
                                break;
                            case 5:
                                {
                                    household.HouseholdType = HouseholdComposition.MultiFamily;
                                    //TODO: Assumption is that there are two families for this type
                                    household.Families.Add(GetFamilyFromPool(familyPool, rand.Take()));
                                    household.Families.Add(GetFamilyFromPool(familyPool, rand.Take()));
                                }
                                break;

                        }
                        targetPersons -= AddHouseholdToRepositories(household, householdRepository, familyRepository, personRepo);
                    }
                });
            }
Exemplo n.º 3
0
 private int AddHouseholdToRepositories(Household household, Repository<Household> householdRepository, Repository<Family> familyRepository, Repository<Person> personRepo)
 {
     int persons = 0;
     foreach (var family in household.Families)
     {
         foreach (var person in family.Persons)
         {
             personRepo.AddNew(person);
             persons++;
         }
         familyRepository.AddNew(family);
     }
     householdRepository.AddNew(household);
     return persons;
 }
Exemplo n.º 4
0
 public override void BeingRemoved()
 {
     Household?.RemoveFamily(this);
 }