Skip to content

Commit

Permalink
Refactor CRISPR functionality and fix DNA ID retrieval in ElitismUtil… (
Browse files Browse the repository at this point in the history
#357)

* Refactor CRISPR functionality and fix DNA ID retrieval in ElitismUtils.ts

* Refactor DeDuplicator class to improve population deduplication logic in DeDuplicator.ts

---------

Co-authored-by: Nigel Leck <[email protected]>
  • Loading branch information
nleck and nigelleck authored Apr 24, 2024
1 parent 4d2adf5 commit f2b6154
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions src/architecture/DeDuplicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,38 @@ export class DeDuplicator {
creatures.splice(i, 1);
i--;
} else {
const child = this.neat.offspring();
for (let attempts = 0; true; attempts++) {
const child = this.neat.offspring();

if (child) {
const key2 = await CreatureUtil.makeUUID(child);
let duplicate2 = unique.has(key);
if (!duplicate2 && i > this.config.elitism) {
duplicate2 = this.previousExperiment(key2);
if (child) {
const key2 = await CreatureUtil.makeUUID(child);
let duplicate2 = unique.has(key);
if (!duplicate2 && i > this.config.elitism) {
duplicate2 = this.previousExperiment(key2);
}
if (!duplicate2) {
unique.add(key2);
creatures[i] = child;
break;
}
}
if (!duplicate2) {
unique.add(key2);
creatures[i] = child;
this.neat.mutate([creature]);
const key3 = await CreatureUtil.makeUUID(creature);
let duplicate3 = unique.has(key3);
if (!duplicate3 && i > this.config.elitism) {
duplicate3 = this.previousExperiment(key3);
}
if (!duplicate3) {
unique.add(key3);
break;
} else if (attempts > 12) {
console.error(
`Can't deDuplicate creature at ${i} of ${creatures.length}`,
);
creatures.splice(i, 1);
i--;
break;
}
}
this.neat.mutate([creature]);
const key3 = await CreatureUtil.makeUUID(creature);
let duplicate3 = unique.has(key3);
if (!duplicate3 && i > this.config.elitism) {
duplicate3 = this.previousExperiment(key3);
}
if (!duplicate3) {
unique.add(key3);
} else {
console.error(
`Can't deDuplicate creature at ${i} of ${creatures.length}`,
);
creatures.splice(i, 1);
i--;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/architecture/ElitismUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function logVerbose(creatures: Creature[]) {
const error = getTag(creature, "error");
const diff = Number.parseFloat(sourceError ?? "99999") -
Number.parseFloat(error ?? "99999");
const dnaID = getTag(sourceCreature, "CRISPR-DNA");
const dnaID = getTag(creature, "CRISPR-DNA");

console.info(
`CRISPR ${blue(dnaID ?? "unknown")} Score: ${
Expand Down

0 comments on commit f2b6154

Please sign in to comment.