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


C# Population.Max方法代码示例

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


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

示例1: SolveStep

        /// <summary>
        /// Solve the next iteration of the algorithm.
        /// </summary>
        public void SolveStep()
        {
            if (this.properties.Objectives.Length < 1)
            {
                throw new Exception("You cannot optimise with 0 objectives.");
            }

            this.iteration = this.Iteration + 1;

            Console.WriteLine("Solving step {0}...", this.Iteration);

            this.progress = 0;

            var sw = Stopwatch.StartNew();

            var r = new Population(this.population[0].Union(this.population[1]));

            foreach (var c in r)
            {
                double totalDistance = 0.0;
                foreach (var c2 in r)
                {
                    /*
                    totalDistance += Math.Max(Math.Max(Math.Abs(c.Fitness.PercentBuses - c2.Fitness.PercentBuses) ,
                                     Math.Abs(c.Fitness.PercentTrains - c2.Fitness.PercentTrains)) ,
                                     Math.Abs(c.Fitness.PercentTrams - c2.Fitness.PercentTrams));
                    */
                    totalDistance +=
                        Math.Sqrt(
                            Math.Pow(c.Fitness.PercentBuses - c2.Fitness.PercentBuses, 2.0)
                            + Math.Pow(c.Fitness.PercentTrains - c2.Fitness.PercentTrains, 2.0)
                            + Math.Pow(c.Fitness.PercentTrams - c2.Fitness.PercentTrams, 2.0));
                }

                c.Fitness.DiversityMetric = totalDistance / r.Count;
            }

            double jtMaxTime = r.Max(c => c.Fitness.TotalJourneyTime).TotalHours;
            double jtMinTime = r.Min(c => c.Fitness.TotalJourneyTime).TotalHours;
            double ttMaxTime = r.Max(c => c.Fitness.WalkingTime).TotalHours;
            double ttMinTime = r.Min(c => c.Fitness.WalkingTime).TotalHours;
            double minDM = r.Min(c => c.Fitness.DiversityMetric);
            double maxDM = r.Max(c => c.Fitness.DiversityMetric);
            int maxChanges = r.Max(c => c.Fitness.Changes);
            int minChanges = r.Min(c => c.Fitness.Changes);

            foreach (var c in r)
            {
                c.Fitness.NormalisedJourneyTime = (c.Fitness.TotalJourneyTime.TotalHours - jtMinTime)
                                                  / (jtMaxTime - jtMinTime);
                c.Fitness.NormalisedChanges = (double)(c.Fitness.Changes - minChanges) / (maxChanges - minChanges);
                c.Fitness.NormalisedTravelTime = (c.Fitness.TotalWaitingTime.TotalHours - ttMinTime)
                                                 / (ttMaxTime - ttMinTime);
                c.Fitness.DiversityMetric = (c.Fitness.DiversityMetric - minDM) / (maxDM - minDM);

                if (double.IsInfinity(c.Fitness.NormalisedChanges))
                {
                    c.Fitness.NormalisedChanges = 0;
                }

                if (double.IsInfinity(c.Fitness.NormalisedJourneyTime))
                {
                    c.Fitness.NormalisedJourneyTime = 0;
                }

                if (double.IsInfinity(c.Fitness.NormalisedTravelTime))
                {
                    c.Fitness.NormalisedTravelTime = 0;
                }

                if (double.IsInfinity(c.Fitness.DiversityMetric))
                {
                    c.Fitness.DiversityMetric = 0;
                }

                Console.WriteLine(
                    "{0}, {1},{2},{3}",
                    c.Fitness.NormalisedJourneyTime,
                    c.Fitness.NormalisedChanges,
                    c.Fitness.PercentBuses,
                    c.Fitness.PercentTrains);
                c.N = 0;
                c.Rank = 0;

                // c.Distance = 0;
            }

            this.NonDominatedSort(r);

            /*
            var ranks = r.GroupBy(g => g.Rank);
            foreach (var rank in ranks)
            {
                foreach (var c1 in rank)
                {
                    foreach (var c2 in rank)
                    {
//.........这里部分代码省略.........
开发者ID:NoxHarmonium,项目名称:rmitjourneyplanner,代码行数:101,代码来源:MoeaJourneyPlanner.cs


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