Metaheuristic code bricks for JavaScript.
for ( const [ candidate , fitness ] of localsearch( [ solution , best ] ) ) ... ;
Can be managed through jspm, duo, component, bower, ender, jam, spm, and npm.
jspm install github:aureooms/js-metaheuristics # or jspm install npm:aureooms-js-metaheuristics
No install step needed for duo!
component install aureooms/js-metaheuristics
bower install aureooms-js-metaheuristics
ender add aureooms-js-metaheuristics
jam install aureooms-js-metaheuristics
spm install aureooms-js-metaheuristics --save
npm install aureooms-js-metaheuristics --save
let metaheuristics = require( "github:aureooms/js-metaheuristics" ) ; // or import metaheuristics from 'aureooms-js-metaheuristics' ;
let metaheuristics = require( "aureooms/js-metaheuristics" ) ;
let metaheuristics = require( "aureooms-js-metaheuristics" ) ;
The script tag exposes the global variable metaheuristics
.
<script src="bower_components/aureooms-js-metaheuristics/js/dist/metaheuristics.min.js"></script>
Alternatively, you can use any tool mentioned here.
require( [ "aureooms-js-metaheuristics" ] , function ( metaheuristics ) { ... } ) ;
let fitness = evaluate( solution , mutation ) ;
apply( solution , mutation ) ;
for ( const mutation of walk( solution ) ) ... ;
if ( accept( fitness , best ) ) ... ;
The signature of a pivoting method is the following
let [ mutation , fitness ] = pivoting( [ solution , best ] , walk , evaluate ) ;
Global and local search methods either halt or loop forerver. In order to maintain a fine-grained step count, every step of the search method will yield a solution. This means there will be a lot of repetitions.
You can iterate over all candidates
for ( const [ candidate , fitness ] of localsearch( [ solution , best ] ) ) ... ;
To keep only the best candidate, maximize over fitness
import { increasing , attr } from 'aureooms-js-compare' ; import { max } from 'aureooms-js-itertools' ; let [ candidate , fitness ] = max( attr( increasing , 1 ) , localsearch( [ solution , best ] ) ) ;
For non-halting methods you can restrict your search to the first n
candidates
import { head } from 'aureooms-js-itertools' ; for ( const [ candidate , fitness ] of head( localsearch( solution , best ) , n ) ) ... ;
The same is valid for selecting the best of the first n
candidates
import { increasing , attr } from 'aureooms-js-compare' ; import { head , max } from 'aureooms-js-itertools' ; let [ candidate , fitness ] = max( attr( increasing , 1 ) , head( localsearch( [ solution , best ] ) , n ) ) ;