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


C# SparseArray类代码示例

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


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

示例1: SparseArraySimpleTest

        public void SparseArraySimpleTest()
        {
            var stringArrayRef = new string[1000];
            var stringArray = new SparseArray<string>(1000);

            var randomGenerator = new RandomGenerator(66707770); // make this deterministic
            for (int idx = 0; idx < 1000; idx++)
            {
                if (randomGenerator.Generate(2.0) > 1)
                { // add data.
                    stringArrayRef[idx] = idx.ToString();
                    stringArray[idx] = idx.ToString();
                }
                else
                {
                    stringArrayRef[idx] = null;
                    stringArray[idx] = null;
                }
            }

            for (int idx = 0; idx < 1000; idx++)
            {
                Assert.AreEqual(stringArrayRef[idx], stringArray[idx]);
            }
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:25,代码来源:SparseArrayTests.cs

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

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

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

        public override void Run()
        {
            var numberOfCategories = this.Categories.Count;
            SparseArray<float>[] O = new SparseArray<float>[numberOfCategories];
            SparseArray<float>[] D = new SparseArray<float>[numberOfCategories];

            Generation = true;
            for ( int i = 0; i < numberOfCategories; i++ )
            {
                O[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
                D[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
                this.Categories[i].Generate( O[i], D[i] );
            }
            Generation = false;

            var modeSplit = this.ModeSplit.ModeSplit( this.Distribution.Distribute( O, D, this.Categories ), this.Categories.Count );
            if ( this.Transpose )
            {
                TransposeMatrix( modeSplit );
            }
            if ( this.SaveOutput )
            {
                if ( !Directory.Exists( this.PurposeName ) )
                {
                    Directory.CreateDirectory( this.PurposeName );
                }
                for ( int i = 0; i < modeSplit.Count; i++ )
                {
                    this.WriteModeSplit( modeSplit[i], this.Root.Modes[i], this.PurposeName );
                }
            }
            this.Flows = modeSplit;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:33,代码来源:DemographicPurpose.cs

示例6: Run

 public override void Run()
 {
     if ( !this.Execute ) return;
     // we actually don't write our mode choice
     var numberOfCategories = this.Categories.Count;
     SparseArray<float>[] O = new SparseArray<float>[numberOfCategories];
     SparseArray<float>[] D = new SparseArray<float>[numberOfCategories];
     for ( int i = 0; i < O.Length; i++ )
     {
         O[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
         D[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
         this.Categories[i].Generate( O[i], D[i] );
     }
     // if we only need to run generation we are done
     if ( this.OnlyDoGeneration ) return;
     // we don't do mode choice
     foreach ( var distributionData in this.Distribution.Distribute( O, D, this.Categories ) )
     {
         var interative = this.ModeSplit as IInteractiveModeSplit;
         if ( interative != null )
         {
             interative.EndInterativeModeSplit();
         }
         if ( !String.IsNullOrWhiteSpace( this.SaveResultFileName ) )
         {
             SaveFriction( distributionData.GetFlatData() );
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:29,代码来源:PoRPoWPurpose.cs

示例7: Generate

 public void Generate(SparseArray<float> production, SparseArray<float> attractions)
 {
     float totalProduction = 0;
     float totalAttraction = 0;
     foreach (var zone in production.ValidIndexies())
     {
         float prod, attr;
         production[zone] = (prod = this.PopulationFactor * production[zone]);
         attractions[zone] = (attr = this.EmploymentFactor * attractions[zone]);
         totalProduction += prod;
         totalAttraction += attr;
     }
     if (totalAttraction <= 0)
     {
         throw new XTMF.XTMFRuntimeException("There is no employment in the zone system!");
     }
     else if (totalProduction <= 0)
     {
         throw new XTMF.XTMFRuntimeException("There is no population in the zone system!");
     }
     // Normalize the attractions
     var inverseTotalAttraction = 1 / totalAttraction; // inverse totalAttraction to save on divisions
     foreach (var zone in Root.ZoneSystem.ZoneArray.ValidIndexies())
     {
         attractions[zone] = (attractions[zone] * inverseTotalAttraction) * totalProduction;
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:27,代码来源:SimpleGeneration.cs

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

示例9: TestCSVODC

 public void TestCSVODC()
 {
     try
     {
         int[] zones = new int[] { 0, 1, 2, 3, 4, 5, 6 };
         SparseArray<int> referenceArray = new SparseArray<int>( new SparseIndexing()
         {
             Indexes = new SparseSet[]
         {
             new SparseSet() { Start = 0, Stop = 6 }
         }
         } );
         float[][][] allData = new float[1][][];
         var data = CreateData( zones.Length );
         CreateCSVFile( zones, data, "Test.csv" );
         allData[0] = data;
         var writer = new ODMatrixWriter<int>( referenceArray, 1, 1 );
         writer.LoadCSVTimes( "Test.csv", false, 0, 0 );
         writer.Save( "Test.odc", false );
         var odcFloatData = ConvertData( allData, zones.Length, 1, 1 );
         ValidateData( zones, odcFloatData, "Test.odc" );
     }
     finally
     {
         File.Delete( "Test.csv" );
         File.Delete( "Test.odc" );
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:28,代码来源:ODCTesting.cs

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

示例11: GetRenderers

        private SparseArray<DataRenderer> GetRenderers(IEntity entity) {
            SparseArray<DataRenderer> renderers;

            if (_renderers.TryGetValue(entity.UniqueId, out renderers) == false) {
                renderers = new SparseArray<DataRenderer>();
                _renderers[entity.UniqueId] = renderers;
            }

            return renderers;
        }
开发者ID:jyunfan2015,项目名称:forge-sample,代码行数:10,代码来源:EntityContainerEventMonitor.cs

示例12: SetOneHundredElements

        public void SetOneHundredElements()
        {
            SparseArray<int> array = new SparseArray<int>(10);

            for (int k = 0; k < 100; k++)
                array[(ulong)k] = k;

            for (int k = 0; k < 100; k++)
                Assert.AreEqual(k, array[(ulong)k]);
        }
开发者ID:ajlopez,项目名称:AjActivity,代码行数:10,代码来源:SparseArrayTests.cs

示例13: GettingNonExistingReturnsNull

        public void GettingNonExistingReturnsNull()
        {
            var array = new SparseArray<string>();

            Assert.IsNull(array.GetValue(10000));

            // We shouldn't have allocated items.

            Assert.AreEqual("Values=20", array.ToString());
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:10,代码来源:Fixture.cs

示例14: GetNegativeShouldNotFail

        public void GetNegativeShouldNotFail()
        {
            var array = new SparseArray<string>();

            Assert.IsNull(array.GetValue(-10));

            // We shouldn't have allocated items.

            Assert.AreEqual("Values=20", array.ToString());
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:10,代码来源:Fixture.cs

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


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