# node-tspsolver

> TSP solver

Latest version **1.0.2** (published 2019-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-tspsolver
pnpm add node-tspsolver
yarn add node-tspsolver
bun add node-tspsolver
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-08-26 |
| First published | 2016-11-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=5.0.0 |
| Dependencies | 3 |
| Unpacked size | 117.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 14 |
| Author | Saby |
| Maintainers | saby |

## Links

- npm: https://www.npmjs.com/package/node-tspsolver
- Repository: https://github.com/saby-echo/node-tspsolver
- Homepage: https://github.com/saby-echo/node-tspsolver#readme
- Issues: https://github.com/saby-echo/node-tspsolver/issues
- npm.io page: https://npm.io/package/node-tspsolver

## Dependencies (3)

- [nan](https://npm.io/package/nan.md) ^2.14.0
- [bindings](https://npm.io/package/bindings.md) ^1.5.0
- [node-gyp](https://npm.io/package/node-gyp.md) ^5.0.3

## Recent versions

- 1.0.2 (latest) — 2019-08-26
- 1.0.1 — 2017-05-06
- 1.0.0 — 2017-05-06
- 0.0.8 — 2017-03-11
- 0.0.7 — 2017-03-11
- 0.0.6 — 2017-02-22
- 0.0.5 — 2016-12-11
- 0.0.4 — 2016-12-11
- 0.0.3 — 2016-11-25
- 0.0.2 — 2016-11-24
- 0.0.1 — 2016-11-24

## README

[![Build Status](https://travis-ci.org/saby1101/node-tspsolver.svg?branch=master)](https://travis-ci.org/saby1101/node-tspsolver)

# node-tspsolver
Travelling salesman solver for nodejs

This solver uses Simulated Annealing with optional periodic reheating.

Initial solution is constructed using Nearest Neighbour heuristic.

Tour transformations used in the local search step: Stochastic 2-opt, translation and swapping.

The solver is implemented in C++ and doesn't use the nodejs main event loop for running, hence non-blocking.

<strong>Signature:</strong>

`function solveTsp(costMatrix, roundtrip, options)` returns a promise

<strong>Arguments:</strong>

`costMatrix` - 2d array of costs .. costMatrix[i][j] gives cost between ith and jth points

`roundtrip` - whether salesman needs to get back to starting point, ie point at index 0. If false, point at n - 1 is treated as the end point

`options` - {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;N - 'number of iterations' default: 1000000, <br/>
&nbsp;&nbsp;&nbsp;&nbsp;T - 'Initial temperature' default: 100, <br/>
&nbsp;&nbsp;&nbsp;&nbsp;lambda - 'Annealing parameter' default: 0.985, <br/>
&nbsp;&nbsp;&nbsp;&nbsp;reheatInterval - 100000, <br/>
} <br/>

## Install:
<code>npm install node-tspsolver</code><br/>
#### NOTE:
Since this is a C++ addon, it requires <strong>node-gyp</strong> to be properly configured in your machine. Please go through the instructions provided in https://github.com/nodejs/node-gyp to properly set it up for your platform.

## Examples:
<pre><code>

var solver = require('node-tspsolver')

var costMatrix = [
    [0, 1, 3, 4],
    [1, 0, 2, 3],
    [3, 2, 0, 5],
    [4, 3, 5, 0]
]

solver
    .solveTsp(costMatrix, true, {})
    .then(function (result)) {
        console.log(result) // result is an array of indices specifying the route.
    })

</code></pre>

---
_Source: https://npm.io/package/node-tspsolver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
