次のコードを書いて、各染色体が5x5の配列である6つの染色体の集団を生成しました。次に、別の方法で各染色体を印刷します。問題は毎回同じアレイを手に入れたことです!配列リストに長方形の配列を正しい方法で格納する方法
static List<int[,]> PopulationChromosomes = new List<int[,]>();
private void moveGenetic_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("C:/temp/intialPopulation.txt", FileMode.Append, FileAccess.Write);
writer = new StreamWriter("C:/temp/listOfChromosomesForAllRounds.txt", true);
population = new int[6][,]; // jagged array
Random rnd = new Random(); // to gereate random number (either 0 or 1)
auvChromosomes = new int[5, 5];
for (int i = 0; i < population.Length; i++)
{
population[i] = new int[5, 5];
}
using (StreamWriter sw = new StreamWriter(fs))
{
for (int i = 0; i < population.Length; i++)
{
for (int j = 0; j < 5; j++)
{
for (int k = 0; k < 5; k++)
{
auvChromosomes[j, k] = rnd.Next(0, 2);
sw.Write("|" + auvChromosomes[j, k] + "|");
} // end-inner-for
sw.WriteLine();
} // end-outer-inner-for
PopulationChromosomes.Add(auvChromosomes);
Array.Clear(auvChromosomes, 0, auvChromosomes.Length);
} // end-outer-for
} // end-using
Chromosomes(PopulationChromosomes, 1);
}
印刷が間違っているか計算していますか?適切な結果を提供できますか? – NetMage
それはリンクをちょうど提供するために提供されます – Rose
「間違って」定義してください。 –