当前位置: 首页>>代码示例>>C#>>正文


C# SparseArray.GetFlatIndex方法代码示例

本文整理汇总了C#中SparseArray.GetFlatIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SparseArray.GetFlatIndex方法的具体用法?C# SparseArray.GetFlatIndex怎么用?C# SparseArray.GetFlatIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SparseArray的用法示例。


在下文中一共展示了SparseArray.GetFlatIndex方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadData

 private void LoadData(float[] data, IReadODData<float> readODData, int dataTypeOffset, SparseArray<IZone> zoneArray, int timesLoaded)
 {
     if(readODData == null)
     {
         return;
     }
     var zones = zoneArray.GetFlatData();
     var numberOfZones = zones.Length;
     var dataTypes = (int)DataTypes.NumberOfDataTypes;
     int previousPointO = -1;
     int previousFlatO = -1;
     if(timesLoaded == 0)
     {
         foreach(var point in readODData.Read())
         {
             var o = point.O == previousPointO ? previousFlatO : zoneArray.GetFlatIndex(point.O);
             var d = zoneArray.GetFlatIndex(point.D);
             if(o >= 0 & d >= 0)
             {
                 previousPointO = point.O;
                 previousFlatO = o;
                 var index = (o * numberOfZones + d) * dataTypes + dataTypeOffset;
                 data[index] = point.Data;
             }
         }
     }
     else
     {
         var iteration = timesLoaded + 1;
         var previousFraction = 1.0f / (iteration + 1.0f);
         var currentFraction = iteration / (1.0f + iteration);
         foreach(var point in readODData.Read())
         {
             var o = point.O == previousPointO ? previousFlatO : zoneArray.GetFlatIndex(point.O);
             var d = zoneArray.GetFlatIndex(point.D);
             if(o >= 0 & d >= 0)
             {
                 previousPointO = point.O;
                 previousFlatO = o;
                 var index = (o * numberOfZones + d) * dataTypes + dataTypeOffset;
                 data[index] = data[index] * previousFraction + point.Data * currentFraction;
             }
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:45,代码来源:V4AutoNetwork.cs

示例2: LoadProbabilities

 /// <summary>
 /// Load the probabilities from file
 /// </summary>
 /// <param name="zoneSystem">The zone system the model is using</param>
 private void LoadProbabilities(SparseArray<IZone> zoneSystem)
 {
     var zones = zoneSystem.GetFlatData();
     AutoProbabilities = new float[zones.Length];
     TransitProbabilities = new float[zones.Length];
     TotalTrips = new float[zones.Length];
     using (CsvReader reader = new CsvReader(ModeSplitTruthData))
     {
         // burn header
         reader.LoadLine();
         // read in the rest of the data
         int columns;
         while(reader.LoadLine(out columns))
         {
             if(columns >= 3)
             {
                 int zone;
                 reader.Get(out zone, 0);
                 zone = zoneSystem.GetFlatIndex(zone);
                 if(zone >= 0)
                 {
                     float auto, transit, totalTrips;
                     reader.Get(out auto, 1);
                     reader.Get(out transit, 2);
                     reader.Get(out totalTrips, 3);
                     AutoProbabilities[zone] = auto;
                     TransitProbabilities[zone] = transit;
                     TotalTrips[zone] = totalTrips;
                 }
             }
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:37,代码来源:AiportModeSplitFitnessFunction.cs

示例3: ComputeLineHaull

 private void ComputeLineHaull(float[][] currentTally, SparseArray<IZone> zoneArray, IZone[] zones, int m, float[][] data)
 {
     // this can't be in parallel since we are writing to the some access and egress data entries
     for(int i = 0; i < data.Length; i++)
     {
         if(data[i] == null) continue;
         for(int j = 0; j < data[i].Length; j++)
         {
             var totalTrips = data[i][j];
             if(totalTrips <= 0f)
             {
                 continue;
             }
             var choices = GetStationChoiceSplit(m, zones[i], zones[j]);
             if(choices == null)
             {
                 continue;
             }
             var accessStations = choices.Item1;
             var egressStations = choices.Item2;
             if(egressStations == null)
             {
                 continue;
             }
             var splits = choices.Item3;
             var totalSplits = 0f;
             for(int z = 0; z < accessStations.Length; z++)
             {
                 if(accessStations[z] != null)
                 {
                     totalSplits += splits[z];
                 }
             }
             for(int z = 0; z < accessStations.Length; z++)
             {
                 if(accessStations[z] == null | egressStations[z] == null) break;
                 var accessZoneNumber = zoneArray.GetFlatIndex(accessStations[z].ZoneNumber);
                 var egressZoneNumber = zoneArray.GetFlatIndex(egressStations[z].ZoneNumber);
                 // no lock needed since we are doing it parallel in the i, so there will be no conflicts
                 currentTally[accessZoneNumber][egressZoneNumber] += totalTrips * (splits[z] / totalSplits);
             }
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:44,代码来源:StationAccessTally.cs

示例4: ComputeFromDestination

 private void ComputeFromDestination(float[][] currentTally, SparseArray<IZone> zoneArray, IZone[] zones, int m, float[][] data)
 {
     Parallel.For(0, data.Length, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
         delegate (int j)
     {
         for(int i = 0; i < data.Length; i++)
         {
             if(data[i] == null || data[i][j] <= 0f) continue;
             var choices = GetStationChoiceSplit(m, zones[i], zones[j]);
             if(choices == null) continue;
             // check for egress stations first
             var stationZones = choices.Item2;
             if(stationZones == null)
             {
                 // if there are no egress stations, use the access stations
                 stationZones = choices.Item1;
             }
             var splits = choices.Item3;
             var totalTrips = data[i][j];
             var totalSplits = 0f;
             for(int z = 0; z < stationZones.Length; z++)
             {
                 if(stationZones[z] != null)
                 {
                     totalSplits += splits[z];
                 }
             }
             for(int z = 0; z < stationZones.Length; z++)
             {
                 if(stationZones[z] == null) break;
                 var flatZoneNumber = zoneArray.GetFlatIndex(stationZones[z].ZoneNumber);
                 if(currentTally[flatZoneNumber] == null)
                 {
                     lock (data)
                     {
                         System.Threading.Thread.MemoryBarrier();
                         if(currentTally[flatZoneNumber] == null)
                         {
                             currentTally[flatZoneNumber] = new float[data[i].Length];
                         }
                     }
                 }
                 // no lock needed since we are doing it parallel in the i, so there will be no conflicts
                 currentTally[flatZoneNumber][j] += totalTrips * (splits[z] / totalSplits);
             }
         }
     });
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:48,代码来源:StationAccessTally.cs

示例5: BuildData

 private float[][][] BuildData(string[] modeNames, SparseArray<IZone> zoneSystem, SparseArray<int> regions)
 {
     var zones = zoneSystem.GetFlatData();
     var modes = Root.AllModes.ToArray();
     var data = new float[modes.Length][][];
     var numberOfRegions = regions.GetFlatData().Length;
     for(int i = 0; i < data.Length; i++)
     {
         var row = data[i] = new float[numberOfRegions][];
         for(int j = 0; j < row.Length; j++)
         {
             row[j] = new float[numberOfRegions];
         }
     }
     using (CsvReader reader = new CsvReader(ZonalModeSplitFile))
     {
         // burn header
         reader.LoadLine();
         int columns;
         while(reader.LoadLine(out columns))
         {
             // ignore lines without the right number of columns
             if(columns == 4)
             {
                 string modeName;
                 int originZone, destinationZone;
                 float expandedPersons;
                 reader.Get(out modeName, 0);
                 reader.Get(out originZone, 1);
                 reader.Get(out destinationZone, 2);
                 reader.Get(out expandedPersons, 3);
                 data[ModeIndex(modeName, modeNames)][regions.GetFlatIndex(zoneSystem[originZone].PlanningDistrict)][regions.GetFlatIndex(zoneSystem[destinationZone].PlanningDistrict)]
                     += expandedPersons;
             }
         }
     }
     return data;
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:38,代码来源:ConvertZonalModeSplitToPDModeSplit.cs

示例6: ComputeFromOrigin

 private void ComputeFromOrigin(float[][] currentTally, SparseArray<IZone> zoneArray, IZone[] zones, int m, float[][] data)
 {
     Parallel.For(0, data.Length, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
         delegate (int i)
     {
         if(data[i] == null) return;
         var tallyRow = currentTally[i];
         for(int j = 0; j < data[i].Length; j++)
         {
             var totalTrips = data[i][j];
             if(totalTrips <= 0f) continue;
             var choices = GetStationChoiceSplit(m, zones[i], zones[j]);
             if(choices == null) continue;
             var stationZones = choices.Item1;
             var splits = choices.Item3;
             var totalSplits = 0f;
             for(int z = 0; z < stationZones.Length; z++)
             {
                 if(stationZones[z] != null)
                 {
                     totalSplits += splits[z];
                 }
             }
             for(int z = 0; z < stationZones.Length; z++)
             {
                 if(stationZones[z] == null) break;
                 var flatZoneNumber = zoneArray.GetFlatIndex(stationZones[z].ZoneNumber);
                 // no lock needed since we are doing it parallel in the i, so there will be no conflicts
                 tallyRow[flatZoneNumber] += totalTrips * (splits[z] / totalSplits);
             }
         }
     });
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:33,代码来源:StationAccessTally.cs

示例7: FillInPopulationByZone

 private void FillInPopulationByZone(SparseArray<IZone> zones, int numberOfZones, IDbCommand command, float[][][] populationByAge)
 {
     for ( int j = 0; j < this.AgeSets.Count; j++ )
     {
         populationByAge[j] = new float[this.EmploymentStatusString.Length][];
         for ( int i = 0; i < this.EmploymentStatusString.Length; i++ )
         {
             populationByAge[j][i] = new float[numberOfZones];
             command.CommandText =
             String.Format( @"SELECT [{3}].[{0}], SUM([{2}].[{1}])
     FROM [{2}] INNER JOIN [{3}] ON
     [{2}].[{4}] = [{3}].[{4}] AND [{2}].[{5}] = [{3}].[{5}]
     WHERE [{2}].[{5}] = {6} AND [{3}].[{7}] = {8} AND [{2}].[{9}] >= {10} AND [{2}].[{9}] <= {11}
     AND [{2}].[{13}] = '{12}'
     GROUP BY [{3}].[{0}];",
                 //0
                     ZoneNumberColumn,
                 //1
                     ExpansionFactorColumnName,
                 //2
                     PersonsTable,
                 //3
                     HomeZoneTableName,
                 //4
                     HouseholdIDColumn,
                 //5
                     TTSYearColumn,
                 //6
                     TTSYear,
                 //7
                     ZoneSystemColumn,
                 //8
                     ZoneSystemNumber,
                 //9
                     AgeColumn,
                 //10
                     this.AgeSets[j].Start,
                 //11
                     this.AgeSets[j].Stop,
                 //12
                     EmploymentStatusString[i],
                 //13
                     EmploymentStatusColumn );
             using ( var reader = command.ExecuteReader() )
             {
                 while ( reader.Read() )
                 {
                     var zone = reader.GetInt32( 0 );
                     var index = zones.GetFlatIndex( zone );
                     if ( index >= 0 )
                     {
                         populationByAge[j][i][index] = (float)reader.GetDouble( 1 );
                     }
                 }
             }
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:58,代码来源:GatherEmploymentByAgeByPD.cs

示例8: WriteData

 /// <summary>
 /// Save the data from the given split data to the given file as CSV.
 /// EmpStat,
 /// </summary>
 /// <param name="writer">The stream to write to.</param>
 /// <param name="splitData">The data to use</param>
 /// <param name="empCode">The empStat code to dump</param>
 private void WriteData(StreamWriter writer, SparseArray<float[]> splitData, char empCode)
 {
     var data = splitData.GetFlatData();
     for ( int i = 0; i < data.Length; i++ )
     {
         var row = splitData[i];
         if ( row != null )
         {
             // buffer as much of the header ahead of time to help performance
             var pdStr = string.Concat( empCode, ",", splitData.GetFlatIndex( i ), "," );
             for ( int j = 0; j < row.Length; j++ )
             {
                 writer.Write( pdStr );
                 writer.Write( j + 1 );
                 writer.Write( ',' );
                 writer.WriteLine( row[j] );
             }
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:27,代码来源:GatherOccupationByEmpStatByPD.cs

示例9: CreateStationIndexLookup

 private int[] CreateStationIndexLookup(SparseArray<IZone> zoneSystem, IZone[] zones)
 {
     var lookup = zones.Select(z => zoneSystem.GetFlatIndex(z.ZoneNumber)).ToArray();
     StationIndexLookup = lookup;
     return lookup;
 }
开发者ID:dianatle,项目名称:XTMF,代码行数:6,代码来源:DriveAccessTransit.cs

示例10: ExtractPopulation

 private float[] ExtractPopulation(IDbCommand command, SparseArray<IZone> zones)
 {
     float[] populationInZone = new float[zones.GetFlatData().Length];
     //Build SQL request
     command.CommandText =
         String.Format( @"SELECT [{3}].[{0}], SUM([{2}].[{1}])
     FROM [{2}] INNER JOIN [{3}] ON
     [{2}].[{4}] = [{3}].[{4}] AND [{2}].[{5}] = [{3}].[{5}]
     WHERE [{2}].[{5}] = {6} AND [{3}].[{7}] = {8}
     GROUP BY [{3}].[{0}];",
         //0
                 ZoneNumberColumn,
         //1
                 ExpansionFactorColumnName,
         //2
                 PersonsTable,
         //3
                 HomeZoneTableName,
         //4
                 HouseholdIDColumn,
         //5
                 TTSYearColumn,
         //6
                 TTSYear,
         //7
                 ZoneSystemColumn,
         //8
                 ZoneSystemNumber );
     // process data
     using ( var reader = command.ExecuteReader() )
     {
         while ( reader.Read() )
         {
             // if the zone is in our zone system add them to it
             var zoneNumber = reader.GetInt32( 0 );
             var index = zones.GetFlatIndex( zoneNumber );
             if ( index >= 0 )
             {
                 populationInZone[index] = (float)reader.GetDouble( 1 );
             }
         }
     }
     return populationInZone;
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:44,代码来源:GatherPopulationByZone.cs

示例11: LoadProbabilities

 private void LoadProbabilities(SparseArray<IZone> zoneSystem)
 {
     var zones = zoneSystem.GetFlatData();
     ObservedDistribution = new float[zones.Length];
     TotalTrips = new float[zones.Length];
     using (CsvReader reader = new CsvReader(ObservedDistributionFile))
     {
         // burn header
         reader.LoadLine();
         // read in the rest of the data
         int columns;
         while(reader.LoadLine(out columns))
         {
             if(columns >= 2)
             {
                 int zone;
                 reader.Get(out zone, 0);
                 zone = zoneSystem.GetFlatIndex(zone);
                 if(zone >= 0)
                 {
                     float probability, totalTrips;
                     reader.Get(out probability, 1);
                     reader.Get(out totalTrips, 2);
                     ObservedDistribution[zone] = probability;
                     TotalTrips[zone] = totalTrips;
                 }
             }
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:30,代码来源:AirportDistributionFitnessFunction.cs


注:本文中的SparseArray.GetFlatIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。