kopt
v0.1.5
Published
K-opt algorithm (currently k = 2)
Downloads
5
Readme
Kopt algorithm written in Typescript
Sub goal:
- javascript library development with typescript, testing, linting, debugging
Usage
Install:
$ npm install --save kopt
Example:
var Kopt = require('Kopt');
// verteces
var vs = [
[0, 0],
[1, 4],
[2, 2],
[3, 2],
[3, 4],
[6, 0],
[7, 3],
[8, 4],
[9, 0]
];
// distance function
function f(u, v) {
return Math.sqrt(Math.pow(u[0] - v[0], 2) + Math.pow(u[1] - v[1], 2));
}
console.log(Kopt.two(Kopt.mkMatrix(vs, f)))
// => [ 0, 1, 4, 6, 7, 8, 5, 3, 2, 0 ]
Type definition:
declare namespace Kopt {
function two(mtrx: number[][]) : number[];
function mkMatrix<T>(vs: T[], f: ((u: T, v: T) => number)) : number[][];
}
Development
$ npm install
$ node_modules/.bin/typings install
$ npm start # run tsc, tslint, mocha (normal and debug), node-inspector from node-foreman
Debugger is available at http://127.0.0.1:8080/debug?port=5858.
Release
$ npm run release