|
|
|
@ -35,7 +35,7 @@ export class Individual
|
|
|
|
|
*/
|
|
|
|
|
Mutate()
|
|
|
|
|
{
|
|
|
|
|
if (this.mutationRate > 0.6)
|
|
|
|
|
if (this.mutationRate > 0.5)
|
|
|
|
|
for (let i = 0; i < this.Parts.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let rand = Math.random();
|
|
|
|
@ -47,25 +47,32 @@ export class Individual
|
|
|
|
|
[this.Parts[i], this.Parts[j]] = [this.Parts[j], this.Parts[i]];
|
|
|
|
|
}
|
|
|
|
|
if (rand < this.mutationRate)
|
|
|
|
|
{
|
|
|
|
|
this.Parts[i].Mutate();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//洗牌
|
|
|
|
|
let rand = Math.random();
|
|
|
|
|
if (rand < 0.5)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
let index = RandomIndex(this.Parts.length - 2);
|
|
|
|
|
let count = Math.ceil(RandomIndex(this.Parts.length - 2 - index) * this.mutationRate * 2) || 1;
|
|
|
|
|
let parts = this.Parts.splice(index, count);
|
|
|
|
|
this.Parts.push(...parts);
|
|
|
|
|
//洗牌
|
|
|
|
|
let rand = Math.random();
|
|
|
|
|
if (rand < 0.5)
|
|
|
|
|
{
|
|
|
|
|
let index = RandomIndex(this.Parts.length - 2);
|
|
|
|
|
let count = Math.ceil(RandomIndex(this.Parts.length - 2 - index) * this.mutationRate * 2) || 1;
|
|
|
|
|
let parts = this.Parts.splice(index, count);
|
|
|
|
|
this.Parts.push(...parts);
|
|
|
|
|
this.Parts[index].Mutate();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
for (let i = 0; i < this.Parts.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let rand = Math.random();
|
|
|
|
|
if (rand < this.mutationRate)
|
|
|
|
|
{
|
|
|
|
|
this.Parts[i].Mutate();
|
|
|
|
|
i += 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let index = RandomIndex(this.Parts.length);
|
|
|
|
|
this.Parts[index].Mutate();
|
|
|
|
|
|
|
|
|
|
if (this.mutationRate > 0.2)
|
|
|
|
|
this.mutationRate -= 0.004;
|
|
|
|
|
return this;
|
|
|
|
|