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


C# SparseArray.ValidIndexies方法代码示例

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


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

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

示例2: LoadLocationChoiceCache

 public void LoadLocationChoiceCache()
 {
     ZoneArray = Root.ZoneSystem.ZoneArray;
     ValidZones = ZoneArray.ValidIndexies().ToArray();
     LoadProbabilityTables();
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:6,代码来源:BeijingLocationChoice.cs

示例3: AssignOccupationAndLicenese

 private void AssignOccupationAndLicenese(Person[] people, int ageOffset, int employmentOffset, SparseArray<int> OccupationSplit, int numberOfEmploymentClassifiedPeople,
     int numberOfLicenses, Random r)
 {
     int[] personIndex = new int[numberOfEmploymentClassifiedPeople];
     for ( int i = 0; i < numberOfEmploymentClassifiedPeople; i++ )
     {
         personIndex[i] = i;
     }
     // Randomize the population for assignment (Card shuffle algorithm)
     for ( int i = 0; i < numberOfEmploymentClassifiedPeople; i++ )
     {
         var selectedIndex = r.Next( i, numberOfEmploymentClassifiedPeople );
         var temp = personIndex[selectedIndex];
         personIndex[selectedIndex] = personIndex[i];
         personIndex[i] = temp;
     }
     // assign the occupations
     int occOffset = 0;
     foreach ( var occIndex in OccupationSplit.ValidIndexies() )
     {
         var occPop = OccupationSplit[occIndex];
         for ( int i = 0; i < occPop; i++ )
         {
             people[personIndex[occOffset + i] + ageOffset + employmentOffset].Occupation = occIndex;
         }
         occOffset += occPop;
     }
     // Randomize the population for assignment (Card shuffle algorithm)
     for ( int i = 0; i < numberOfEmploymentClassifiedPeople; i++ )
     {
         var selectedIndex = r.Next( i, numberOfEmploymentClassifiedPeople );
         var temp = personIndex[selectedIndex];
         personIndex[selectedIndex] = personIndex[i];
         personIndex[i] = temp;
     }
     // assign the occupations
     for ( int i = 0; i < numberOfLicenses; i++ )
     {
         people[personIndex[i] + ageOffset + employmentOffset].DriversLicense = true;
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:41,代码来源:PopulationSynthesis.cs

示例4: SplitCars

        private SparseArray<int> SplitCars(Person[] people, int zoneIndex, int validAgeIndex, int validOccupationIndex, bool license, int ageOffset, int agePop, Random rand, out int[] indexes)
        {
            SparseArray<float> ret = new SparseArray<float>( new SparseIndexing() { Indexes = new SparseSet[] { new SparseSet() { Start = 0, Stop = 2 } } } );
            // Because everything is random at this point we actually need to scan to see how many people we have
            List<int> indexesList = new List<int>( agePop );
            if ( validOccupationIndex == this.UnemployedOccupation )
            {
                for ( int i = 0; i < agePop; i++ )
                {
                    var person = people[i + ageOffset];
                    if ( person.DriversLicense == license )
                    {
                        var range = this.Demographics.AgeCategories[validAgeIndex];
                        var age = person.Age;
                        if ( age >= range.Start && age <= range.Stop )
                        {
                            indexesList.Add( i );
                        }
                    }
                }
                var data = this.Demographics.NonWorkerVehicleRates[zoneIndex];
                foreach ( var validCarsIndex in ret.ValidIndexies() )
                {
                    ret[validCarsIndex] = data[license ? 1 : 0, validAgeIndex, validCarsIndex];
                }
            }
            else
            {
                for ( int i = 0; i < agePop; i++ )
                {
                    var person = people[i + ageOffset];
                    if ( person.DriversLicense == license
                        && person.Occupation == validOccupationIndex )
                    {
                        indexesList.Add( i );
                    }
                }
                var data = this.Demographics.WorkerVehicleRates[zoneIndex];
                foreach ( var validCarsIndex in ret.ValidIndexies() )
                {
                    ret[validCarsIndex] = data[license ? 1 : 0, validOccupationIndex, validCarsIndex];
                }
            }
            indexes = indexesList.ToArray();

            return this.SplitAndClear( indexes.Length, ret, rand );
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:47,代码来源:PopulationSynthesis.cs

示例5: AssignCars

        private void AssignCars(Person[] people, int[] indexes, SparseArray<int> split, Household[] households, int ageOffset, Random rand)
        {
            var numberOfPeople = indexes.Length;
            // randomly shuffle the indexes before we actually assign the households
            for ( int i = 0; i < numberOfPeople; i++ )
            {
                var selectedIndex = rand.Next( i, numberOfPeople );
                var temp = indexes[selectedIndex];
                indexes[selectedIndex] = indexes[i];
                indexes[i] = temp;
            }

            int typeOffset = 0;
            foreach ( var carType in split.ValidIndexies() )
            {
                var numberInType = split[carType];
                for ( int i = 0; i < numberInType; i++ )
                {
                    people[indexes[i + typeOffset] + ageOffset].Household = households[carType];
                }
                typeOffset += numberInType;
            }
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:23,代码来源:PopulationSynthesis.cs


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