tspsolver

Node adaptation of google-maps-tsp-solver (https://code.google.com/p/google-maps-tsp-solver/)

npm install tspsolver
1 downloads in the last week
37 downloads in the last month

tspsolver

Server-side node module adaptation of google-maps-tsp-solver (https://code.google.com/p/google-maps-tsp-solver/). Uses googlemaps node module.

More information on how the original was implemented:

https://code.google.com/p/google-maps-tsp-solver/

Example 1 - Round Trip using Express framework


var express = require('express');
var app = express();

app.get('/', function(req, res) {
    res.send("Use /route-optimizer")
})

app.all('/route-optimizer', function(req, res) {
    var tsp = require('tspsolver');

    if (req.method == "POST") {
        var addresses = req.body.address;
    } else if (typeof req.query.address !== "undefined") {
        var addresses = req.query.address;
    } else {
        res.send("No addresses specified!");
    }

    if (typeof addresses == "string") {
        var addressSingle = addresses;
        addresses = new Array();
        addresses.push(addressSingle);
    }

    for (var i=0;i<addresses.length;i++) {
        console.log("Adding address '"+addresses[i]+"'");
        tsp.addAddress(addresses[i]);
    }

    tsp.solveRoundTrip(function() {
        var embed_uri = tsp.createGoogleLink(true);
        var map_uri   = tsp.createGoogleLink();

        var send = {
            'addresses': addresses,
            'embed_uri': embed_uri,
            'map_uri' :  map_uri
        };

        console.log(send);
        res.send(send);
    })
})

app.listen(3000);

npm loves you