Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CRISPR functionality and fix DNA ID retrieval in ElitismUtil… #357

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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