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


C# SparseArray.GetFlatData方法代码示例

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


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

示例1: Generate

        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;
            }
        }
开发者ID:dianatle,项目名称:XTMF,代码行数:31,代码来源:PoRPoWGeneration.cs

示例2: EmmeMatrix

 public EmmeMatrix(SparseArray<IZone> zoneSystem, float[][] data)
 {
     var zones = zoneSystem.GetFlatData();
     MagicNumber = EmmeMagicNumber;
     Version = 1;
     Type = DataType.Float;
     Dimensions = 2;
     float[] temp = new float[zones.Length * zones.Length];
     Indexes = new int[2][];
     for(int i = 0; i < Indexes.Length; i++)
     {
         var row = Indexes[i] = new int[zones.Length];
         for(int j = 0; j < row.Length; j++)
         {
             row[j] = zones[j].ZoneNumber;
         }
     }
     for(int i = 0; i < data.Length; i++)
     {
         Array.Copy(data[i], 0, temp, i * zones.Length, zones.Length);
     }
     FloatData = temp;
     DoubleData = null;
     SignedIntData = null;
     UnsignedIntData = null;
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:26,代码来源:EmmeMatrix.cs

示例3: Generate

        public void Generate(SparseArray<float> production, SparseArray<float> attractions)
        {
            var ages = this.Root.Demographics.AgeRates;
            var studentRates = this.Root.Demographics.SchoolRates.GetFlatData();
            var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
            var prod = production.GetFlatData();

            for ( int i = 0; i < zones.Length; i++ )
            {
                // this is only null for externals
                var studentRatesForZone = studentRates[i];
                if ( studentRatesForZone == null )
                {
                    // if it is an external ignore
                    prod[i] = 0f;
                }
                else
                {
                    // otherwise compute the production
                    var pd = zones[i].PlanningDistrict;
                    prod[i] = zones[i].Population * ages[zones[i].ZoneNumber, this.Age] * studentRatesForZone[this.Age, 0] *
                        StudentDailyRates[pd, 0, this.Age] * StudentTimeOfDayRates[pd, 0, this.Age];
                }
            }

            SaveProductionToDisk( zones, prod );
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:27,代码来源:SchoolGeneration.cs

示例4: Generate

        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;
            }
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:29,代码来源:PoRPoSGeneration.cs

示例5: Generate

        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;
            }
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:32,代码来源:PowGeneration.cs

示例6: Process

        public static SparseTwinIndex<float> Process(SparseArray<float> production, float[] friction)
        {
            var ret = production.CreateSquareTwinArray<float>();
            var flatRet = ret.GetFlatData();
            var flatProduction = production.GetFlatData();
            var numberOfZones = flatProduction.Length;
            try
            {
                // Make all of the frictions to the power of E
                Parallel.For( 0, friction.Length, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
                    delegate(int i)
                    {
                        friction[i] = (float)Math.Exp( friction[i] );
                    } );

                Parallel.For( 0, numberOfZones, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
                    delegate(int i)
                    {
                        float sum = 0f;
                        var iIndex = i * numberOfZones;
                        // gather the sum of the friction
                        for ( int j = 0; j < numberOfZones; j++ )
                        {
                            sum += friction[iIndex + j];
                        }
                        if ( sum <= 0 )
                        {
                            return;
                        }
                        sum = 1f / sum;
                        for ( int j = 0; j < numberOfZones; j++ )
                        {
                            flatRet[i][j] = flatProduction[i] * ( friction[iIndex + j] * sum );
                        }
                    } );
            }
            catch ( AggregateException e )
            {
                if ( e.InnerException is XTMFRuntimeException )
                {
                    throw new XTMFRuntimeException( e.InnerException.Message );
                }
                else
                {
                    throw new XTMFRuntimeException( e.InnerException.Message + "\r\n" + e.InnerException.StackTrace );
                }
            }
            return ret;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:49,代码来源:SinglyConstrainedGravityModel.cs

示例7: Generate

 public void Generate(SparseArray<float> production, SparseArray<float> attractions)
 {
     var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
     var numberOfzones = zones.Length;
     var flatProduction = production.GetFlatData();
     for ( int i = 0; i < numberOfzones; i++ )
     {
         int regionIndex;
         if ( !this.InverseLookup( zones[i].RegionNumber, out regionIndex ) )
         {
             // if this region is not included just continue
             flatProduction[i] = 0;
             continue;
         }
         flatProduction[i] = zones[i].Population * this.RegionPopulationParameter[regionIndex]
             + zones[i].Employment * this.RegionEmploymentParameter[regionIndex]
             + this.RegionConstantsParameter[regionIndex];
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:19,代码来源:DRMNHBOPMGeneration.cs

示例8: Generate

        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;
            }
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:21,代码来源:HBOGeneration.cs

示例9: Generate

 public override void Generate(SparseArray<float> production, SparseArray<float> attractions)
 {
     // Do nothing, the distribution needs to do it all anyways
     // The only thing this generation needs is the ability to setup the mode choice properly
     var flatProduction = production.GetFlatData();
     var ageRates = this.Root.Demographics.AgeRates;
     var empRates = this.Root.Demographics.EmploymentStatusRates.GetFlatData();
     var occRates = this.Root.Demographics.OccupationRates.GetFlatData();
     var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
     var age = this.AgeCategoryRange[0].Start;
     var occ = this.OccupationCategory[0].Start;
     Parallel.For( 0, flatProduction.Length, (int i) =>
     {
         float total = 0;
         var zoneNumber = zones[i].ZoneNumber;
         var emp = empRates[i];
         var occRate = occRates[i];
         if ( emp == null | occRate == null )
         {
             flatProduction[i] = 0;
         }
         else
         {
             foreach ( var set in this.AllAges )
             {
                 for ( int a = set.Start; a <= set.Stop; a++ )
                 {
                     total += ageRates[zoneNumber, a] * emp[a, 1] * occRate[a, 1, occ];
                 }
             }
             // NOTE, SINCE THE DISTRIBUTION DOES TRIP RATES BASED ON  PDO->PDD WE ONLY NEED TO
             // GIVE THE TOTAL WORKERS FOR THIS GIVEN AGE
             // the rate is not just the age, but the weight of the age for valid workers
             flatProduction[i] = total > 0 ? ( ageRates[zoneNumber, age] * emp[age, 1] * occRate[age, 1, occ] ) / total : 0;
         }
     } );
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:37,代码来源:PowGeneration.cs

示例10: FillRatioIntraZonalTravelTime

 private void FillRatioIntraZonalTravelTime(int districtNumber, IZone[] flatZones, SparseTwinIndex<float> matrix, SparseArray<float> radius)
 {
     var validDistricts = radius.ValidIndexArray();
     var flatRadius = radius.GetFlatData();
     for ( int otherDistrict = 0; otherDistrict < validDistricts.Length; otherDistrict++ )
     {
         var sparseOther = radius.GetSparseIndex( otherDistrict );
         if ( sparseOther == districtNumber ) continue;
         if ( this.AnyTripIntraDistrict( otherDistrict, flatZones, matrix ) )
         {
             var distanceRatio = radius[districtNumber] / flatRadius[otherDistrict];
             var data = matrix.GetFlatData();
             var averageTT = GetAverageIntraDistrictNonIntraZonalTravelTime( sparseOther, flatZones, data );
             var averageIntraZonealTT = GetAverageIntraZonalTravelTime( sparseOther, flatZones, data );
             var zoneRatio = GetNumberOfZonesRatio( flatZones, districtNumber, sparseOther );
             averageTT *= distanceRatio * zoneRatio;
             averageIntraZonealTT *= distanceRatio * zoneRatio;
             for ( int i = 0; i < flatZones.Length; i++ )
             {
                 if ( flatZones[i].PlanningDistrict != districtNumber ) continue;
                 for ( int j = 0; j < flatZones.Length; j++ )
                 {
                     if ( flatZones[j].PlanningDistrict != districtNumber ) continue;
                     if ( i == j )
                     {
                         data[i][j] = averageIntraZonealTT;
                     }
                     else
                     {
                         data[i][j] = averageTT;
                     }
                 }
             }
             break;
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:37,代码来源:BuildTripMatrix.cs

示例11: ProcessFlow

        public SparseTwinIndex<float> ProcessFlow(SparseArray<float> O, SparseArray<float> D, int[] validIndexes, SparseArray<float> attractionStar = null)
        {
            int length = validIndexes.Length;
            Productions = O;
            Attractions = D;
            if(attractionStar == null)
            {
                AttractionsStar = D.CreateSimilarArray<float>();
            }
            else
            {
                AttractionsStar = attractionStar;
            }
            FlowMatrix = Productions.CreateSquareTwinArray<float>();
            if(Friction == null)
            {
                InitializeFriction(length);
            }
            var flatAttractionStar = AttractionsStar.GetFlatData();
            float[] oldTotal = new float[flatAttractionStar.Length];
            var flatAttractions = Attractions.GetFlatData();
            for(int i = 0; i < length; i++)
            {
                flatAttractionStar[i] = 1f;
                oldTotal[i] = flatAttractions[i];
            }
            int iteration = 0;
            float[] columnTotals = new float[length];
            var balanced = false;
            do
            {
                if(ProgressCallback != null)
                {
                    // this doesn't go to 100%, but that is alright since when we end, the progress
                    // of the calling model should assume we hit 100%
                    ProgressCallback(iteration / (float)MaxIterations);
                }
                Array.Clear(columnTotals, 0, columnTotals.Length);
                if(Vector.IsHardwareAccelerated)
                {
                    VectorProcessFlow(columnTotals, FlowMatrix.GetFlatData());
                }
                else
                {
                    ProcessFlow(columnTotals);
                }
                balanced = Balance(columnTotals, oldTotal);
            } while((++iteration) < MaxIterations && !balanced);

            if(ProgressCallback != null)
            {
                ProgressCallback(1f);
            }
            return FlowMatrix;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:55,代码来源:GravityModel.cs

示例12: SaveVector

 public static void SaveVector(SparseArray<float> data, string saveTo)
 {
     var flatData = data.GetFlatData();
     var indexes = data.ValidIndexArray().Select(index => index.ToString()).ToArray();
     using (StreamWriter writer = new StreamWriter(saveTo))
     {
         writer.WriteLine("Zone,Value");
         for (int i = 0; i < flatData.Length; i++)
         {
             writer.Write(indexes[i]);
             writer.Write(',');
             writer.WriteLine(flatData[i]);
         }
     }
 }
开发者ID:dianatle,项目名称:XTMF,代码行数:15,代码来源:SaveData.cs

示例13: LoadCapacityFactors

 private void LoadCapacityFactors()
 {
     try
     {
         CapacityFactorSource.LoadData();
         CapacityFactor = CapacityFactorSource.GiveData();
         CapacityFactorSource.UnloadData();
     }
     catch
     {
         // if we were unable to load it properly make sure that it is unloaded
         CapacityFactorSource.UnloadData();
         CapacityFactor = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
         var flat = CapacityFactor.GetFlatData();
         for(int i = 0; i < flat.Length; i++)
         {
             flat[i] = 1.0f;
         }
     }
 }
开发者ID:dianatle,项目名称:XTMF,代码行数:20,代码来源:StationAccessChoice.cs

示例14: LoadData

 public void LoadData()
 {
     // setup our zones
     ZoneArray = Root.ZoneSystem.ZoneArray;
     Zones = ZoneArray.GetFlatData();
     if(Data == null || Regenerate)
     {
         var data = Data;
         // now that we have zones we can build our data
         if(data == null)
         {
             data = new float[Zones.Length * Zones.Length * (int)DataTypes.NumberOfDataTypes];
         }
         //now we need to load in each type
         LoadData(data, TravelTimeReader, (int)DataTypes.TravelTime, Data != null & ApplyTimeBlending);
         LoadData(data, CostReader, (int)DataTypes.Cost, false );
         // now store it
         Data = data;
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:20,代码来源:NoCacheSingleTimePeriodNetworkData.cs

示例15: 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


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