Exemplo n.º 1
0
        public void LoadData()
        {
            var zoneArray = Root.ZoneSystem.ZoneArray;
            var zones     = zoneArray.GetFlatData();
            var resources = ResourcesToAdd.Select(resource => resource.AquireResource <SparseArray <float> >().GetFlatData()).ToArray();
            SparseArray <float> data;

            data = SaveRatesBasedOnPD ? ZoneSystemHelper.CreatePDArray <float>(zoneArray) : zoneArray.CreateSimilarArray <float>();
            var flatData = data.GetFlatData();

            if (VectorHelper.IsHardwareAccelerated)
            {
                for (int j = 0; j < resources.Length; j++)
                {
                    VectorHelper.Add(flatData, 0, flatData, 0, resources[j], 0, flatData.Length);
                }
            }
            else
            {
                for (int j = 0; j < resources.Length; j++)
                {
                    var currentResource = resources[j];
                    for (int i = 0; i < currentResource.Length; i++)
                    {
                        flatData[i] += currentResource[i];
                    }
                }
            }
            Data = data;
        }
        public void IterationStarting(int iteration)
        {
            // initialize data structures
            HouseholdsByPD = ZoneSystemHelper.CreatePDArray <PDData>(Root.ZoneSystem.ZoneArray);
            var flat = HouseholdsByPD.GetFlatData();

            for (int i = 0; i < flat.Length; i++)
            {
                flat[i] = new PDData(HouseholdsByPD.GetSparseIndex(i));
            }
        }
Exemplo n.º 3
0
        public void LoadData()
        {
            var zoneArray = Root.ZoneSystem.ZoneArray;
            var zones     = zoneArray.GetFlatData();
            var resources = ResourcesToAdd.Select(resource => resource.AcquireResource <SparseArray <float> >().GetFlatData()).Union(
                ResourcesToAddRaw.Select(source =>
            {
                source.LoadData();
                var ret = source.GiveData();
                source.UnloadData();
                return(ret.GetFlatData());
            })
                ).ToArray();
            SparseArray <float> data;

            data = SaveRatesBasedOnPD ? ZoneSystemHelper.CreatePDArray <float>(zoneArray) : zoneArray.CreateSimilarArray <float>();
            var flatData = data.GetFlatData();

            for (int j = 0; j < resources.Length; j++)
            {
                VectorHelper.Add(flatData, 0, flatData, 0, resources[j], 0, flatData.Length);
            }
            Data = data;
        }
        /// <summary>
        /// Gather the data for each PD from the database
        /// </summary>
        /// <param name="employmentStatusChar">The employment code we want to look at</param>
        /// <param name="command">The command / connection to use</param>
        /// <param name="zones">The zone system to extract PD's for</param>
        /// <returns>The occupation data stored per PD</returns>
        private SparseArray <float[]> Execute(char employmentStatusChar, IDbCommand command, SparseArray <IZone> zones)
        {
            var pds = ZoneSystemHelper.CreatePDArray <float[]>(zones);

            command.CommandText = @"
SELECT Persons.EmploymentStatus, PlanningDistrict.PD, Persons.Occupation, SUM(Persons.ExpansionFactor) AS ExpandedPersons
FROM (((Households INNER JOIN Persons ON Households.TTSYear = Persons.TTSYear AND Households.HouseholdId = Persons.HouseholdId)
	INNER JOIN HouseholdZones ON Households.TTSYear = HouseholdZones.TTSYear AND Households.HouseholdId = HouseholdZones.HouseholdId)
	INNER JOIN PlanningDistrict ON HouseholdZones.ZoneSystem = PlanningDistrict.ZoneSystem AND HouseholdZones.Zone = PlanningDistrict.Zone)
" + "WHERE Households.TTSYear = " + this.TTSYear + " AND HouseholdZones.ZoneSystem = " + this.ZoneSystemNumber + " AND (Persons.EmploymentStatus = '" + employmentStatusChar + "' )"
                                  + @" AND Persons.Occupation <> '9'
GROUP BY Persons.EmploymentStatus, PlanningDistrict.PD, Persons.Occupation
ORDER BY Persons.EmploymentStatus ASC, PlanningDistrict.PD ASC, Persons.Occupation ASC;
";
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var  pd     = reader.GetInt32(1);
                    var  occ    = reader.GetString(2);
                    bool exists = true;
                    var  data   = pds[pd];
                    if (data == null)
                    {
                        if (pds.ContainsIndex(pd))
                        {
                            exists = false;
                            data   = new float[4];
                        }
                        else
                        {
                            continue;
                        }
                    }
                    int index;
                    switch (occ)
                    {
                    case "P":
                        index = 0;
                        break;

                    case "G":
                        index = 1;
                        break;

                    case "S":
                        index = 2;
                        break;

                    case "M":
                        index = 3;
                        break;

                    default:
                        continue;
                    }
                    data[index] = (float)reader.GetDouble(3);
                    if (!exists)
                    {
                        pds[pd] = data;
                    }
                }
            }
            return(pds);
        }