优化:修复异形优化算法NotPutCache错误的问题

pull/2793/head
ChenX 4 months ago
parent 40df322879
commit fc3de97218

@ -51,11 +51,26 @@ export class Container
constructor(public BinPath?: Path, private _PlaceType = PlaceType.Box, public ComparePosFnKey = "xy")
{
if (BinPath)
{
this.StatusKey = this.BinPath.Id.toString() + "," + this._PlaceType + "," + ComparePosFnKey;
this.UpdateCurNotPuts();
}
this.CompartePoint = ComparePoint(ComparePosFnKey);
}
private UpdateCurNotPuts()
{
this._CurNotPuts = NestCache.GetNoPut(this.StatusKey);
if (!this._CurNotPuts)
{
this._CurNotPuts = new Set;
NestCache.SetNoPut(this.StatusKey, this._CurNotPuts);
this._NotPuts.push(this._CurNotPuts);
}
}
get UseRatio(): number
{
return this.PlacedBox.area / this.BinPath.Area;
@ -72,6 +87,7 @@ export class Container
}
private _NotPuts: Set<number>[] = [];//已经无法放置的pathId
private _CurNotPuts: Set<number>;
private PrePut(part: Part): PartPlacedContainerState
{
@ -100,8 +116,6 @@ export class Container
}
//快速退出
let noSet = NestCache.GetNoPut(this.StatusKey);
if (noSet) this._NotPuts.push(noSet);
for (let set of this._NotPuts)
{
if (set.has(part.State.Contour.Id))
@ -114,12 +128,7 @@ export class Container
let finalNfp = this.GetNFPs(part, binNfp);
if (!finalNfp || finalNfp.length === 0)
{
if (noSet) noSet.add(part.State.Contour.Id);
else
{
noSet = new Set([part.State.Contour.Id]);
NestCache.SetNoPut(this.StatusKey, noSet);
}
this._CurNotPuts.add(part.State.Contour.Id);
return;
}
@ -324,6 +333,7 @@ export class Container
private AppendPart(part: Part, calc = true): void
{
this.StatusKey += "," + part.State.Contour.Id;
this.UpdateCurNotPuts();
this.PlacedParts.push(part);
this.PlacedArea += part.State.Contour.Area;
let m = { x: part.PlacePosition.x * 1e-4, y: part.PlacePosition.y * 1e-4 };

@ -91,6 +91,10 @@ export class OptimizeMachine
{
console.time("1");
if (this.Parts.length === 0) return;
//默认100次sleep一次 1500->70 2500->40 3500->10 4500->1
let sleepCount = Math.max(130 - (30 * Math.ceil(this.Parts.length / 1000)), 1);
//开始自然选择
while (!this._IsSuspend) //实验停止信号
{
@ -101,7 +105,7 @@ export class OptimizeMachine
if (globalThis.document || !clipperCpp.lib)
await Sleep(0);
let p = this._Individuals[i];
const useContainerTemplate = i >= this._Individuals.length - 5; // 最后的5个个体使用容器模板模式来优化排料
const useContainerTemplate = i === 1 || i === 4 || i === 10 || i === 20 || i === 50; // 最后的5个个体使用容器模板模式来优化排料
if (this.calcCount < 1000 || this.calcCount % 1000 === 0)
p.Evaluate(this.best, true, useContainerTemplate, i % 3);
else
@ -113,12 +117,16 @@ export class OptimizeMachine
this.best = p.Fitness;
await this.callBack(p);
}
if (this.Parts.length > 2000)
Sleep(0);
if (goBack)
p.mutationRate = 0.6;
}
this.calcCount += this._Individuals.length;
if (this.calcCount % 100 === 0)
if (this.calcCount % sleepCount === 0)
{
await Sleep(0);
if (false)//debug time

Loading…
Cancel
Save