Ejemplo n.º 1
0
        private void LoadDriversLicenseDistribution()
        {
            DriversLicenseRates = Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTwinIndex <float> >();
            if (!DriversLicenseRateFile.ContainsFileName())
            {
                return;
            }
            using (CommentedCsvReader reader = new CommentedCsvReader(DriversLicenseRateFile.GetFileName(Root.InputBaseDirectory)))
            {
                while (reader.NextLine())
                {
                    if (reader.NumberOfCurrentCells >= 4)
                    {
                        reader.Get(out int pd, 0);
                        reader.Get(out int ageCat, 1);
                        reader.Get(out int empStat, 2);
                        reader.Get(out float chance, 3);
                        foreach (var zone in PDZoneMap[pd])
                        {
                            var zoneData = DriversLicenseRates[zone];
                            if (zoneData == null)
                            {
                                zoneData = SparseTwinIndex <float> .CreateSimilarArray(AgeCategories, EmploymentStatus);

                                DriversLicenseRates[zone] = zoneData;
                            }
                            zoneData[ageCat, empStat] = chance;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void LoadJobTypeDisribution()
        {
            JobTypeRates = SparseTwinIndex <float> .CreateSimilarArray(Root.ZoneSystem.ZoneArray, EmploymentStatus);

            var employmentIndexes = EmploymentStatus.ValidIndexies().ToArray();

            using (CsvReader reader = new CsvReader(GetFullPath(JobEmploymentRateFile)))
            {
                if (JobEmploymentRateFileHeader)
                {
                    reader.LoadLine();
                }
                while (!reader.EndOfFile)
                {
                    var length = reader.LoadLine();
                    if (length >= 3)
                    {
                        reader.Get(out int pd, 0);
                        reader.Get(out float fulltime, 1);
                        reader.Get(out float parttime, 2);
                        if (PdZoneMap.TryGetValue(pd, out List <int> zones))
                        {
                            foreach (var zone in zones)
                            {
                                JobTypeRates[zone, employmentIndexes[1]] = fulltime;
                                JobTypeRates[zone, employmentIndexes[2]] = parttime;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void LoadJobTypeDisribution()
        {
            this.JobTypeRates = SparseTwinIndex <float> .CreateSimilarArray(this.Root.ZoneSystem.ZoneArray, this.EmploymentStatus);

            var employmentIndexes = this.EmploymentStatus.ValidIndexies().ToArray();

            using (CommentedCsvReader reader = new CommentedCsvReader(this.JobEmploymentRateFile.GetFileName(Root.InputBaseDirectory)))
            {
                int   pd;
                float fulltime;
                float parttime;

                while (reader.NextLine())
                {
                    if (reader.NumberOfCurrentCells >= 3)
                    {
                        reader.Get(out pd, 0);
                        reader.Get(out fulltime, 1);
                        reader.Get(out parttime, 2);
                        foreach (var zone in this.PDZoneMap[pd])
                        {
                            this.JobTypeRates[zone, employmentIndexes[1]] = fulltime;
                            this.JobTypeRates[zone, employmentIndexes[2]] = parttime;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private SparseTwinIndex <float> GetResultMatrix(SparseTwinIndex <float> first)
 {
     if (OverwriteFirst)
     {
         return(first);
     }
     return(first.CreateSimilarArray <float>());
 }
Ejemplo n.º 5
0
        private static SparseTwinIndex <float> BuildDistribution(SparseArray <float> O, SparseArray <float> D, int oLength, float[] flows)
        {
            var ret = SparseTwinIndex <float> .CreateSimilarArray(O, D);

            var retFlat = ret.GetFlatData();

            System.Threading.Tasks.Parallel.For(0, oLength,
                                                delegate(int i)
            {
                var iOffset = i * oLength;
                for (int j = 0; j < oLength; j++)
                {
                    retFlat[i][j] = flows[iOffset + j];
                }
            });
            return(ret);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Replicate a SparseTwinIndex
        /// </summary>
        /// <typeparam name="T">The type of data</typeparam>
        /// <param name="baseData">The data source to replicate</param>
        /// <returns>An exact copy of the sparse twin index.</returns>
        private static SparseTwinIndex <T> Replicate <T>(SparseTwinIndex <T> baseData)
        {
            var ret      = baseData.CreateSimilarArray <T>();
            var flatRet  = ret.GetFlatData();
            var flatBase = baseData.GetFlatData();

            for (int i = 0; i < flatBase.Length; i++)
            {
                var retRow  = flatRet[i];
                var baseRow = flatBase[i];
                for (int j = 0; j < retRow.Length; j++)
                {
                    retRow[j] = baseRow[j];
                }
            }
            return(ret);
        }
Ejemplo n.º 7
0
        private void LoadDriversLicenseDistribution()
        {
            DriversLicenseRates = Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTwinIndex <float> >();
            var employmentIndexes = EmploymentStatus.ValidIndexies().ToArray();

            using (CsvReader reader = new CsvReader(GetFullPath(DriversLicenseRateFile)))
            {
                int   pd;
                int   ageCat;
                int   empStat;
                float chance;
                if (DriversLicenseRateFileHeader)
                {
                    reader.LoadLine();
                }
                while (!reader.EndOfFile)
                {
                    var length = reader.LoadLine();
                    if (length >= 4)
                    {
                        reader.Get(out pd, 0);
                        reader.Get(out ageCat, 1);
                        reader.Get(out empStat, 2);
                        reader.Get(out chance, 3);
                        List <int> zones;
                        if (PDZoneMap.TryGetValue(pd, out zones))
                        {
                            foreach (var zone in zones)
                            {
                                var zoneData = this.DriversLicenseRates[zone];
                                if (zoneData == null)
                                {
                                    zoneData = SparseTwinIndex <float> .CreateSimilarArray(AgeCategories, EmploymentStatus);

                                    this.DriversLicenseRates[zone] = zoneData;
                                }
                                zoneData[ageCat, empStat] = chance;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void RunValidationChecks(SparseTwinIndex <float> runData, SparseTwinIndex <float> truthData)
        {
            var diff = runData.CreateSimilarArray <float>().GetFlatData();

            // Compute the differences at the zone level
            ComputeDifferences(runData, truthData, diff);
            // we can save all of the files at the same time and work out the aggregations
            Parallel.Invoke(
                delegate
            {
                ProduceZoneData(diff, runData, truthData);
            },
                delegate
            {
                ProducePDData(diff, runData, truthData);
            },
                delegate
            {
                ProduceRegionData(diff, runData, truthData);
            }
                );
        }
Ejemplo n.º 9
0
        public void LoadData()
        {
            if (!Root.ZoneSystem.Loaded)
            {
                Root.ZoneSystem.LoadData();
            }

            SparseTwinIndex <float> distances = Root.ZoneSystem.Distances;

            if (!ConvertToKM)
            {
                Data = distances;
            }
            else
            {
                var flatDistances = distances.GetFlatData();
                Data = distances.CreateSimilarArray <float>();
                var local = Data.GetFlatData();
                if (VectorHelper.IsHardwareAccelerated)
                {
                    for (int i = 0; i < local.Length; i++)
                    {
                        VectorHelper.Multiply(local[i], 0, flatDistances[i], 0, 0.001f, local.Length);
                    }
                }
                else
                {
                    for (int i = 0; i < local.Length; i++)
                    {
                        for (int j = 0; j < local[i].Length; j++)
                        {
                            local[i][j] = flatDistances[i][j] * 0.001f;
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void ValidateEmploymentStatus()
        {
            var zoneArray              = ZoneSystem.ZoneArray;
            var validZones             = zoneArray.ValidIndexies().ToArray();
            var employmentStatusDist   = zoneArray.CreateSimilarArray <SparseTwinIndex <float> >();
            var validEmploymentStatus  = Demographics.EmploymentStatus.ValidIndexies().ToArray();
            var numberEmploymentStatus = validEmploymentStatus.Length;
            var numberOfZones          = validZones.Length;
            var validAges              = Demographics.AgeCategories.ValidIndexies().ToArray();
            var agesLength             = validAges.Length;

            //for(int i = 0; i < numberOfZones; i++)
            Parallel.For(0, numberOfZones,
                         delegate(int i)
            {
                var zoneNumber = validZones[i];
                var pop        = Population.Population[zoneNumber];
                var popLength  = pop.Length;
                var dist       = SparseTwinIndex <float> .CreateSimilarArray(Demographics.AgeCategories, Demographics.EmploymentStatus);
                var ages       = Demographics.AgeCategories;

                for (int p = 0; p < popLength; p++)
                {
                    var person    = pop[p];
                    var personAge = person.Age;
                    for (int a = 0; a < agesLength; a++)
                    {
                        var range = ages[validAges[a]];
                        if (personAge >= range.Start && personAge <= range.Stop)
                        {
                            dist[validAges[a], person.EmploymentStatus] += person.ExpansionFactor;
                            break;
                        }
                    }
                }
                employmentStatusDist[zoneNumber] = dist;
            });
            using (StreamWriter writer = new StreamWriter(EmploymentStatusReportFile))
            {
                writer.Write("Zone,AgeCat");
                foreach (var emp in Demographics.EmploymentStatus.ValidIndexies())
                {
                    writer.Write(',');
                    writer.Write(Demographics.EmploymentStatus[emp]);
                }
                writer.WriteLine("Population");
                foreach (var zone in zoneArray.ValidIndexies())
                {
                    var data = employmentStatusDist[zone];
                    if (zoneArray[zone].Population <= 0)
                    {
                        continue;
                    }
                    for (int ageCat = 0; ageCat < agesLength; ageCat++)
                    {
                        writer.Write(zone);
                        writer.Write(',');
                        writer.Write(validAges[ageCat]);
                        var total      = 0f;
                        var population = zoneArray[zone].Population * Demographics.AgeRates[zone, validAges[ageCat]];
                        for (int e = 0; e < numberEmploymentStatus; e++)
                        {
                            total += data[validAges[ageCat], validEmploymentStatus[e]];
                        }

                        for (int e = 0; e < numberEmploymentStatus; e++)
                        {
                            var res = data[validAges[ageCat], validEmploymentStatus[e]] / total;
                            if (float.IsNaN(res))
                            {
                                res = 0;
                            }
                            res -= Demographics.EmploymentStatusRates[zone][validAges[ageCat], validEmploymentStatus[e]];
                            writer.Write(',');
                            writer.Write(res * population);
                        }
                        writer.Write(',');
                        writer.WriteLine(population);
                    }
                }
            }
        }