// Trap function with Fitness function signature
//
// Trap is a deceptive function that is used, concatenated, to test
// evolutionary algorithms.
// @license GPL v3
// @package nodeo
// @author J. J. Merelo <jjmerelo@gmail.com>
// To avoid uncomprehensible radix complaint at charAt
/*jshint -W065 */
/*jshint smarttabs:true */
var functions = require('./functions');
var trap = exports;
// Class definition
// ```
// var trap = new Trap.trap( { l: 3, a: 1, b:2, z = 2})
// ```
//
function Trap( options ) {
for ( var i in options ) {
this[i] = options[i];
}
Iif ( !this.l ) {
this.l = 3;
}
Iif ( !this.a ) {
this.a = 1;
}
Iif ( !this.b ) {
this.l = 2;
}
Iif ( !this.z ) {
this.a = this.l-1;
}
// Methods
this.apply = apply;
}
// Applies trap function to chromosome using instance values
function apply( chromosome ){
return functions.ltrap(chromosome, this.l, this.a, this.b, this.z);
}
trap.Trap = Trap;
|