Skip to content

Commit

Permalink
More fast stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Dec 5, 2024
1 parent 0c0e32a commit 798aac4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "molecular-ts",
"version": "1.13.2",
"version": "1.13.3",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const progress = computed(() => {
return genomesHandled.value / totalCount * 100;
});
class StopException extends Error {}
function createAlgo() {
const typesCount = configStore.typesConfig.FREQUENCIES.length;
const worldConfig = fullCopyObject(configStore.worldConfig);
Expand All @@ -66,6 +68,9 @@ function createAlgo() {
onTaskResult: (metrics) => {
console.log('genome handled', metrics);
genomesHandled.value++;
if (needStop.value) {
throw new StopException();
}
} // TODO TTaskConfig to input
};
const weightsConfig: ClusterizationWeightsConfig = createDefaultClusterizationWeightsConfig();
Expand Down Expand Up @@ -122,17 +127,23 @@ function stopAlgo() {
async function runAlgoStep(algo: GeneticSearch<SimulationGenome>) {
genomesHandled.value = 0;
await algo.fitStep();
algo.clearCache();
try {
await algo.fitStep();
algo.clearCache();
bestGenome.value = algo.bestGenome;
generation.value = algo.generation;
bestGenome.value = algo.bestGenome;
generation.value = algo.generation;
const scores = algo.population.map((x) => x.stats!.fitness);
averageScore.value = arraySum(scores) / scores.length;
const scores = algo.population.map((x) => x.stats!.fitness);
averageScore.value = arraySum(scores) / scores.length;
console.log(`Generation ${algo.generation}`, algo.bestGenome, algo.bestGenome.stats);
console.log('Fitness', algo.population.map((x) => x.stats!.fitness));
console.log(`Generation ${algo.generation}`, algo.bestGenome, algo.bestGenome.stats);
console.log('Fitness', algo.population.map((x) => x.stats!.fitness));
} catch (e) {
if (!(e instanceof StopException)) {
throw e;
}
}
if (needStop.value) {
isStarted.value = false;
Expand Down

0 comments on commit 798aac4

Please sign in to comment.