本文整理汇总了C#中Population.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# Population.RemoveAt方法的具体用法?C# Population.RemoveAt怎么用?C# Population.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population.RemoveAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoSolve
/// <summary>
/// Returns a solution found using best-placement.
/// </summary>
/// <returns></returns>
protected override IRoute DoSolve(OsmSharp.Tools.Math.TSP.Problems.IProblem problem)
{
// create the settings.
SolverSettings settings = new SolverSettings(
-1,
-1,
1000000000,
-1,
-1,
-1);
Solver<List<int>, GeneticProblem, Fitness> solver =
new Solver<List<int>, GeneticProblem, Fitness>(
new GeneticProblem(problem),
settings,
null,
null,
null,
_generation_operation,
new FitnessCalculator(),
true, false);
Population<List<int>, GeneticProblem, Fitness> population =
new Population<List<int>, GeneticProblem, Fitness>(true);
while (population.Count < _population_size)
{
// generate new.
Individual<List<int>, GeneticProblem, Fitness> new_individual =
_generation_operation.Generate(solver);
// add to population.
population.Add(new_individual);
}
// select each individual once.
Population<List<int>, GeneticProblem, Fitness> new_population =
new Population<List<int>, GeneticProblem, Fitness>(true);
Individual<List<int>, GeneticProblem, Fitness> best = null;
int stagnation = 0;
while (stagnation < _stagnation)
{
while (new_population.Count < _population_size)
{
// select an individual and the next one.
int idx = OsmSharp.Tools.Math.Random.StaticRandomGenerator.Get().Generate(population.Count);
Individual<List<int>, GeneticProblem, Fitness> individual1 = population[idx];
Individual<List<int>, GeneticProblem, Fitness> individual2 = null;
if (idx == population.Count - 1)
{
individual2 = population[0];
}
else
{
individual2 = population[idx + 1];
}
population.RemoveAt(idx);
Individual<List<int>, GeneticProblem, Fitness> new_individual = _cross_over_operation.CrossOver(solver,
individual1, individual2);
new_individual.CalculateFitness(solver.Problem, solver.FitnessCalculator);
if (new_individual.Fitness.CompareTo(
individual1.Fitness) < 0)
{
new_population.Add(new_individual);
}
else
{
new_population.Add(individual1);
}
}
population = new_population;
population.Sort(solver, solver.FitnessCalculator);
new_population = new Population<List<int>, GeneticProblem, Fitness>(true);
if (best == null ||
best.Fitness.CompareTo(population[0].Fitness) > 0)
{
stagnation = 0;
best = population[0];
}
else
{
stagnation++;
}
//// report progress.
//OsmSharp.Tools.Output.OutputStreamHost.ReportProgress(stagnation,_stagnation,
// "OsmSharp.Tools.Math.TSP.EdgeAssemblyGenetic.EdgeAssemblyCrossOverSolver",
// "Solving using EAX...");
}
List<int> result = new List<int>(best.Genomes);
result.Insert(0, 0);
//.........这里部分代码省略.........