JAVA代码改成C#代码
packagesimpleGa;publicclassIndividual{staticintdefaultGeneLength=64;//基因序列privatebyte...
package simpleGa;
public class Individual {
static int defaultGeneLength = 64;
//基因序列
private byte[] genes = new byte[defaultGeneLength];
// 个体的 适应值
private int fitness = 0;
// 创建一个随机的 基因个体
public void generateIndividual() {
for (int i = 0; i < size(); i++) {
byte gene = (byte) Math.round(Math.random());
genes[i] = gene;
}
}
// Use this if you want to create individuals with different gene lengths
public static void setDefaultGeneLength(int length) {
defaultGeneLength = length;
}
public byte getGene(int index) {
return genes[index];
}
public void setGene(int index, byte value) {
genes[index] = value;
fitness = 0;
}
/* Public methods */
public int size() {
return genes.length;
}
public int getFitness() {
if (fitness == 0) {
fitness = FitnessCalc.getFitness(this);
}
return fitness;
}
@Override
public String toString() {
String geneString = "";
for (int i = 0; i < size(); i++) {
geneString += getGene(i);
}
return geneString;
}
} 展开
public class Individual {
static int defaultGeneLength = 64;
//基因序列
private byte[] genes = new byte[defaultGeneLength];
// 个体的 适应值
private int fitness = 0;
// 创建一个随机的 基因个体
public void generateIndividual() {
for (int i = 0; i < size(); i++) {
byte gene = (byte) Math.round(Math.random());
genes[i] = gene;
}
}
// Use this if you want to create individuals with different gene lengths
public static void setDefaultGeneLength(int length) {
defaultGeneLength = length;
}
public byte getGene(int index) {
return genes[index];
}
public void setGene(int index, byte value) {
genes[index] = value;
fitness = 0;
}
/* Public methods */
public int size() {
return genes.length;
}
public int getFitness() {
if (fitness == 0) {
fitness = FitnessCalc.getFitness(this);
}
return fitness;
}
@Override
public String toString() {
String geneString = "";
for (int i = 0; i < size(); i++) {
geneString += getGene(i);
}
return geneString;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询