Route Optimization Engine

Same duty, shorter route.
Every time.

Route Optimization Engine re-sequences a crew's stops with Haversine distance, a Nearest-Neighbor seed tour, and 2-Opt local search — then hands back a shorter route and a ready-to-render map, in one call.

Haversine + 2-Opt
Live Route Map
Request / Response
Crew Routing Screen
app.totalapp.app/analytic-engines/route-optimization-engine
Route Optimization Engine
TotalApp
Haversine + 2-OptLive Route MapRequest / ResponseCrew Routing Screen
Same duty, shorter route. Every time.Route Optimization…
Haversine + 2-Opt
Haversine + 2-Opt
Haversine distance — great-circle km…
Nearest-Neighbor seed — starts at the…
Live Route Map
map.points — origin + every stop, each…
map.connector — a flat…
Request / Response
Send routeId, stops[], and an optional…
Get back optimizedStops…
Live Route Map
map.points — origin + every stop, each with an…
map.connector — a flat [lat,lng,lat,lng,...] array…
Feeds the same shared route-map component the…
Request / Response
Send routeId, stops[], and an optional origin…
Get back optimizedStops, totalDistanceKm, and map…
Crew Routing Screen
Optimize Route — sends the row's stops to the…
View on Map — draws the route's current stops…
Server-side calculation keeps route data and the…
Route Optimization…

An approximate TSP solver built…

map.points — origin +…✓
map.connector — a flat…✓
Feeds the same shared…✓
Try Route…
Route Optimization Engine re-sequences a crew's stops…
Route Optimization…
Haversine + 2-Opt
Live Route Map
Request / Response
Crew Routing Screen
Route Optimization Engine AI
Route Optimization Engine re-sequences a crew's stops with Haversine distance, a Nearest-Neighbor seed tour, and 2-Opt…
Try Route Optimization
An approximate TSP solver built…Live Route Map
Haversine + 2-Opt

An approximate TSP
solver built for real crews

Every "Optimize Route" click runs the same three-step heuristic: measure real-world distance between every stop, build a fast greedy tour, then locally refine it until no swap shortens it further.

  • ✓
    Haversine distance — great-circle km between any two lat/lng points, using Earth's real radius (6,371 km)
  • ✓
    Nearest-Neighbor seed — starts at the origin hub, always jumps to the closest unvisited stop next
  • ✓
    2-Opt refinement — repeatedly reverses tour segments whenever that shortens total distance, undoing the seed tour's bad jumps
  • ✓
    O(n²) — instant for the 2–15 stop routes a real field crew actually runs in a day
Open Crew Routing
Before — unordered
78.4 km
After — optimized
H1234
51.2 km
−34.7%
distance
Approximate TSP solverBuilt for real crews.
Live Route Map

A map payload,
ready to render

The optimized tour comes back pre-packaged in AnyChart connector-map format — numbered points plus a flat lat/lng connector series — so the client never has to transform anything before drawing it.

  • ✓
    map.points — origin + every stop, each with an order index for numbered pins
  • ✓
    map.connector — a flat [lat,lng,lat,lng,...] array plus short/full tooltip text
  • ✓
    Feeds the same shared route-map component the Fleet module already uses
  • ✓
    "View on Map" stays independent — it draws the current stops without calling the optimizer at all
View a Route on the Map
Route payloadBoston Hub → 4 stops
H1234
Total51.2 km
Stops4
Ready to renderpoints + connectors.
Request / Response

One call in,
one route out

A single POST /api/en/crew-routing/optimize takes the route's stops and returns the re-sequenced list, the new total distance, and the ready-to-draw map — no side effects, no partial writes.

  • ✓
    Send routeId, stops[], and an optional origin lat/lng
  • ✓
    Get back optimizedStops, totalDistanceKm, and map in one response
  • ✓
    No origin coordinates supplied? Defaults to Boston Hub automatically
  • ✓
    Pure calculation — the engine never writes to disk; the client saves the result
Read the Full API Docs
request → response
1POST /api/en/crew-routing/optimize
2{ "routeId": "rt_204",
3 "stops": [ … ×5 ] }
1// 200 OK
2{ "optimizedStops": [ … ],
3 "totalDistanceKm": 51.2,
4 "map": { points, connector } }
Errors
401 unauthenticated
400 bad JSON
One call in, one route outJSON.
Crew Routing Screen

Built for
Energy & Utilities field crews

Crew Routing (Energy & Utilities → Field & Dispatch Operations) is the one screen that calls this engine. One "Optimize Route" click per route row does the rest.

  • ✓
    Optimize Route — sends the row's stops to the engine, re-sequences them, and saves the new order + distance
  • ✓
    View on Map — draws the route's current stops directly, independent of optimization
  • ✓
    Server-side calculation keeps route data and the optimizer in the same backend layer
  • ✓
    Swapping in a real Directions API later only touches this one engine file
Explore Energy & Utilities
Field Dispatch Operations3 active routes
RouteStopsDist.
Route — North Grid551.2 km🪄 Optimize
Route — Substation B322.7 kmView map
Route — Meter Sweep764.9 km🪄 Optimize
Saved this week
212 km
Built for Energy & UtilitiesField crews, optimized.