C#で遺伝的アルゴリズムを使用して巡回セールスマン問題を解決しようとしています。しかし、私のアプリでは、最高の値がゆっくりと変化します。クラシック、貪欲、pmx などのさまざまな Crossing-Over メソッドを試しましたが、欲しいものが得られませんでした。遺伝的アルゴリズムで局所最小値への近似が遅くなる最も効果的な理由は何ですか? クロスオーバー法じゃないですか。
私の CO の方法は正しいと思いますね。私のコード:
Tour ClassicCrossingOver(Tour mother, Tour father)
{
int pos = N / 2;
City[] gens = new City[N];
for (int i = 0; i < pos; i++)
{
gens[i] = mother.Cities[i];
}
List<int> nonPos = new List<int>(); //Handles duplicate city positions
for (int i = pos; i < gens.Length; i++)
{
if (gens.Contains(father.Cities[i]))
nonPos.Add(i);
gens[i] = father.Cities[i];
}
List<City> noneGenes = new List<City>(); //Handles cities that doesnt exists in the child
foreach (City gene in map.Cities)
{
if (gens.Contains(gene)) continue;
noneGenes.Add(gene);
}
for (int i = 0; i < noneGenes.Count; i++)
{
int j = rnd.Next(nonPos.Count - 1);
gens[nonPos[j]] = noneGenes[i];
nonPos.RemoveAt(j);
}
Tour tur = new Tour(map) { Cities = gens };
return tur;
}