@wemap/routers 11.0.0 → 11.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -700,11 +700,14 @@ let OsmGraph = _OsmGraph;
700
700
  __publicField(OsmGraph, "HIGHWAYS_PEDESTRIANS", HIGHWAYS_PEDESTRIANS);
701
701
  __publicField(OsmGraph, "DEFAULT_WAY_SELECTOR", DEFAULT_WAY_SELECTOR);
702
702
  const DEFAULT_OPTIONS = Object.assign({}, geo.GeoGraphRouter.DEFAULT_OPTIONS, {
703
- weightEdgeFn: (edge) => edge.data instanceof osm.OsmNode && edge.data.isElevator ? 30 : getDurationFromLength(edge.length)
703
+ weightEdgeFn: (edge) => edge.data instanceof osm.OsmNode && edge.data.isElevator ? 90 : getDurationFromLength(edge.length)
704
704
  });
705
705
  const WITHOUT_STAIRS_OPTIONS = Object.assign({}, DEFAULT_OPTIONS, {
706
706
  acceptEdgeFn: (edge) => edge.data.tags.highway !== "steps"
707
707
  });
708
+ const DEFAULT_TRIP_OPTIONS = Object.assign({}, {
709
+ tspTempCoeff: 0.99
710
+ }, geo.GeoGraphRouter.DEFAULT_OPTIONS);
708
711
  const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previousStep) => {
709
712
  var _a, _b, _c, _d, _e;
710
713
  const edges = graphItinerary.edges;
@@ -789,14 +792,14 @@ class WemapOsmRouter extends geo.GeoGraphRouter {
789
792
  }
790
793
  return { direction, directionExtra };
791
794
  }
792
- getShortestTrip(waypoints, options = DEFAULT_OPTIONS) {
795
+ getShortestTrip(waypoints, options = DEFAULT_TRIP_OPTIONS) {
793
796
  const points = waypoints.map((waypoint) => {
794
797
  const point = new salesman__default.default.Point(0, 0);
795
798
  point.coords = waypoint;
796
799
  return point;
797
800
  });
798
801
  const cache = [];
799
- const solution = salesman__default.default.solve(points, 0.9, void 0, (p, q) => {
802
+ const solution = salesman__default.default.solve(points, options.tspTempCoeff, void 0, (p, q) => {
800
803
  const osmItinerary = this.getShortestPath(
801
804
  p.coords,
802
805
  q.coords,
@@ -807,9 +810,9 @@ class WemapOsmRouter extends geo.GeoGraphRouter {
807
810
  });
808
811
  const orderedPoints = solution.map((i) => points[i]);
809
812
  const orderedItineraries = [];
810
- for (let i = 0; i < orderedPoints.length - 1; i++) {
813
+ for (let i = 0; i < orderedPoints.length; i++) {
811
814
  const p = orderedPoints[i];
812
- const q = orderedPoints[i + 1];
815
+ const q = orderedPoints[(i + 1) % orderedPoints.length];
813
816
  let cachedItinerary = cache.find((itinerary) => itinerary.start === p.coords && itinerary.end === q.coords || itinerary.end === p.coords && itinerary.start === q.coords);
814
817
  if (cachedItinerary.end === p.coords) {
815
818
  cachedItinerary = geo.GeoGraphItinerary.fromGraphVertices(
@@ -823,7 +826,7 @@ class WemapOsmRouter extends geo.GeoGraphRouter {
823
826
  }
824
827
  return orderedItineraries;
825
828
  }
826
- getTripItinerary(waypoints, options = DEFAULT_OPTIONS) {
829
+ getTripItinerary(waypoints, options = DEFAULT_TRIP_OPTIONS) {
827
830
  const shortestTrip = this.getShortestTrip(waypoints, options);
828
831
  return new Itinerary({
829
832
  from: shortestTrip[0].start,
@@ -1814,7 +1817,11 @@ class WemapMultiRouter {
1814
1817
  return ioMapsToTest;
1815
1818
  }
1816
1819
  convertOptionsToWemapOsmOptions(options) {
1817
- return !options || !("useStairs" in options) || options.useStairs ? WemapOsmRouter.DEFAULT_OPTIONS : WemapOsmRouter.WITHOUT_STAIRS_OPTIONS;
1820
+ const outputOptions = !options || !("useStairs" in options) || options.useStairs ? WemapOsmRouter.DEFAULT_OPTIONS : WemapOsmRouter.WITHOUT_STAIRS_OPTIONS;
1821
+ if (typeof (options == null ? void 0 : options.tspTempCoeff) !== "undefined") {
1822
+ outputOptions.tspTempCoeff = options.tspTempCoeff;
1823
+ }
1824
+ return outputOptions;
1818
1825
  }
1819
1826
  async getTrip(mode, waypoints, options = null) {
1820
1827
  const ioMapsToTest = this.getIoMapsFromOptions(options);