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 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 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); } } }); }
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 void ProcessInternalToExternal(SparseTriIndex <float> distribution, SparseArray <float> employment) { var indexes = employment.ValidIndexArray(); Parallel.For(0, indexes.Length, delegate(int i) { var zones = 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 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 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 ); } } } ); }