shuffle and stop logs
This commit is contained in:
@ -167,7 +167,7 @@
|
|||||||
<div class="live-preview-content" id="live-preview-content"></div>
|
<div class="live-preview-content" id="live-preview-content"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" id="btn-stop-matching" class="btn btn-secondary">
|
<button type="button" id="btn-stop-matching" class="btn btn-danger">
|
||||||
Stop Matching
|
Stop Matching
|
||||||
</button>
|
</button>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -302,7 +302,10 @@ function startMatching() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stopMatching() {
|
function stopMatching() {
|
||||||
if (AppState.worker) AppState.worker.postMessage({ type: 'stop' });
|
console.log("stopMatching")
|
||||||
|
if (AppState.worker) {
|
||||||
|
AppState.worker.postMessage({ type: 'stop' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProgress(progress) {
|
function updateProgress(progress) {
|
||||||
|
|||||||
@ -38,6 +38,20 @@ function cloneConfiguration(arr) {
|
|||||||
return arr.map(group => [...group]);
|
return arr.map(group => [...group]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffle cells based on random
|
||||||
|
*/
|
||||||
|
function shuffleCells(cells) {
|
||||||
|
const shuffled = [...cells];
|
||||||
|
|
||||||
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return shuffled;
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Scoring Functions
|
// Scoring Functions
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
@ -128,7 +142,7 @@ class StatsTracker {
|
|||||||
|
|
||||||
class ExhaustiveSearch {
|
class ExhaustiveSearch {
|
||||||
constructor(cells, serial, parallel, options = {}) {
|
constructor(cells, serial, parallel, options = {}) {
|
||||||
this.cells = cells;
|
this.cells = shuffleCells(cells);
|
||||||
this.serial = serial;
|
this.serial = serial;
|
||||||
this.parallel = parallel;
|
this.parallel = parallel;
|
||||||
this.totalCellsNeeded = serial * parallel;
|
this.totalCellsNeeded = serial * parallel;
|
||||||
@ -144,6 +158,7 @@ class ExhaustiveSearch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
console.log("ExhaustiveSearch: stop requested")
|
||||||
this.stopped = true;
|
this.stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +247,7 @@ class ExhaustiveSearch {
|
|||||||
iteration++;
|
iteration++;
|
||||||
this.stats.recordIteration();
|
this.stats.recordIteration();
|
||||||
|
|
||||||
if (iteration % 500 === 0) {
|
if (iteration % (this.maxIterations * 0.01) === 0) {
|
||||||
const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations));
|
const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations));
|
||||||
|
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
@ -301,12 +316,6 @@ self.onmessage = function (e) {
|
|||||||
const { cells, serial, parallel, algorithm, options } = data;
|
const { cells, serial, parallel, algorithm, options } = data;
|
||||||
|
|
||||||
switch (algorithm) {
|
switch (algorithm) {
|
||||||
case 'genetic':
|
|
||||||
currentAlgorithm = new GeneticAlgorithm(cells, serial, parallel, options);
|
|
||||||
break;
|
|
||||||
case 'simulated-annealing':
|
|
||||||
currentAlgorithm = new SimulatedAnnealing(cells, serial, parallel, options);
|
|
||||||
break;
|
|
||||||
case 'exhaustive':
|
case 'exhaustive':
|
||||||
currentAlgorithm = new ExhaustiveSearch(cells, serial, parallel, options);
|
currentAlgorithm = new ExhaustiveSearch(cells, serial, parallel, options);
|
||||||
break;
|
break;
|
||||||
@ -323,6 +332,7 @@ self.onmessage = function (e) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'stop':
|
case 'stop':
|
||||||
|
console.log("Algo: Stop requested")
|
||||||
if (currentAlgorithm) {
|
if (currentAlgorithm) {
|
||||||
currentAlgorithm.stop();
|
currentAlgorithm.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user