Comparing version 0.2.2 to 0.2.3
@@ -12,2 +12,3 @@ import { IndividualConfig } from './individual.model'; | ||
private mateFn; | ||
readonly fullname: string; | ||
constructor(config: IndividualConfig); | ||
@@ -14,0 +15,0 @@ setFitness(): Promise<void>; |
@@ -17,2 +17,5 @@ "use strict"; | ||
class Individual { | ||
get fullname() { | ||
return `${this.name.first} ${this.name.last}`; | ||
} | ||
constructor(config) { | ||
@@ -22,3 +25,4 @@ this.entity = config.entity; | ||
first: chance.first(), | ||
last: typeof config.name !== 'undefined' && typeof config.name.last !== 'undefined' | ||
last: typeof config.name !== 'undefined' && | ||
typeof config.name.last !== 'undefined' | ||
? config.name.last | ||
@@ -33,3 +37,3 @@ : chance.last() | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.fitness = yield this.fitnessFn(this.entity); | ||
this.fitness = yield this.fitnessFn(this.entity, this.fullname); | ||
}); | ||
@@ -39,3 +43,3 @@ } | ||
const entity = this.entity; | ||
const mutated = this.mutateFn(entity); | ||
const mutated = this.mutateFn(entity, this.fullname); | ||
const config = this.makeConfig(mutated); | ||
@@ -47,3 +51,3 @@ return new Individual(config); | ||
const father = other.entity; | ||
const kids = this.mateFn(mother, father); | ||
const kids = this.mateFn(mother, father, this.fullname, other.fullname); | ||
const son = this.makeConfig(kids[0]); | ||
@@ -54,6 +58,3 @@ const daughter = this.makeConfig(kids[1]); | ||
}; | ||
return [ | ||
new Individual(son), | ||
new Individual(daughter) | ||
]; | ||
return [new Individual(son), new Individual(daughter)]; | ||
} | ||
@@ -60,0 +61,0 @@ makeConfig(entity) { |
export interface Fitness { | ||
(entity: any): number; | ||
(entity: any, name: string): number; | ||
} | ||
export interface Mutate { | ||
(entity: any): any; | ||
(entity: any, name: string): any; | ||
} | ||
export interface Mate { | ||
(mother: any, father: any): [any, any]; | ||
(mother: any, father: any, motherName: string, fatherName: string): [any, any]; | ||
} | ||
@@ -10,0 +10,0 @@ export interface IndividualConfig { |
{ | ||
"name": "evjs", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Generic genetic/evolution algorithm in JS", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36080
491