• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Google Maps TSP Solver. A fork of Geir Engdahl's TSP solver located at: https://code.google.com/p/google-maps-tsp-solver

Google-Maps-TSP-Solver

Google Maps TSP Solver that computes the fastest route that visits a given set of locations using JavaScript. It's a fork of Geir Engdahl's TSP Solver project, but is/will be optimized for headless environments (node.js, Titanium) multiple APIs.

Work in progress.

Algorithms

Different algorithms are selected based on the number of input locations, in order to produce results in a responsive manner. For large sets of points, the returned solution will be approximate. It is an NP-complete problem after all.

  • tspK3 - Uses 3-opt algorithm to find a good solution to the TSP. The 3-opt algorithm is a local optimization technique similar to the 2-opt step which is performed after each wave of ants in the ant colony solver. Since 3-opt is much more expensive than 2-opt, it's too slow to use it after each ant wave. But it is used after the ant colony / 2-opt combo is done, and usually improves the solution quite a bit. The solution quality is never degraded by this step.

  • tspAntColonyK2 - Computes a near-optimal solution to the TSP problem, using Ant Colony Optimization and local optimization in the form of k2-opting each candidate route.

  • tspBruteForce - Returns the optimal solution to the TSP problem. If mode is 1, it will return the optimal solution to the related problem of finding a path from node 0 to node numActive - 1, visiting the in-between nodes in the best order.

###Usage

// Your normal Google Map object initialization
var myOptions = {
  zoom: zoom,
  center: center,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
myMap = new google.maps.Map(div, myOptions);
directionsPanel = document.getElementById("my_textual_div");

// Create the tsp object
tsp = new BpTspSolver(myMap, directionsPanel);

// Set your preferences
tsp.setAvoidHighways(true);
tsp.setTravelMode(google.maps.DirectionsTravelMode.WALKING);

// Add points (by coordinates, or by address).
// The first point added is the starting location.
// The last point added is the final destination (in the case of A - Z mode)
tsp.addWaypoint(latLng, addWaypointCallback);  // Note: The callback is new for version 3, to ensure waypoints and addresses appear in the order they were added in.
tsp.addAddress(address, addAddressCallback);

// Solve the problem (start and end up at the first location)
tsp.solveRoundTrip(onSolveCallback);
// Or, if you want to start in the first location and end at the last,
// but don't care about the order of the points in between:
tsp.solveAtoZ(onSolveCallback);

// Retrieve the solution (so you can display it to the user or do whatever :-)
var dir = tsp.getGDirections();  // This is a normal GDirections object.
// The order of the elements in dir now correspond to the optimal route.

// If you just want the permutation of the location indices that is the best route:
var order = tsp.getOrder();

// If you want the duration matrix that was used to compute the route:
var durations = tsp.getDurations();

// There are also other utility functions, see the source.

Original source is located at: https://code.google.com/p/google-maps-tsp-solver/

License

MIT

Authors

  • James Tolley <info [at] gmaptools.com>
  • Geir K. Engdahl <geir.engdahl (at) gmail.com>

More Repositories

1

Ti-Amazon-S3

Amazon S3 CommonJS module for Appcelerator Alloy / Titanium SDK
JavaScript
59
star
2

TiUIExamples

Titanium UI Examples using JavaScript Modules (commonJS)
JavaScript
36
star
3

TiEventKit

Ti.EventKit brings in iOS EventKit into the Titanium namespace. You can add events to iOS apps using the native calendar app.
Python
30
star
4

Ti-Double-Slider

A native iOS double slider for Titanium Mobile.
Objective-C
27
star
5

SPStatusOverlay

A custom iOS status bar overlay for Titanium Mobile, based on the MTStatusBarOverlay project.
Objective-C
24
star
6

sp.signature

Titanium Alloy widget for capturing signatures easy peasy lemon squeezy. Converts to SVG format.
JavaScript
23
star
7

SimPushServer

Titanium SimPushServer
Objective-C
17
star
8

Ti-iSimulate

An iOS module for embedding iSimulate within a Titanium project
Python
12
star
9

TiAnimations

A kitchen sink for Titanium animation effects
JavaScript
9
star
10

SigCanvas

Drawing on a CANVAS element within Titanium Mobile
JavaScript
8
star
11

stablecode-vscode

StableCode VSCode extension (WIP)
8
star
12

Turntable.fm-SSB

A single site browser (SSB) Mac app for TurnTable.fm, built with node-webkit.
4
star
13

gae-php-hybridauth

Standardized multi-provider authentication for Google App Engine, based on HybridAuth.
PHP
2
star
14

Googly-App-Template

A web app HTML + CSS template that looks slightly Googl-y.
2
star
15

gae-python.docset

Docset for Google App Engine - Python APIs
CSS
1
star
16

TiGoogle

Titanium CLI plugin for Google APIs
1
star
17

gitmarks_tzm

My Gitmarks
1
star
18

WPMU-Clean-State

Wordpress as a CMS framework, not a blogging app.
1
star
19

gae-instantapi

Instant API for Google App Engine --> Convert a JSON file into REST endpoints
Python
1
star