override public void Generate(SparseArray <float> production, SparseArray <float> attractions) { if (LoadData) { if (DailyRates == null) { this.LoadDailyRates.LoadData(); this.DailyRates = this.LoadDailyRates.GiveData(); } if (TimeOfDayRates == null) { this.LoadTimeOfDayRates.LoadData(); this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData(); } } var flatProduction = production.GetFlatData(); var flatAttraction = attractions.GetFlatData(); var numberOfIndexes = flatAttraction.Length; // Compute the Production and Attractions ComputeProduction(flatProduction, flatAttraction, numberOfIndexes); //We do not normalize the attraction if (LoadData) { this.LoadDailyRates.UnloadData(); this.LoadTimeOfDayRates.UnloadData(); DailyRates = null; TimeOfDayRates = null; } }
private SparseTriIndex <float> ConvertResults(float[] results, SparseArray <IZone> zoneSystem) { SparseTriIndex <float> ret = Data; // first create the datastructure if (ret == null) { ret = SparseTriIndex <float> .CreateSimilarArray(new SparseArray <int>(new SparseIndexing() { Indexes = new SparseSet[] { new SparseSet() { BaseLocation = 0, Start = 0, Stop = NumberOfWorkerCategories - 1 } } }), zoneSystem, zoneSystem); } // now fill it var r = ret.GetFlatData(); var numberOfZones = r[0].Length; Parallel.For(0, numberOfZones, (int i) => { for (int workerCategory = 0; workerCategory < r.Length; workerCategory++) { var workerCategoryMatrix = r[workerCategory]; var pos = sizeof(float) * ((workerCategoryMatrix.Length * workerCategoryMatrix.Length) * workerCategory + numberOfZones * i); Buffer.BlockCopy(results, pos, workerCategoryMatrix[i], 0, numberOfZones * sizeof(float)); } }); return(ret); }
public override void Generate(SparseArray<float> production, SparseArray<float> attractions) { if(LoadData) { LoadExternalWorkerRates.LoadData(); LoadWorkAtHomeRates.LoadData(); LoadExternalJobsRates.LoadData(); ExternalRates = LoadExternalWorkerRates.GiveData(); WorkAtHomeRates = LoadWorkAtHomeRates.GiveData(); ExternalRates = LoadExternalJobsRates.GiveData(); } var flatProduction = production.GetFlatData(); var flatWah = new float[flatProduction.Length]; var totalProduction = ComputeProduction(flatProduction, flatWah); var totalAttraction = ComputeAttraction(attractions.GetFlatData()); Normalize(production.GetFlatData(), attractions.GetFlatData(), totalProduction, totalAttraction); totalAttraction = RemoveWAHFromAttraction(attractions.GetFlatData(), flatWah); StoreProductionData(production); WriteGenerationFile(totalProduction, totalAttraction); WriteAttractionFile(attractions); if(LoadData) { LoadExternalWorkerRates.UnloadData(); LoadWorkAtHomeRates.UnloadData(); LoadExternalJobsRates.UnloadData(); WorkAtHomeRates = null; ExternalRates = null; ExternalJobs = null; } }
public override void Generate(SparseArray <float> production, SparseArray <float> attractions) { if (LoadData) { this.LoadExternalWorkerRates.LoadData(); this.LoadWorkAtHomeRates.LoadData(); this.LoadExternalJobsRates.LoadData(); this.ExternalRates = this.LoadExternalWorkerRates.GiveData(); this.WorkAtHomeRates = this.LoadWorkAtHomeRates.GiveData(); this.ExternalRates = this.LoadExternalJobsRates.GiveData(); } var flatProduction = production.GetFlatData(); var flatWah = new float[flatProduction.Length]; var flatIntraZonal = new float[flatProduction.Length]; float elfgta = CalculateElfGTA(); var totalProduction = ComputeProduction(flatProduction, flatWah, flatIntraZonal); var totalAttraction = ComputeAttraction(attractions.GetFlatData()); ApplyWahAndIntrazonal(production.GetFlatData(), attractions.GetFlatData(), flatWah, flatIntraZonal, totalProduction, totalAttraction, elfgta); ApplyAgeCategoryFactor(production.GetFlatData(), attractions.GetFlatData()); Normalize(production.GetFlatData(), attractions.GetFlatData()); WriteGenerationFile(flatProduction.Sum(), attractions.GetFlatData().Sum()); WriteAttractionFile(production, attractions); if (LoadData) { this.LoadExternalWorkerRates.UnloadData(); this.LoadWorkAtHomeRates.UnloadData(); this.LoadExternalJobsRates.UnloadData(); WorkAtHomeRates = null; ExternalRates = null; ExternalJobs = null; } }
private void ProcessEE(SparseTriIndex <float> distribution, SparseArray <float> population, SparseArray <float> employment) { var indexes = population.ValidIndexArray(); Parallel.For(0, indexes.Length, delegate(int i) { var zones = this.Root.ZoneSystem.ZoneArray; var origin = indexes[i]; var originTotal = population[origin] + employment[origin]; var originZone = zones[origin]; // The factor to apply to the distribution to map it to the results var factor = originTotal / (originZone.Population + originZone.Employment); if (originTotal <= 0 | originZone.RegionNumber > 0 | float.IsInfinity(factor)) { return; } var originIndex = zones.GetFlatIndex(origin); var numberOfZones = zones.GetFlatData().Length; foreach (var destination in distribution.ValidIndexes(origin)) { var destinationIndex = zones.GetFlatIndex(destination); // do not process EE trips if (zones[destination].RegionNumber != 0) { continue; } foreach (var mode in distribution.ValidIndexes(origin, destination)) { var ammount = distribution[origin, destination, mode] * factor; AddData(mode, originIndex, destinationIndex, ammount, numberOfZones); } } }); }
private void ProcessExternalToInternal(SparseTriIndex <float> distribution, SparseArray <float> population) { var indexes = population.ValidIndexArray(); Parallel.For(0, indexes.Length, delegate(int i) { var zones = Root.ZoneSystem.ZoneArray; var zoneNumber = indexes[i]; var originPopulation = population[zoneNumber]; var originZone = zones[zoneNumber]; var factor = originPopulation / originZone.Population; if (originPopulation <= 0 | originZone.RegionNumber > 0 | float.IsInfinity(factor)) { return; } var originIndex = zones.GetFlatIndex(zoneNumber); // The factor to apply to the distribution to map it to the results var numberOfZones = zones.GetFlatData().Length; foreach (var destination in distribution.ValidIndexes(zoneNumber)) { var destinationIndex = zones.GetFlatIndex(destination); // do not process EE trips if (zones[destination].RegionNumber == 0) { continue; } foreach (var mode in distribution.ValidIndexes(zoneNumber, destination)) { var ammount = distribution[zoneNumber, destination, mode] * factor; AddData(mode, originIndex, destinationIndex, ammount, numberOfZones); } } }); }
public override void Generate(SparseArray<float> production, SparseArray<float> attractions) { if ( LoadData ) { if ( DailyRates == null ) { this.LoadDailyRates.LoadData(); this.DailyRates = this.LoadDailyRates.GiveData(); } if ( TimeOfDayRates == null ) { this.LoadTimeOfDayRates.LoadData(); this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData(); } } var flatProduction = production.GetFlatData(); var flatAttraction = attractions.GetFlatData(); var numberOfIndexes = flatAttraction.Length; // Compute the Production and Attractions ComputeProduction( flatProduction, flatAttraction, numberOfIndexes ); //We do not normalize the attraction if ( LoadData ) { this.LoadDailyRates.UnloadData(); this.LoadTimeOfDayRates.UnloadData(); DailyRates = null; TimeOfDayRates = null; } }
private void Save(int layerIndex, float[][] flatData, SparseTriIndex <float> data) { var origins = data.ValidIndexes(layerIndex).ToArray(); // if there is no data there is nothing to save! if (origins.Length <= 0) { return; } var destinations = data.ValidIndexes(origins[0]).ToArray(); switch (FileFormat) { case FileFormats.MTX: SaveMTX(layerIndex, flatData, origins, destinations); return; case FileFormats.CSVThirdNormalized: SaveThirdNormalizedCSV(layerIndex, flatData, origins, destinations); return; case FileFormats.CSVSquare: SaveSquareMatrixToCSV(layerIndex, flatData, origins, destinations); return; default: throw new XTMFRuntimeException(this, "Unknown file format!"); } }
private float UnemployedMobilityProbability(int mobility, SparseTriIndex <float> ncars, int age, SparseTwinIndex <float> dlicRate) { switch (mobility) { case 0: return((1 - dlicRate[age, 0]) * ncars[0, age, 0]); case 1: return((1 - dlicRate[age, 0]) * ncars[0, age, 1]); case 2: return((1 - dlicRate[age, 0]) * ncars[0, age, 2]); case 3: return(dlicRate[age, 0] * ncars[1, age, 0]); case 4: return(dlicRate[age, 0] * ncars[1, age, 1]); case 5: return(dlicRate[age, 0] * ncars[1, age, 2]); default: throw new XTMFRuntimeException(this, "Unknown mobility type '" + mobility + "'!"); } }
public override void Generate(SparseArray<float> production, SparseArray<float> attractions) { if ( LoadData ) { if ( DailyRates == null ) { this.LoadDailyRates.LoadData(); this.DailyRates = this.LoadDailyRates.GiveData(); } if ( TimeOfDayRates == null ) { this.LoadTimeOfDayRates.LoadData(); this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData(); } } var flatProduction = production.GetFlatData(); var numberOfIndexes = flatProduction.Length; // Compute the Production ComputeProduction( flatProduction, numberOfIndexes ); float totalProduction = flatProduction.Sum(); WriteGenerationCSV( totalProduction ); //The PoRPoS Model does NOT include having an attraction component. The distribution will handle this case. if ( LoadData ) { this.DailyRates = null; this.TimeOfDayRates = null; } }
override public void Generate(SparseArray <float> production, SparseArray <float> attractions) { if (LoadData) { if (DailyRates == null) { this.LoadDailyRates.LoadData(); this.DailyRates = this.LoadDailyRates.GiveData(); } if (TimeOfDayRates == null) { this.LoadTimeOfDayRates.LoadData(); this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData(); } } var flatProduction = production.GetFlatData(); var numberOfIndexes = flatProduction.Length; // Compute the Production ComputeProduction(flatProduction, numberOfIndexes); float totalProduction = flatProduction.Sum(); WriteGenerationCSV(totalProduction); //The PoRPoS Model does NOT include having an attraction component. The distribution will handle this case. if (LoadData) { this.DailyRates = null; this.TimeOfDayRates = null; } }
public override void Generate(SparseArray <float> production, SparseArray <float> attractions) { if (LoadData) { LoadExternalWorkerRates.LoadData(); LoadWorkAtHomeRates.LoadData(); LoadExternalJobsRates.LoadData(); ExternalRates = LoadExternalWorkerRates.GiveData(); WorkAtHomeRates = LoadWorkAtHomeRates.GiveData(); ExternalRates = LoadExternalJobsRates.GiveData(); } var flatProduction = production.GetFlatData(); var flatWah = new float[flatProduction.Length]; var totalProduction = ComputeProduction(flatProduction, flatWah); var totalAttraction = ComputeAttraction(attractions.GetFlatData()); Normalize(production.GetFlatData(), attractions.GetFlatData(), totalProduction, totalAttraction); totalAttraction = RemoveWAHFromAttraction(attractions.GetFlatData(), flatWah); StoreProductionData(production); WriteGenerationFile(totalProduction, totalAttraction); WriteAttractionFile(attractions); if (LoadData) { LoadExternalWorkerRates.UnloadData(); LoadWorkAtHomeRates.UnloadData(); LoadExternalJobsRates.UnloadData(); WorkAtHomeRates = null; ExternalRates = null; ExternalJobs = null; } }
private void LoadJobOccupationDistribution() { JobOccupationRates = SparseTriIndex <float> .CreateSimilarArray(Root.ZoneSystem.ZoneArray, EmploymentStatus, OccupationCategories); var occupationIndexes = OccupationCategories.ValidIndexies().ToArray(); using (CommentedCsvReader reader = new CommentedCsvReader(JobOccupationRateFile.GetFileName(Root.InputBaseDirectory))) { while (reader.NextLine()) { if (reader.NumberOfCurrentCells >= 5) { reader.Get(out int pd, 0); reader.Get(out int employmentStatus, 1); reader.Get(out float professional, 2); reader.Get(out float general, 3); reader.Get(out float sales, 4); reader.Get(out float manufacturing, 5); foreach (var zone in PDZoneMap[pd]) { JobOccupationRates[zone, employmentStatus, occupationIndexes[0]] = 0; JobOccupationRates[zone, employmentStatus, occupationIndexes[1]] = professional; JobOccupationRates[zone, employmentStatus, occupationIndexes[2]] = general; JobOccupationRates[zone, employmentStatus, occupationIndexes[3]] = sales; JobOccupationRates[zone, employmentStatus, occupationIndexes[4]] = manufacturing; } } } } }
private void LoadWorkerCarDistribution() { this.WorkerVehicleRates = this.Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTriIndex <float> >(); SparseArray <float> NumberOfVehicles = new SparseArray <float>(new SparseIndexing() { Indexes = new SparseSet[] { new SparseSet() { Start = 0, Stop = 2 } } }); SparseArray <float> DriversLicense = new SparseArray <float>(new SparseIndexing() { Indexes = new SparseSet[] { new SparseSet() { Start = 0, Stop = 1 } } }); if (!this.WorkerVehicleRateFile.ContainsFileName()) { return; } using (CommentedCsvReader reader = new CommentedCsvReader(this.WorkerVehicleRateFile.GetFileName(Root.InputBaseDirectory))) { int pd; int driversLic; int occ; float chanceZero; float chanceOne; float chanceTwo; while (reader.NextLine()) { if (reader.NumberOfCurrentCells >= 6) //Only read if the number of columns in the row matches. { reader.Get(out pd, 0); reader.Get(out driversLic, 1); reader.Get(out occ, 2); reader.Get(out chanceZero, 3); reader.Get(out chanceOne, 4); reader.Get(out chanceTwo, 5); foreach (var zone in this.PDZoneMap[pd]) { var zoneData = this.WorkerVehicleRates[zone]; if (zoneData == null) { zoneData = SparseTriIndex <float> .CreateSimilarArray(DriversLicense, this.OccupationCategories, NumberOfVehicles); this.WorkerVehicleRates[zone] = zoneData; } zoneData[driversLic, occ, 0] = chanceZero; zoneData[driversLic, occ, 1] = chanceOne; zoneData[driversLic, occ, 2] = chanceTwo; } } } } }
public void UnloadData() { Loaded = false; if (!KeepLocalData) { Data = null; } }
private void LoadData() { this.LoadDailyRates.LoadData(); this.LoadTimeOfDayRates.LoadData(); this.DailyRates = this.LoadDailyRates.GiveData(); this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData(); this.LoadDailyRates.UnloadData(); this.LoadTimeOfDayRates.UnloadData(); }
private void LoadData() { LoadDailyRates.LoadData(); LoadTimeOfDayRates.LoadData(); DailyRates = LoadDailyRates.GiveData(); TimeOfDayRates = LoadTimeOfDayRates.GiveData(); LoadDailyRates.UnloadData(); LoadTimeOfDayRates.UnloadData(); }
private void Save(SparseTriIndex <float> data) { var layerIndex = data.ValidIndexes().ToArray(); System.Threading.Tasks.Parallel.For(0, layerIndex.Length, (int i) => { Save(layerIndex[i], data.GetFlatData()[i], data); }); }
private float ApplyMobilityProbability(int mobility, int emp, int occ, SparseTriIndex <float> ncars, int age, SparseTwinIndex <float> dlicRate) { // make sure the age is greater than 0 age = (age == 0 ? 1 : age); // now we have slightly different forms depending if the person is a worker or not if (emp == 0) { return(UnemployedMobilityProbability(mobility, ncars, age, dlicRate)); } return(EmployedMobilityProbability(mobility, emp, occ, ncars, age, dlicRate)); }
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()); }
private void LoadWorkerCarDistribution() { WorkerVehicleRates = Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTriIndex <float> >(); SparseArray <float> numberOfVehicles = new SparseArray <float>(new SparseIndexing { Indexes = new[] { new SparseSet { Start = 0, Stop = 2 } } }); SparseArray <float> driversLicense = new SparseArray <float>(new SparseIndexing { Indexes = new[] { new SparseSet { Start = 0, Stop = 1 } } }); using (CsvReader reader = new CsvReader(GetFullPath(WorkerVehicleRateFile))) { if (WorkerVehicleRateFileHeader) { reader.LoadLine(); } while (!reader.EndOfFile) { var length = reader.LoadLine(); if (length >= 6) { reader.Get(out int pd, 0); reader.Get(out int driversLic, 1); reader.Get(out int occ, 2); reader.Get(out float chanceZero, 3); reader.Get(out float chanceOne, 4); reader.Get(out float chanceTwo, 5); if (PdZoneMap.TryGetValue(pd, out List <int> zones)) { foreach (var zone in zones) { var zoneData = WorkerVehicleRates[zone]; if (zoneData == null) { zoneData = SparseTriIndex <float> .CreateSimilarArray(driversLicense, OccupationCategories, numberOfVehicles); WorkerVehicleRates[zone] = zoneData; } zoneData[driversLic, occ, 0] = chanceZero; zoneData[driversLic, occ, 1] = chanceOne; zoneData[driversLic, occ, 2] = chanceTwo; } } } } } }
private void LoadData() { LoadWorkAtHomeRates.LoadData(); LoadExternalWorkerRates.LoadData(); LoadExternalJobsRates.LoadData(); WorkExternal = LoadExternalWorkerRates.GiveData(); WorkAtHomeRates = LoadWorkAtHomeRates.GiveData(); ExternalJobs = LoadExternalJobsRates.GiveData(); LoadWorkAtHomeRates.UnloadData(); LoadExternalWorkerRates.UnloadData(); LoadExternalJobsRates.UnloadData(); }
private void LoadData() { this.LoadWorkAtHomeRates.LoadData(); this.LoadExternalWorkerRates.LoadData(); this.LoadExternalJobsRates.LoadData(); this.WorkExternal = this.LoadExternalWorkerRates.GiveData(); this.WorkAtHomeRates = this.LoadWorkAtHomeRates.GiveData(); this.ExternalJobs = this.LoadExternalJobsRates.GiveData(); this.LoadWorkAtHomeRates.UnloadData(); this.LoadExternalWorkerRates.UnloadData(); this.LoadExternalJobsRates.UnloadData(); }
private void LoadNonWorkerCarDistribution() { NonWorkerVehicleRates = Root.ZoneSystem.ZoneArray.CreateSimilarArray <SparseTriIndex <float> >(); SparseArray <float> numberOfVehicles = new SparseArray <float>(new SparseIndexing { Indexes = new[] { new SparseSet { Start = 0, Stop = 2 } } }); SparseArray <float> driversLicense = new SparseArray <float>(new SparseIndexing { Indexes = new[] { new SparseSet { Start = 0, Stop = 1 } } }); if (!NonWorkerVehicleRateFile.ContainsFileName()) { return; } using (CommentedCsvReader reader = new CommentedCsvReader(NonWorkerVehicleRateFile.GetFileName(Root.InputBaseDirectory))) { while (reader.NextLine()) { if (reader.NumberOfCurrentCells >= 6) { reader.Get(out int pd, 0); reader.Get(out int driversLic, 1); reader.Get(out int ageCat, 2); reader.Get(out float chanceZero, 3); reader.Get(out float chanceOne, 4); reader.Get(out float chanceTwo, 5); foreach (var zone in PDZoneMap[pd]) { var zoneData = NonWorkerVehicleRates[zone]; if (zoneData == null) { zoneData = SparseTriIndex <float> .CreateSimilarArray(driversLicense, AgeCategories, numberOfVehicles); NonWorkerVehicleRates[zone] = zoneData; } zoneData[driversLic, ageCat, 0] = chanceZero; zoneData[driversLic, ageCat, 1] = chanceOne; zoneData[driversLic, ageCat, 2] = chanceTwo; } } } } }
public void LoadData() { float[][][] data = new float[TwinSources.Length][][]; SparseIndexing indicies = RootCreateIndices(); for (int i = 0; i < TwinSources.Length; i++) { TwinSources[i].LoadData(); var innerData = TwinSources[i].GiveData(); CreateIndices(indicies, i, innerData); data[i] = innerData.GetFlatData(); TwinSources[i].UnloadData(); } Data = new SparseTriIndex <float>(indicies, data); Loaded = true; }
public void Load() { ZoneSystem = Root.ZoneSystem.ZoneArray; Zones = ZoneSystem.GetFlatData(); if (SaveWorkerCategory != null) { WorkerResults = new float[3][]; for (int i = 0; i < WorkerResults.Length; i++) { WorkerResults[i] = new float[Zones.Length]; } } Probabilities = Linkages.AquireResource <SparseTriIndex <float> >(); ConvertToProbabilities(Probabilities.GetFlatData()); Linkages.ReleaseResource(); }
private void LoadJobOccupationDistribution() { JobOccupationRates = SparseTriIndex <float> .CreateSimilarArray(Root.ZoneSystem.ZoneArray, EmploymentStatus, OccupationCategories); var employmentIndexes = EmploymentStatus.ValidIndexies().ToArray(); var occupationIndexes = OccupationCategories.ValidIndexies().ToArray(); using (CsvReader reader = new CsvReader(GetFullPath(JobOccupationRateFile))) { int pd; int employmentStatus; float professional; float general; float sales; float manufacturing; if (JobOccupationRateFileHeader) { reader.LoadLine(); } while (!reader.EndOfFile) { var length = reader.LoadLine(); if (length >= 5) { reader.Get(out pd, 0); reader.Get(out employmentStatus, 1); reader.Get(out professional, 2); reader.Get(out general, 3); reader.Get(out sales, 4); reader.Get(out manufacturing, 5); List <int> zones; if (PDZoneMap.TryGetValue(pd, out zones)) { foreach (var zone in zones) { this.JobOccupationRates[zone, employmentStatus, occupationIndexes[0]] = 0; this.JobOccupationRates[zone, employmentStatus, occupationIndexes[1]] = professional; this.JobOccupationRates[zone, employmentStatus, occupationIndexes[2]] = general; this.JobOccupationRates[zone, employmentStatus, occupationIndexes[3]] = sales; this.JobOccupationRates[zone, employmentStatus, occupationIndexes[4]] = manufacturing; } } } } } }
public void Load() { _zoneSystem = Root.ZoneSystem.ZoneArray; _planningDistricts = ZoneSystemHelper.CreatePdArray <float>(_zoneSystem); Zones = _zoneSystem.GetFlatData(); if (SaveWorkerCategory != null) { WorkerResults = new float[3][]; for (int i = 0; i < WorkerResults.Length; i++) { WorkerResults[i] = new float[Zones.Length]; } } _linkages = Linkages.AcquireResource <SparseTriIndex <float> >(); CopyLinkages(_linkages); SaveLinkagesToFile(_linkages.GetFlatData()); Linkages.ReleaseResource(); }
public override void Generate(SparseArray <float> production, SparseArray <float> attractions) { if (LoadData && Rates == null) { LoadRates.LoadData(); Rates = LoadRates.GiveData(); } InitializeDemographicCategory(); var flatProduction = production.GetFlatData(); var numberOfIndexes = flatProduction.Length; // Compute the Production SaveGenerationData(ComputeProduction(flatProduction, numberOfIndexes)); //The HBO Model does NOT include having an attraction component. The distribution will handle this case. if (LoadData) { Rates = null; } }
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; }
public void LoadData() { float[][][] data = new float[TwinSources.Length][][]; SparseIndexing indicies = RootCreateIndices(); for (int i = 0; i < TwinSources.Length; i++) { TwinSources[i].LoadData(); var innerData = TwinSources[i].GiveData(); CreateIndices(indicies, i, innerData); var inner = innerData.GetFlatData(); if (CreateCopy) { inner = inner.Select(i2 => i2.Clone() as float[]).ToArray(); } data[i] = inner; TwinSources[i].UnloadData(); } Data = new SparseTriIndex <float>(indicies, data); Loaded = true; }
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]]}"); } } }
public override void Generate(SparseArray<float> production, SparseArray<float> attractions) { if ( LoadData && Rates == null ) { this.LoadRates.LoadData(); this.Rates = this.LoadRates.GiveData(); } this.InitializeDemographicCategory(); var flatProduction = production.GetFlatData(); var numberOfIndexes = flatProduction.Length; // Compute the Production float totalProduction = 0; totalProduction = ComputeProduction( flatProduction, numberOfIndexes ); SaveGenerationData( totalProduction ); //The HBO Model does NOT include having an attraction component. The distribution will handle this case. if ( LoadData ) { this.Rates = null; } }
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]])); } } }
private static float EmployedMobilityProbability(int mobility, int emp, int occ, SparseTriIndex<float> ncars, int age, SparseTwinIndex<float> dlicRate) { switch ( mobility ) { case 0: return ( 1 - dlicRate[age, emp] ) * ncars[0, occ, 0]; case 1: return ( 1 - dlicRate[age, emp] ) * ncars[0, occ, 1]; case 2: return ( 1 - dlicRate[age, emp] ) * ncars[0, occ, 2]; case 3: return ( dlicRate[age, emp] * ncars[1, occ, 0] ); case 4: return dlicRate[age, emp] * ncars[1, occ, 1]; case 5: return dlicRate[age, emp] * ncars[1, occ, 2]; default: throw new XTMFRuntimeException( "Unknown mobility type '" + mobility.ToString() + "'!" ); } }
private void LoadData() { this.LoadWorkAtHomeRates.LoadData(); this.LoadExternalWorkerRates.LoadData(); this.LoadExternalJobsRates.LoadData(); this.WorkExternal = this.LoadExternalWorkerRates.GiveData(); this.WorkAtHomeRates = this.LoadWorkAtHomeRates.GiveData(); this.ExternalJobs = this.LoadExternalJobsRates.GiveData(); this.LoadWorkAtHomeRates.UnloadData(); this.LoadExternalWorkerRates.UnloadData(); this.LoadExternalJobsRates.UnloadData(); }
private float ApplyMobilityProbability(int emp, int occ, SparseTriIndex<float> ncars, int age, SparseTwinIndex<float> dlicRate) { switch(Mobility[0].Start) { case 0: return (1 - dlicRate[age, emp]) * ncars[0, occ, 0]; case 1: return (1 - dlicRate[age, emp]) * ncars[0, occ, 1]; case 2: return (1 - dlicRate[age, emp]) * ncars[0, occ, 2]; case 3: return dlicRate[age, emp] * ncars[1, occ, 0]; case 4: return dlicRate[age, emp] * ncars[1, occ, 1]; case 5: return dlicRate[age, emp] * ncars[1, occ, 2]; } return 0; }
private void ProcessEI(SparseTriIndex<float> distribution, SparseArray<float> population) { var indexes = population.ValidIndexArray(); Parallel.For( 0, indexes.Length, delegate(int i) { var zones = this.Root.ZoneSystem.ZoneArray; var zoneNumber = indexes[i]; var originPopulation = population[zoneNumber]; var originZone = zones[zoneNumber]; var factor = originPopulation / originZone.Population; if ( originPopulation <= 0 | originZone.RegionNumber > 0 | float.IsInfinity( factor ) ) { return; } var originIndex = zones.GetFlatIndex( zoneNumber ); // The factor to apply to the distribution to map it to the results var numberOfZones = zones.GetFlatData().Length; foreach ( var destination in distribution.ValidIndexes( zoneNumber ) ) { var destinationIndex = zones.GetFlatIndex( destination ); // do not process EE trips if ( zones[destination].RegionNumber == 0 ) { continue; } foreach ( var mode in distribution.ValidIndexes( zoneNumber, destination ) ) { var ammount = distribution[zoneNumber, destination, mode] * factor; AddData( mode, originIndex, destinationIndex, ammount, numberOfZones ); } } } ); }
private float GenerateForWorkingStudent(IZone[] zones, int zoneIndex, SparseTwinIndex<float> ageRates, SparseTwinIndex<float> empRates, SparseTriIndex<float> occRates, SparseTwinIndex<float> dlicRate, SparseTriIndex<float> ncars, int age, float ppGenerationRate, int emp, float studentFactor) { float temp = 0; var ageEmpRate = ageRates[zones[zoneIndex].ZoneNumber, age] * empRates[age, emp] * studentFactor; foreach ( var occSet in this.OccupationCategory ) { for ( int occ = occSet.Start; occ <= occSet.Stop; occ++ ) { var nonMobilityRate = ageEmpRate * occRates[age, emp, occ]; foreach ( var mobilitySet in this.Mobility ) { for ( int mob = mobilitySet.Start; mob <= mobilitySet.Stop; mob++ ) { // calculate the probability of a person of this type for this zone var catFactor = nonMobilityRate * ApplyMobilityProbability( mob, emp, occ, ncars, age, dlicRate ); // now apply that to temp += zones[zoneIndex].Population * catFactor * ppGenerationRate; } } } } return temp; }
private void ProcessExternalModel(SparseTriIndex<float> distribution, SparseArray<float> population, SparseArray<float> employment) { ProcessEI( distribution, population ); ProcessIE( distribution, employment ); ProcessEE( distribution, population, employment ); }
private void ProcessIE(SparseTriIndex<float> distribution, SparseArray<float> employment) { var indexes = employment.ValidIndexArray(); Parallel.For( 0, indexes.Length, delegate(int i) { var zones = this.Root.ZoneSystem.ZoneArray; var destination = indexes[i]; var destinationEmployment = employment[destination]; var destinationZone = zones[destination]; var factor = destinationEmployment / destinationZone.Employment; if ( destinationEmployment <= 0 | destinationZone.RegionNumber > 0 | float.IsInfinity( factor ) ) { return; } var destinationIndex = zones.GetFlatIndex( destination ); // The factor to apply to the distribution to map it to the results var numberOfZones = zones.GetFlatData().Length; foreach ( var origin in distribution.ValidIndexes() ) { var originIndex = zones.GetFlatIndex( origin ); // do not process EE trips if ( zones[origin].RegionNumber == 0 ) { continue; } foreach ( var mode in distribution.ValidIndexes( origin, destination ) ) { var ammount = distribution[origin, destination, mode] * factor; if ( ammount <= 0 ) { continue; } AddData( mode, originIndex, destinationIndex, ammount, numberOfZones ); } } } ); }
private void LoadData() { this.LoadDailyRates.LoadData(); this.LoadTimeOfDayRates.LoadData(); this.DailyRates = this.LoadDailyRates.GiveData(); this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData(); this.LoadDailyRates.UnloadData(); this.LoadTimeOfDayRates.UnloadData(); }
private void LoadData() { this.LoadRates.LoadData(); this.Rates = this.LoadRates.GiveData(); this.LoadRates.UnloadData(); }
private float ApplyMobilityProbability(int mobility, int emp, int occ, SparseTriIndex<float> ncars, int age, SparseTwinIndex<float> dlicRate) { // make sure the age is greater than 0 age = ( age == 0 ? 1 : age ); // now we have slightly different forms depending if the person is a worker or not if ( emp == 0 ) { return UnemployedMobilityProbability( mobility, ncars, age, dlicRate ); } else { return EmployedMobilityProbability( mobility, emp, occ, ncars, age, dlicRate ); } }