Socket
Socket
Sign inDemoInstall

@wemap/salesman.js

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @wemap/salesman.js

Solves the traveling salesman problem using simulated annealing.


Version published
Weekly downloads
8
decreased by-61.9%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

salesman

See: demo
Author: Ophir LOJKINE
Author: Thibaud MICHEL

salesman npm module Modified by Wemap (thibaud@getwemap.com) to add ts

Good heuristic for the traveling salesman problem using simulated annealing.

  • salesman
    • ~Point
    • ~solve(points, [temp_coeff], [callback], [callback])Array.<number>

salesman~Point

Kind: inner class of salesman

new Point(x, y)

Represents a point in two dimensions. Used as the input for solve.

ParamTypeDescription
xnumberabscissa
ynumberordinate

salesman~solve(points, [temp_coeff], [callback], [callback]) ⇒ Array.<number>

Solves the following problem: Given a list of points and the distances between each pair of points, what is the shortest possible route that visits each point exactly once and returns to the origin point?

Kind: inner method of salesman
Returns: Array.<number> - An array of indexes in the original array. Indicates in which order the different points are visited.

ParamTypeDefaultDescription
pointsArray.<Point>The points that the path will have to visit.
[temp_coeff]number0.999changes the convergence speed of the algorithm. Smaller values (0.9) work faster but give poorer solutions, whereas values closer to 1 (0.99999) work slower, but give better solutions.
[callback]functionAn optional callback to be called after each iteration.
[callback]functioneuclideanAn optional argument to specify how distances are calculated. The function takes two Point objects as arguments and returns a number for distance. Defaults to simple Euclidean distance calculation.

Example

var points = [
      new salesman.Point(2,3)
      //other points
    ];
var solution = salesman.solve(points);
var ordered_points = solution.map(i => points[i]);
// ordered_points now contains the points, in the order they ought to be visited.

Keywords

FAQs

Last updated on 16 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc