private void LoadAgeDist()
        {
            List <AgeDist> ageDistributions = new List <AgeDist>();
            var            ageCategories    = AgeCategories.Count;

            using (CommentedCsvReader reader = new CommentedCsvReader(AgeDistributionFile.GetFileName(Root.InputBaseDirectory)))
            {
                while (reader.NextLine())
                {
                    if (reader.NumberOfCurrentCells >= ageCategories + 1)
                    {
                        float[] ageD = new float[ageCategories];
                        reader.Get(out int zone, 0);
                        for (int i = 1; i < reader.NumberOfCurrentCells; i++)
                        {
                            reader.Get(out ageD[i - 1], i);
                        }
                        ageDistributions.Add(new AgeDist {
                            Zone = zone, Percentages = ageD
                        });
                    }
                }
            }
            int numberOfSetZones = 0;

            foreach (var ageDist in ageDistributions)
            {
                if (!PDZoneMap.TryGetValue(ageDist.Zone, out List <int> pd))
                {
                    throw new XTMFRuntimeException(this, "In " + Name + " we were unable to find a planning district for the zone number '" + ageDist.Zone + "' while loading the age distribution.");
                }
                numberOfSetZones += pd.Count;
            }

            var elements         = ageDistributions.Count;
            var first            = new int[numberOfSetZones * ageCategories];
            var second           = new int[numberOfSetZones * ageCategories];
            var d                = new float[numberOfSetZones * ageCategories];
            var validAgeCategory = AgeCategories.ValidIndexies().ToArray();
            int soFar            = 0;

            for (int i = 0; i < elements; i++)
            {
                var zones = PDZoneMap[ageDistributions[i].Zone];
                foreach (var zone in zones)
                {
                    for (int j = 0; j < ageCategories; j++)
                    {
                        first[soFar]  = zone;
                        second[soFar] = validAgeCategory[j];
                        d[soFar]      = ageDistributions[i].Percentages[j];
                        soFar++;
                    }
                }
            }
            AgeRates = SparseTwinIndex <float> .CreateTwinIndex(first, second, d);
        }
Example #2
0
        private void LoadAgeDist()
        {
            List <AgeDist> ageDistributions = new List <AgeDist>();
            var            ageCategories    = AgeCategories.Count;

            using (CsvReader reader = new CsvReader(GetFullPath(AgeDistributionFile)))
            {
                int length;
                if (AgeDistributionFileHeader)
                {
                    // burn the header
                    reader.LoadLine();
                }
                while ((length = reader.LoadLine()) > ageCategories)
                {
                    float[] ageD = new float[ageCategories];
                    reader.Get(out int zone, 0);
                    for (int i = 1; i < length; i++)
                    {
                        reader.Get(out ageD[i - 1], i);
                    }
                    ageDistributions.Add(new AgeDist {
                        Zone = zone, Percentages = ageD
                    });
                }
            }
            int numberOfSetZones = 0;

            foreach (var ageDist in ageDistributions)
            {
                if (PdZoneMap.TryGetValue(ageDist.Zone, out List <int> temp))
                {
                    numberOfSetZones += temp.Count;
                }
            }

            var elements         = ageDistributions.Count;
            var first            = new int[numberOfSetZones * ageCategories];
            var second           = new int[numberOfSetZones * ageCategories];
            var d                = new float[numberOfSetZones * ageCategories];
            var validAgeCategory = AgeCategories.ValidIndexies().ToArray();
            int soFar            = 0;

            for (int i = 0; i < elements; i++)
            {
                if (PdZoneMap.TryGetValue(ageDistributions[i].Zone, out List <int> zones))
                {
                    foreach (var zone in zones)
                    {
                        for (int j = 0; j < ageCategories; j++)
                        {
                            first[soFar]  = zone;
                            second[soFar] = validAgeCategory[j];
                            d[soFar]      = ageDistributions[i].Percentages[j];
                            soFar++;
                        }
                    }
                }
            }
            AgeRates = SparseTwinIndex <float> .CreateTwinIndex(first, second, d);
        }
Example #3
0
        public void LoadData()
        {
            Loaded = true;
            LoadPdZoneMap();
            LoadCategoryInformation();
            LoadAgeDist();
            LoadEmploymentDist();
            LoadOccupationDist();
            LoadStudentDist();
            LoadJobOccupationDistribution();
            LoadJobTypeDisribution();
            LoadDriversLicenseDistribution();
            LoadNumberOfCarsDistribution();
            if (SaveDataIntoZones)
            {
                foreach (var zone in Root.ZoneSystem.ZoneArray.ValidIndexies())
                {
                    var   z                   = Root.ZoneSystem.ZoneArray[zone];
                    float generalworker       = 0;
                    float manufacturingworker = 0;
                    float professionalworker  = 0;
                    float salesWorker         = 0;
                    float generalJob          = 0;
                    float manufacturingJob    = 0;
                    float professionalJob     = 0;
                    float salesJob            = 0;
                    var   occRates            = OccupationRates[zone];
                    var   empData             = EmploymentStatusRates[zone];
                    if (occRates != null && empData != null)
                    {
                        foreach (var age in AgeCategories.ValidIndexies())
                        {
                            var agePop = z.Population * AgeRates[zone, age];
                            foreach (var status in EmploymentStatus.ValidIndexies())
                            {
                                var statusPop = agePop * empData[age, status];
                                professionalworker  += statusPop * occRates[age, status, 1];
                                generalworker       += statusPop * occRates[age, status, 2];
                                salesWorker         += statusPop * occRates[age, status, 3];
                                manufacturingworker += statusPop * occRates[age, status, 4];
                            }
                        }
                        foreach (var status in EmploymentStatus.ValidIndexies())
                        {
                            var statusJobPop = z.Employment * JobTypeRates[zone, status];
                            professionalJob  += statusJobPop * JobOccupationRates[zone, status, 1];
                            generalJob       += statusJobPop * JobOccupationRates[zone, status, 2];
                            salesJob         += statusJobPop * JobOccupationRates[zone, status, 3];
                            manufacturingJob += statusJobPop * JobOccupationRates[zone, status, 4];
                        }
                    }
                    z.GeneralEmployment       = generalJob;
                    z.ManufacturingEmployment = manufacturingJob;
                    z.ProfessionalEmployment  = professionalJob;
                    z.RetailEmployment        = salesJob;

                    z.WorkGeneral       = generalworker;
                    z.WorkManufacturing = manufacturingworker;
                    z.WorkProfessional  = professionalworker;
                    z.WorkRetail        = salesWorker;
                }
            }
        }