-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cosmetic -- Removed biological term jargon to make the interface seem…
… more general
- Loading branch information
Showing
2 changed files
with
25 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
/** | ||
* @fileOverview | ||
* File contains the definitions for the Mutator class | ||
* @fileOverview File contains the definitions for the Mutator class | ||
* @author <a href="mailto:[email protected]">Pavan Tumati</a | ||
* @version 1.0.0 | ||
* @name ObjectMutator | ||
*/ | ||
|
||
/** | ||
|
@@ -11,31 +13,31 @@ class Mutator { | |
/** | ||
* @constructs Mutator | ||
* @description Constructs mutator object | ||
* @param {chromosome} The base object that gets mutated | ||
* @param {mutationGroup} The set of (joint) mutations to apply to a chromosome | ||
* @param {cullFunction} The function passed to a filter to remove any invalid/unwanted genes in the mutation set | ||
* @param {baseObject} The base object that gets mutated | ||
* @param {mutationGroup} The set of (joint) mutations to apply to a baseObject | ||
* @param {cullFunction} The function passed to a filter to remove any invalid/unwanted mutations to the baseObject | ||
*/ | ||
constructor( chromosome, mutationGroup, cullFunction ) { | ||
constructor( baseObject, mutationGroup, cullFunction ) { | ||
this.mutations = []; | ||
this.chromosome = chromosome; | ||
this.baseObject = baseObject; | ||
|
||
this.assertGenesToMutatePresent( mutationGroup ); | ||
this.assertKeysToMutatePresent( mutationGroup ); | ||
function generateMutations( chromosome, mutationGroup ) { | ||
function internalGenerateMutations( mutationGroup ) { | ||
let mutationGroupClone = mutationGroup.slice(0); | ||
let frameGene = mutationGroupClone.shift(); | ||
let frameObject = mutationGroupClone.shift(); | ||
|
||
let nextGeneration = []; | ||
for( let i = frameGene.start; frameGene.checkRange(i); i = frameGene.step(i) ) { | ||
for( let i = frameObject.start; frameObject.checkRange(i); i = frameObject.step(i) ) { | ||
if( mutationGroupClone.length > 0 ) { | ||
let subMutations = internalGenerateMutations( mutationGroupClone ); | ||
nextGeneration.push.apply( nextGeneration, subMutations.map( (submutation ) => { | ||
submutation[ frameGene.gene ] = i; | ||
submutation[ frameObject.targetKey ] = i; | ||
return submutation; | ||
})); | ||
} else { | ||
let mutation = {}; | ||
mutation[ frameGene.gene ] = i; | ||
mutation[ frameObject.targetKey ] = i; | ||
nextGeneration.push( mutation ); | ||
} | ||
} | ||
|
@@ -52,8 +54,8 @@ class Mutator { | |
}; | ||
|
||
this.mutations = (typeof( cullFunction ) === 'function') ? | ||
generateMutations( chromosome, mutationGroup ).filter( cullFunction ) : | ||
generateMutations( chromosome, mutationGroup ); | ||
generateMutations( baseObject, mutationGroup ).filter( cullFunction ) : | ||
generateMutations( baseObject, mutationGroup ); | ||
} | ||
|
||
/** | ||
|
@@ -62,10 +64,10 @@ class Mutator { | |
* | ||
* @param {mutationGroup} Mutation group that needs to be checked | ||
*/ | ||
assertGenesToMutatePresent( mutationGroup ) { | ||
assertKeysToMutatePresent( mutationGroup ) { | ||
mutationGroup.forEach(element => { | ||
if( !this.chromosome.hasOwnProperty( element.gene ) ) | ||
throw Error( `Missing gene ${ element.gene }` ); | ||
if( !this.baseObject.hasOwnProperty( element.targetKey ) ) | ||
throw Error( `Missing gene ${ element.targetKey }` ); | ||
}); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters