本文整理汇总了C#中Population.GetMaxChromo方法的典型用法代码示例。如果您正苦于以下问题:C# Population.GetMaxChromo方法的具体用法?C# Population.GetMaxChromo怎么用?C# Population.GetMaxChromo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population.GetMaxChromo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Go_Click
private void Go_Click(object sender, EventArgs e)
{
//initialize var
int cLength = Convert.ToInt32(chromoLength.Text);
EliteSelection<int> sel2 = new EliteSelection<int>(0);
RouletteSelection<int> sel1 = new RouletteSelection<int>();
GreedyCrossover cros = new GreedyCrossover(-1, -1, matrix);
GoldenMutation<int> mut = new GoldenMutation<int>(cLength);
pop = new Population<int>(mut, cros, sel1, sel2, x => 1 / cros.CalcFitness(x),
Convert.ToDouble(mProb.Text), Convert.ToDouble(cProb.Text));
maxF = new double[Convert.ToInt32(expCount.Text), Convert.ToInt32(iterCount.Text) + 1];
avgF = new double[Convert.ToInt32(expCount.Text), Convert.ToInt32(iterCount.Text) + 1];
double min = 100500; // Hi to Max ))
string bestChromo = null;
//experiments
for (int i = 0; i < Convert.ToInt32(expCount.Text); ++i)
{
//initial chromosomes
Trace.WriteLine("experiment #" + (i + 1).ToString());
Trace.Indent();
ChromosomesFromArray();
maxF[i, 0] = Math.Round(1 / pop.GetMaxFitness());
avgF[i, 0] = 1 / pop.GetPopulationFitness();
Trace.WriteLine("initial best fitness = " + Math.Round((1 / pop.GetMaxFitness())).ToString());
Trace.WriteLine("initial avg fitness = " + (1 / pop.GetPopulationFitness()).ToString());
Trace.WriteLine("initia;best fitness chromo = " + pop.GetMaxChromo());
// iterations
for (int j = 0; j < Convert.ToInt32(iterCount.Text); ++j)
{
Trace.WriteLine("iteration #" + (j + 1).ToString());
Trace.Indent();
pop.Iteration();
maxF[i, j + 1] = Math.Round(1 / pop.GetMaxFitness());
avgF[i, j + 1] = 1 / pop.GetPopulationFitness();
Trace.WriteLine(" best fitness = " + Math.Round((1 / pop.GetMaxFitness())).ToString());
Trace.WriteLine("avg fitness = " + (1 / pop.GetPopulationFitness()).ToString());
Trace.WriteLine("best fitness chromo = " + pop.GetMaxChromo());
Trace.Unindent();
}
if (Math.Round(1 / pop.GetMaxFitness()) < min)
{
min = Math.Round(1 / pop.GetMaxFitness());
bestChromo = pop.GetMaxChromo();
}
Trace.Unindent();
}
answer.Text = "Best Path: " + bestChromo + "Path Length" + min.ToString();
}