private void LoadTriIndexedData()
        {
            // first 2 columns are the first 2, the remainder are the last dimension enumerated
            List <int>   first  = new List <int>();
            List <int>   second = new List <int>();
            List <int>   third  = new List <int>();
            List <float> data   = new List <float>();

            StoreData(first, second, third, data);
            Data = SparseTriIndex <float> .CreateSparseTriIndex(first.ToArray(), second.ToArray(), third.ToArray(), data.ToArray());
        }
Exemple #2
0
        public void LoadData()
        {
            // get a replica of the zone system
            SparseArray <SparseTriIndex <float> > temp = this.Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTriIndex <float> >();
            var total = (this.EmploymentCategoryRange[0].Stop - this.EmploymentCategoryRange[0].Start + 1)
                        * (this.MobilityRange[0].Stop - this.MobilityRange[0].Start + 1)
                        * (this.AgeRange[0].Stop - this.AgeRange[0].Start + 1);

            int[]   first  = new int[total];
            int[]   second = new int[total];
            int[]   third  = new int[total];
            float[] data   = new float[total];
            int     pos    = 0;

            for (int i = this.EmploymentCategoryRange[0].Start; i <= this.EmploymentCategoryRange[0].Stop; i++)
            {
                for (int j = this.MobilityRange[0].Start; j <= this.MobilityRange[0].Stop; j++)
                {
                    for (int k = this.AgeRange[0].Start; k <= this.AgeRange[0].Stop; k++)
                    {
                        first[pos]  = i;
                        second[pos] = j;
                        third[pos]  = k;
                        data[pos]   = 0f;
                        pos++;
                    }
                }
            }
            var flatTemp = temp.GetFlatData();

            // initialize the first one, and use it for the first zone
            flatTemp[0] = SparseTriIndex <float> .CreateSparseTriIndex(first, second, third, data);

            //release memory resources before we allocate a bunch more
            first = second = third = null;
            // now create a clone of this for each zone [i starts at 1 since 0 has already been set]
            for (int i = 1; i < flatTemp.Length; i++)
            {
                flatTemp[i] = flatTemp[0].CreateSimilarArray <float>();
            }
            this.Data = temp;
        }
Exemple #3
0
        public void SparseTriIndexTest()
        {
            var    length = 1000000;
            Random r      = new Random();

            int[]   baseData = new int[length];
            int[][] position = GeneratePositions(3, length);
            for (int i = 0; i < length; i++)
            {
                baseData[i] = r.Next();
            }
            var sparseData = SparseTriIndex <int> .CreateSparseTriIndex(position[0], position[1], position[2], baseData);

            for (int i = 0; i < length; i++)
            {
                if (baseData[i] != sparseData[position[0][i], position[1][i], position[2][i]])
                {
                    Assert.Fail($"{baseData[i]} != {sparseData[position[0][i], position[1][i], position[2][i]]}");
                }
            }
        }
Exemple #4
0
        public void SparseTriIndexTest()
        {
            var    length = 1000000;
            Random r      = new Random();

            int[]   BaseData = new int[length];
            int[][] Position = GeneratePositions(3, length);
            for (int i = 0; i < length; i++)
            {
                BaseData[i] = r.Next();
            }
            var sparseData = SparseTriIndex <int> .CreateSparseTriIndex(Position[0], Position[1], Position[2], BaseData);

            for (int i = 0; i < length; i++)
            {
                if (BaseData[i] != sparseData[Position[0][i], Position[1][i], Position[2][i]])
                {
                    Assert.Fail(String.Format("{0} != {1}", BaseData[i], sparseData[Position[0][i], Position[1][i], Position[2][i]]));
                }
            }
        }
Exemple #5
0
        public void SparseTriIndexFlatTest()
        {
            var    length = 1000000;
            Random r      = new Random();

            int[]   baseData = new int[length];
            int[][] position = GeneratePositions(3, length);
            for (int i = 0; i < length; i++)
            {
                baseData[i] = r.Next();
            }
            var sparseData = SparseTriIndex <int> .CreateSparseTriIndex(position[0], position[1], position[2], baseData);

            for (int dataPoint = 0; dataPoint < length; dataPoint++)
            {
                int i = position[0][dataPoint], j = position[1][dataPoint], k = position[2][dataPoint];

                if (!sparseData.GetFlatIndex(ref i, ref j, ref k))
                {
                    Assert.Fail("Valid position, {0}:{1}:{2} was deemed invalid", position[0][dataPoint], position[1][dataPoint], position[2][dataPoint]);
                }
            }
        }
        private void LoadOccupationDist()
        {
            List <OccupationDist> occupation = new List <OccupationDist>();

            if (SaveDataIntoZones)
            {
                foreach (var zone in Root.ZoneSystem.ZoneArray.ValidIndexies())
                {
                    var z = Root.ZoneSystem.ZoneArray[zone];
                    z.WorkGeneral       = 0;
                    z.WorkManufacturing = 0;
                    z.WorkProfessional  = 0;
                    z.WorkRetail        = 0;
                }
            }
            using (CommentedCsvReader reader = new CommentedCsvReader(OccupationDistributionFile.GetFileName(Root.InputBaseDirectory)))
            {
                float[] data = new float[7];

                while (reader.NextLine())
                {
                    if (reader.NumberOfCurrentCells < 7)
                    {
                        continue;
                    }
                    for (int i = 0; i < data.Length && i < reader.NumberOfCurrentCells; i++)
                    {
                        reader.Get(out data[i], i);
                    }
                    occupation.Add(new OccupationDist
                    {
                        AgeCat           = (int)data[1],
                        Zone             = (int)data[0],
                        EmploymentStatus = (int)data[2],
                        Professional     = data[3],
                        General          = data[4],
                        Sales            = data[5],
                        Manufacturing    = data[6]
                    });
                }
            }
            occupation.Sort(delegate(OccupationDist first, OccupationDist second)
            {
                if (first.Zone > second.Zone)
                {
                    return(1);
                }
                if (first.Zone == second.Zone)
                {
                    if (first.AgeCat > second.AgeCat)
                    {
                        return(1);
                    }
                    if (first.AgeCat == second.AgeCat)
                    {
                        if (first.EmploymentStatus > second.EmploymentStatus)
                        {
                            return(1);
                        }
                        if (first.EmploymentStatus == second.EmploymentStatus)
                        {
                            return(0);
                        }
                    }
                }
                return(-1);
            });
            OccupationRates = Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTriIndex <float> >();
            var start            = 0;
            var stop             = 0;
            var employmentLength = occupation.Count;

            int[]   firstIndex;
            int[]   secondIndex;
            int[]   thirdIndex;
            float[] d;
            int     numberOfElements;

            for (int i = 1; i < employmentLength; i++)
            {
                if (occupation[i].Zone == occupation[i - 1].Zone)
                {
                    stop = i;
                }
                else
                {
                    numberOfElements = stop - start + 1;
                    firstIndex       = new int[numberOfElements * 5];
                    secondIndex      = new int[numberOfElements * 5];
                    thirdIndex       = new int[numberOfElements * 5];
                    d = new float[numberOfElements * 5];
                    for (int j = 0; j < numberOfElements; j++)
                    {
                        for (int k = 0; k < 5; k++)
                        {
                            firstIndex[j * 5 + k]  = occupation[start + j].AgeCat;
                            secondIndex[j * 5 + k] = occupation[start + j].EmploymentStatus;
                            thirdIndex[j * 5 + k]  = k;
                        }
                        d[j * 5 + 1] = occupation[start + j].Professional;
                        d[j * 5 + 2] = occupation[start + j].General;
                        d[j * 5 + 3] = occupation[start + j].Sales;
                        d[j * 5 + 4] = occupation[start + j].Manufacturing;
                    }
                    if (OccupationByPD)
                    {
                        foreach (var z in PDZoneMap[occupation[i - 1].Zone])
                        {
                            OccupationRates[z] = SparseTriIndex <float> .CreateSparseTriIndex(firstIndex, secondIndex, thirdIndex, d);
                        }
                    }
                    else
                    {
                        OccupationRates[occupation[i - 1].Zone] = SparseTriIndex <float> .CreateSparseTriIndex(firstIndex, secondIndex, thirdIndex, d);
                    }
                    start = i;
                }
            }
            numberOfElements = stop - start + 1;
            firstIndex       = new int[numberOfElements * 5];
            secondIndex      = new int[numberOfElements * 5];
            thirdIndex       = new int[numberOfElements * 5];
            d = new float[numberOfElements * 5];
            for (int j = 0; j < numberOfElements; j++)
            {
                for (int k = 0; k < 5; k++)
                {
                    firstIndex[j * 5 + k]  = occupation[start + j].AgeCat;
                    secondIndex[j * 5 + k] = occupation[start + j].EmploymentStatus;
                    thirdIndex[j * 5 + k]  = k;
                }

                d[j * 5 + 1] = occupation[start + j].Professional;
                d[j * 5 + 2] = occupation[start + j].General;
                d[j * 5 + 3] = occupation[start + j].Sales;
                d[j * 5 + 4] = occupation[start + j].Manufacturing;
            }
            if (OccupationByPD)
            {
                foreach (var z in PDZoneMap[occupation[employmentLength - 1].Zone])
                {
                    OccupationRates[z] = SparseTriIndex <float> .CreateSparseTriIndex(firstIndex, secondIndex, thirdIndex, d);
                }
            }
            else
            {
                OccupationRates[occupation[employmentLength - 1].Zone] = SparseTriIndex <float> .CreateSparseTriIndex(firstIndex, secondIndex, thirdIndex, d);
            }
        }
Exemple #7
0
        private void LoadOccupationDist()
        {
            List <OccupationDist> occupation = new List <OccupationDist>();
            List <int>            zones;

            if (SaveDataIntoZones)
            {
                foreach (var zone in Root.ZoneSystem.ZoneArray.ValidIndexies())
                {
                    var z = Root.ZoneSystem.ZoneArray[zone];
                    z.WorkGeneral       = 0;
                    z.WorkManufacturing = 0;
                    z.WorkProfessional  = 0;
                    z.WorkRetail        = 0;
                }
            }
            using (CsvReader reader = new CsvReader(GetFullPath(OccupationDistributionFile)))
            {
                int     length;
                float[] data = new float[7];
                if (OccupationDistributionFileHeader)
                {
                    // burn the header
                    reader.LoadLine();
                }
                while ((length = reader.LoadLine()) > 6)
                {
                    for (int i = 0; i < data.Length && i < length; i++)
                    {
                        reader.Get(out data[i], i);
                    }
                    occupation.Add(new OccupationDist
                    {
                        AgeCat           = (int)data[1],
                        Zone             = (int)data[0],
                        EmploymentStatus = (int)data[2],
                        Professional     = data[3],
                        General          = data[4],
                        Sales            = data[5],
                        Manufacturing    = data[6]
                    });
                }
            }
            occupation.Sort(delegate(OccupationDist first, OccupationDist second)
            {
                if (first.Zone > second.Zone)
                {
                    return(1);
                }
                if (first.Zone == second.Zone)
                {
                    if (first.AgeCat > second.AgeCat)
                    {
                        return(1);
                    }
                    if (first.AgeCat == second.AgeCat)
                    {
                        if (first.EmploymentStatus > second.EmploymentStatus)
                        {
                            return(1);
                        }
                        if (first.EmploymentStatus == second.EmploymentStatus)
                        {
                            return(0);
                        }
                    }
                }
                return(-1);
            });
            OccupationRates = Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTriIndex <float> >();
            var start            = 0;
            var stop             = 0;
            var employmentLength = occupation.Count;

            int[]   firstIndex;
            int[]   secondIndex;
            int[]   thirdIndex;
            float[] d;
            int     numberOfElements;

            for (int i = 1; i < employmentLength; i++)
            {
                if (occupation[i].Zone == occupation[i - 1].Zone)
                {
                    stop = i;
                }
                else
                {
                    numberOfElements = stop - start + 1;
                    firstIndex       = new int[numberOfElements * 5];
                    secondIndex      = new int[numberOfElements * 5];
                    thirdIndex       = new int[numberOfElements * 5];
                    d = new float[numberOfElements * 5];
                    for (int j = 0; j < numberOfElements; j++)
                    {
                        for (int k = 0; k < 5; k++)
                        {
                            firstIndex[j * 5 + k]  = occupation[start + j].AgeCat;
                            secondIndex[j * 5 + k] = occupation[start + j].EmploymentStatus;
                            thirdIndex[j * 5 + k]  = k;
                        }
                        d[j * 5 + 1] = occupation[start + j].Professional;
                        d[j * 5 + 2] = occupation[start + j].General;
                        d[j * 5 + 3] = occupation[start + j].Sales;
                        d[j * 5 + 4] = occupation[start + j].Manufacturing;
                    }
                    if (PdZoneMap.TryGetValue(occupation[i - 1].Zone, out zones))
                    {
                        foreach (var z in zones)
                        {
                            OccupationRates[z] = SparseTriIndex <float> .CreateSparseTriIndex(firstIndex, secondIndex, thirdIndex, d);
                        }
                    }
                    start = i;
                }
            }
            numberOfElements = stop - start + 1;
            firstIndex       = new int[numberOfElements * 5];
            secondIndex      = new int[numberOfElements * 5];
            thirdIndex       = new int[numberOfElements * 5];
            d = new float[numberOfElements * 5];
            for (int j = 0; j < numberOfElements; j++)
            {
                for (int k = 0; k < 5; k++)
                {
                    firstIndex[j * 5 + k]  = occupation[start + j].AgeCat;
                    secondIndex[j * 5 + k] = occupation[start + j].EmploymentStatus;
                    thirdIndex[j * 5 + k]  = k;
                }

                d[j * 5 + 1] = occupation[start + j].Professional;
                d[j * 5 + 2] = occupation[start + j].General;
                d[j * 5 + 3] = occupation[start + j].Sales;
                d[j * 5 + 4] = occupation[start + j].Manufacturing;
            }
            if (PdZoneMap.TryGetValue(occupation[employmentLength - 1].Zone, out zones))
            {
                foreach (var z in zones)
                {
                    OccupationRates[z] = SparseTriIndex <float> .CreateSparseTriIndex(firstIndex, secondIndex, thirdIndex, d);
                }
            }
        }