📄 population.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace CIProject
{
public class Population
{
public Population(int size)
{
populationCount = size;
population = new Chromosome[populationCount];
chromosomeFitness = new double[populationCount];
for (int i = 0; i < populationCount; i++)
{
chromosomeFitness[i] = 0.0;
}
}
public Chromosome this[int index]
{
set
{
population[index] = value;
}
get
{
return population[index];
}
}
public void SetFitness(int index, double f)
{
chromosomeFitness[index] = f;
}
public double GetFitness(int index)
{
return chromosomeFitness[index];
}
public void Sort(int index, int size)
{
Double tempF = 0.0;
Chromosome tempC = null;
for (int i = index; i < size; i++)
{
for (int j = index; j < (size - 1); j++)
{
if (chromosomeFitness[j] < chromosomeFitness[j + 1])
{
tempF = chromosomeFitness[j];
chromosomeFitness[j] = chromosomeFitness[j + 1];
chromosomeFitness[j + 1] = tempF;
tempC = population[j];
population[j] = population[j + 1];
population[j + 1] = tempC;
}
}
}
}
public int Length
{
get
{
return populationCount;
}
}
private int populationCount;
private Chromosome[] population;
private Double[] chromosomeFitness;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -