Skip to content

Commit

Permalink
New release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Nov 3, 2024
1 parent 51cc4e4 commit 6fe79ba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genetic-search",
"version": "0.2.2",
"version": "0.2.3",
"description": "Multiprocessing genetic algorithm implementation library",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/classes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { multi, single } from "itertools-ts";
import { multi, set, single } from "itertools-ts";
import {
GeneticSearchConfig,
GeneticSearchStrategyConfig,
Expand Down Expand Up @@ -191,7 +191,7 @@ export class ComposedGeneticSearch<TGenome extends BaseGenome> implements Geneti
await eliminators.step();
}

this.final.population = [...this.final.population, ...this.bestGenomes];
this.final.population = [...set.distinct([...this.final.population, ...this.bestGenomes], (x) => x.id)];
return await this.final.step();
}

Expand Down
8 changes: 6 additions & 2 deletions tests/parabola/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
RunnerStrategyConfig,
ScoringStrategyInterface,
MultiprocessingRunnerStrategyConfig,
NextIdGetter,
NextIdGetter, BaseMutationStrategy, BaseMutationStrategyConfig,
} from "../../src";

export type ParabolaArgumentGenome = BaseGenome & {
Expand All @@ -36,7 +36,11 @@ export class ParabolaPopulateStrategy implements PopulateStrategyInterface<Parab
}
}

export class ParabolaMutationStrategy implements MutationStrategyInterface<ParabolaArgumentGenome> {
export class ParabolaMutationStrategy extends BaseMutationStrategy<ParabolaArgumentGenome, BaseMutationStrategyConfig> {
constructor() {
super({ probability: 1 });
}

mutate(genome: ParabolaArgumentGenome, newGenomeId: number): ParabolaArgumentGenome {
return { x: genome.x + Math.random() * 10 - 5, id: newGenomeId };
}
Expand Down

0 comments on commit 6fe79ba

Please sign in to comment.