|
|
|
@ -57,7 +57,14 @@ export class OptimizeMachine
|
|
|
|
|
{
|
|
|
|
|
let parts = this.Parts.map(p => p.Clone());
|
|
|
|
|
if (i < 3)
|
|
|
|
|
ShuffleArray(parts);
|
|
|
|
|
{
|
|
|
|
|
for (let i = parts.length - 1; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
|
|
|
[parts[i], parts[j]] = [parts[j], parts[i]];
|
|
|
|
|
parts[i].Mutate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this._Individuals.push(new Individual(parts, 0.8));
|
|
|
|
|
}
|
|
|
|
|
//2.执行
|
|
|
|
@ -82,7 +89,7 @@ export class OptimizeMachine
|
|
|
|
|
if (globalThis.document || !clipperCpp.lib)
|
|
|
|
|
await Sleep(0);
|
|
|
|
|
let p = this._Individuals[i];
|
|
|
|
|
if (this.calcCount < 2000 || this.calcCount % 1000 === 0)
|
|
|
|
|
if (this.calcCount < 1000 || this.calcCount % 1000 === 0)
|
|
|
|
|
p.Evaluate(this.Bin, this.best, true, i % 2);
|
|
|
|
|
else
|
|
|
|
|
p.Evaluate(this.Bin, this.best);
|
|
|
|
@ -118,8 +125,9 @@ export class OptimizeMachine
|
|
|
|
|
|
|
|
|
|
//自然选择
|
|
|
|
|
this._Individuals.splice(-10);//杀死它
|
|
|
|
|
for (let i = 0; i < 5; i++)
|
|
|
|
|
for (let i = 0; i < 4; i++)
|
|
|
|
|
this._Individuals.push(bestP.Clone());
|
|
|
|
|
this._Individuals.push(this.bestP.Clone());
|
|
|
|
|
for (let i = 0; i < 3; i++)
|
|
|
|
|
this._Individuals.push(this._Individuals[1].Clone());
|
|
|
|
|
for (let i = 0; i < 2; i++)
|
|
|
|
|