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


C# SparseArray.CreateSimilarArray方法代码示例

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


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

示例1: 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:dianatle,项目名称:XTMF,代码行数:55,代码来源:GravityModel.cs

示例2: WriteParallel

        private void WriteParallel(int[] validZones, SparseArray<IPerson[]> population, StreamWriter writer, int length)
        {
            var output = population.CreateSimilarArray<StringBuilder>();
            var flatOutput = output.GetFlatData();
            var flatPop = population.GetFlatData();
            int current = 0;
            Parallel.For( 0, length,
                delegate(int i)
                {
                    var popInZone = flatPop[i];
                    if ( popInZone == null ) return;
                    StringBuilder builder = new StringBuilder();
                    foreach ( var person in popInZone )
                    {
                        builder.Append( validZones[i] );
                        if ( person == null )
                        {
                            builder.AppendLine( ", PERSON MISSING!" );
                            continue;
                        }
                        builder.Append( ',' );
                        builder.Append( person.Age );
                        builder.Append( ',' );
                        builder.Append( person.Household != null ? person.Household.Cars : 0 );
                        builder.Append( ',' );
                        builder.Append( person.SchoolZone != null ? person.SchoolZone.ZoneNumber : -1 );
                        builder.Append( ',' );
                        builder.Append( person.WorkZone != null ? person.WorkZone.ZoneNumber : -1 );
                        builder.Append( ',' );
                        builder.Append( (int)person.EmploymentStatus );
                        builder.Append( ',' );
                        builder.Append( (int)person.StudentStatus );
                        builder.Append( ',' );
                        builder.Append( (int)person.Occupation );
                        builder.Append( ',' );
                        builder.Append( person.DriversLicense ? 1 : 0 );
                        builder.Append( ',' );
                        builder.Append( person.ExpansionFactor );
                        builder.AppendLine();
                    }
                    flatOutput[i] = builder;
                    System.Threading.Interlocked.Increment( ref current );
                    this.Progress = (float)current / length;
                } );

            for ( int i = 0; i < length; i++ )
            {
                var sbuilder = flatOutput[i];
                if ( sbuilder != null )
                {
                    writer.Write( sbuilder.ToString() );
                }
            }
            this.Progress = 1;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:55,代码来源:GTAPopulation.cs

示例3: GetWarmBalancingFactors

 private SparseArray<float> GetWarmBalancingFactors(SparseArray<float> attraction, out string balanceFileName)
 {
     SparseArray<float> balanceFactors = null;
     if ( this.BalanceFactors.ContainsFileName() )
     {
         balanceFileName = this.BalanceFactors.GetFileName() + this.CurrentMultiSetIndex + ".bin";
         if ( File.Exists( balanceFileName ) )
         {
             balanceFactors = LoadBalanceFactors( balanceFileName );
         }
         else
         {
             balanceFactors = attraction.CreateSimilarArray<float>();
             var flatFactors = balanceFactors.GetFlatData();
             // initialize the factors to 1
             for ( int i = 0; i < flatFactors.Length; i++ )
             {
                 flatFactors[i] = 1.0f;
             }
         }
     }
     else
     {
         balanceFileName = null;
     }
     return balanceFactors;
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:27,代码来源:BlendedDemographicCategoryLogsumDistribution.cs

示例4: SplitAndClear

 private SparseArray<int> SplitAndClear(int pop, SparseArray<float> splitPercentages, Random rand)
 {
     var flatSplitPercentages = splitPercentages.GetFlatData();
     var length = flatSplitPercentages.Length;
     var ret = splitPercentages.CreateSimilarArray<int>();
     var flatRet = ret.GetFlatData();
     var flatRemainder = new float[length];
     float remainderTotal = 0;
     int total = 0;
     for ( int i = 0; i < length; i++ )
     {
         float element = ( flatSplitPercentages[i] * pop );
         total += ( flatRet[i] = (int)Math.Floor( element ) );
         flatRemainder[i] = element - flatRet[i];
     }
     int notAssigned = pop - total;
     // Make sure that we do not over assign
     remainderTotal = notAssigned;
     for ( int i = 0; i < notAssigned; i++ )
     {
         var randPop = rand.NextDouble() * remainderTotal;
         float ammountToReduce = 0;
         int j = 0;
         for ( ; j < length; j++ )
         {
             randPop -= ( ammountToReduce = flatRemainder[j] );
             if ( randPop <= 0 )
             {
                 remainderTotal -= ammountToReduce;
                 flatRemainder[j] = 0;
                 flatRet[j] += 1;
                 break;
             }
         }
         if ( j == length )
         {
             for ( j = 0; j < length; j++ )
             {
                 if ( flatRemainder[j] >= 0 )
                 {
                     remainderTotal -= flatRemainder[j];
                     flatRemainder[j] = 0;
                     flatRet[j] += 1;
                     break;
                 }
             }
         }
     }
     return ret;
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:50,代码来源:PopulationSynthesis.cs


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