本文整理汇总了C#中Population.Min方法的典型用法代码示例。如果您正苦于以下问题:C# Population.Min方法的具体用法?C# Population.Min怎么用?C# Population.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population.Min方法的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)
{
//.........这里部分代码省略.........