This commit is contained in:
2025-12-21 09:00:48 +01:00
parent fecdcafed2
commit cfb031aee6
4 changed files with 420 additions and 390 deletions

View File

@ -232,10 +232,14 @@ class ExhaustiveSearch {
: [[...this.cells]];
for (const cellSubset of cellCombos) {
if (this.stopped) break;
if (this.stopped) {
return this.returnBestResult(iteration, totalCombinations);
}
for (const partition of this.generatePartitions(cellSubset, this.parallel, this.serial)) {
if (this.stopped) break;
if (this.stopped) {
return this.returnBestResult(iteration, totalCombinations);
}
const scoreResult = calculateScore(partition, this.capacityWeight, this.irWeight);
@ -247,7 +251,8 @@ class ExhaustiveSearch {
iteration++;
this.stats.recordIteration();
if (iteration % (this.maxIterations * 0.01) === 0) {
// Check frequently for stop and send progress updates every 100 iterations
if (iteration % 100 === 0) {
const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations));
self.postMessage({
@ -265,12 +270,29 @@ class ExhaustiveSearch {
}
if (iteration >= this.maxIterations) {
this.stopped = true;
break;
return this.returnBestResult(iteration, totalCombinations);
}
}
}
return this.returnBestResult(iteration, totalCombinations);
}
returnBestResult(iteration, totalCombinations) {
if (!this.bestSolution) {
// No solution found yet, create one from first cells
const config = [];
for (let i = 0; i < this.serial; i++) {
config.push(this.cells.slice(i * this.parallel, (i + 1) * this.parallel));
}
const scoreResult = calculateScore(config, this.capacityWeight, this.irWeight);
this.bestSolution = { config, ...scoreResult };
this.bestScore = scoreResult.score;
}
const usedLabels = new Set(this.bestSolution.config.flat().map(c => c.label));
const excludedCells = this.cells.filter(c => !usedLabels.has(c.label));
// Final progress update
const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations));
self.postMessage({
@ -286,9 +308,6 @@ class ExhaustiveSearch {
}
});
const usedLabels = new Set(this.bestSolution.config.flat().map(c => c.label));
const excludedCells = this.cells.filter(c => !usedLabels.has(c.label));
return {
configuration: this.bestSolution.config,
score: this.bestScore,