@wemap/routers 12.1.0 → 12.2.0

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/index.ts CHANGED
@@ -23,8 +23,6 @@ export { default as NoRouteFoundError } from './src/graph/NoRouteFoundError.js';
23
23
 
24
24
  /* Wemap Router */
25
25
  export { default as OsmGraphUtils } from './src/wemap-osm/OsmGraphUtils.js';
26
- export { type OsmRouterOptions } from './src/wemap-osm/OsmRouterOptions.js';
27
-
28
26
  export { default as WemapMultiRouter } from './src/wemap-multi/WemapMultiRouter.js';
29
27
  export { default as CustomNetworkMap } from './src/wemap-multi/CustomNetworkMap.js';
30
28
 
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/routers"
13
13
  },
14
14
  "name": "@wemap/routers",
15
- "version": "12.1.0",
15
+ "version": "12.2.0",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -52,5 +52,5 @@
52
52
  },
53
53
  "./helpers/*": "./helpers/*"
54
54
  },
55
- "gitHead": "a9ae25d8931032e8779034182c62aa6af1528819"
55
+ "gitHead": "6dda458e79cb7bc9bb63de3db2d000823672c3ca"
56
56
  }
@@ -149,39 +149,7 @@ export default class GraphRouterEngine {
149
149
  }
150
150
  }
151
151
 
152
- // edges.forEach(edge => {
153
- // // if (edge.properties.isOneway) {
154
- // // console.log("isOneway")
155
- // // return edge.vertex1 == u
156
- // // } else {
157
- // // console.log(`${edge.id} => keep: ${cond} - ${JSON.stringify(edge.properties)} [f: ${firstPart}, s: ${secondPart}]`);
158
- // // }
159
- // // return edge.vertex1 == u || edge.vertex2 == u
160
- // const firstPart = edge.vertex1 == u;
161
- // const secondPart = !edge.properties.isOneway && edge.vertex2 == u;
162
- // const cond = edge.vertex1 == u || !edge.properties.isOneway && edge.vertex2 == u
163
- // console.log(`${edge.id} => keep: ${cond} - ${JSON.stringify(edge.properties)} [f: ${firstPart}, s: ${secondPart}]`);
164
- // })
165
-
166
- // const mEdges = edges
167
- // .filter(edge => edge.vertex1 == u || !edge.properties.isOneway && edge.vertex2 == u)
168
- // .map(edge => `${edge.id} - ${edge.properties.name}`)
169
- // console.log('_-------_')
170
- // console.log(`Processing vertex ${u.id} (${u.properties.name})`);
171
- // console.log(`Calc for edges: ${mEdges}`);
172
-
173
- // if (u.properties.name === 'p11') {
174
- // console.log(u);
175
- // }
176
-
177
-
178
152
  edges
179
- // .filter(edge => {
180
- // if (edge.properties.isOneway) {
181
- // return edge.vertex1 == u
182
- // }
183
- // return edge.vertex1 == u || edge.vertex2 == u
184
- // })
185
153
  .filter(edge => edge.vertex1 == u || !edge.properties.isOneway && edge.vertex2 == u)
186
154
  .forEach(edge => {
187
155
  const v = u === edge.vertex1 ? edge.vertex2 : edge.vertex1;
@@ -206,4 +174,43 @@ export default class GraphRouterEngine {
206
174
  ): GraphRouterEngineResults {
207
175
  return this.calculateShortestPathToMultipleDestinationsByVertex(source, [target], options, inputVertices, inputEdges);
208
176
  }
177
+
178
+ // https://en.wikipedia.org/wiki/Component_(graph_theory)
179
+ calculateComponents() {
180
+
181
+ function shiftSet<T>(set: Set<T>): T {
182
+ const firstValue = set.values().next().value as T;
183
+ set.delete(firstValue);
184
+ return firstValue;
185
+ }
186
+
187
+ const verticesToTest = new Set<Vertex>(this.graph.vertices);
188
+ let components: Vertex[][] = [];
189
+
190
+ while (verticesToTest.size > 0) {
191
+ const vertexToTest = shiftSet(verticesToTest);
192
+ const otherVertices = this.graph.vertices.filter(v => v.id !== vertexToTest.id);
193
+ const result = this.calculateShortestPathToMultipleDestinationsByVertex(vertexToTest, otherVertices);
194
+ const reachedVertices = otherVertices.filter(ov => result.weightedDistance(ov) !== null);
195
+
196
+ components.push([vertexToTest, ...reachedVertices]);
197
+ reachedVertices.forEach(rv => verticesToTest.delete(rv));
198
+ }
199
+
200
+ // As graph is ordered, fuse components with same vertices
201
+ for (let i = 0; i < components.length - 1; i++) {
202
+ const component1 = components[i];
203
+ for (let j = i + 1; j < components.length; j++) {
204
+ const component2 = components[j];
205
+ const componentsIntersect = component2.some(v => component1.includes(v));
206
+ if (componentsIntersect) {
207
+ component1.push(...component2);
208
+ components = components.filter(component => component !== component2);
209
+ }
210
+ }
211
+ }
212
+
213
+ return components.map(c => [... new Set(c)]);
214
+ }
215
+
209
216
  }
@@ -265,3 +265,28 @@ describe('OsmRouter - getTrip', () => {
265
265
  expect(router.getShortestTrip([p1, p2, p3, p4, p5, p6])).is.empty;
266
266
  });
267
267
  });
268
+
269
+
270
+ describe('OsmRouter - create graph components', () => {
271
+
272
+ const networkModel = loadGraph('components.osm');
273
+ const router = new GraphRouter(networkModel);
274
+
275
+ const arraysEqual = <T>(a: T[], b: T[]) => JSON.stringify(a.sort()) === JSON.stringify(b.sort());
276
+ const findComponent = (components: Vertex[][], vertexNames: string[]) =>
277
+ components.find(c => arraysEqual(c.map(v => v.properties.name), vertexNames))
278
+
279
+ it('createComponents()', () => {
280
+ const components = router.calculateComponents();
281
+
282
+ // console.log(JSON.stringify(components.map(c => c.map(v => v.properties.name)), null, 4));
283
+ expect(components.length).equal(6);
284
+ expect(findComponent(components, ['p1', 'p2', 'p3', 'p4'])).to.be.not.undefined;
285
+ expect(findComponent(components, ['p11', 'p12', 'p13'])).to.be.not.undefined;
286
+ expect(findComponent(components, ['p13', 'p14'])).to.be.not.undefined;
287
+ expect(findComponent(components, ['p21', 'p22'])).to.be.not.undefined;
288
+ expect(findComponent(components, ['p31', 'p32', 'p32', 'p33', 'p34'])).to.be.not.undefined;
289
+ expect(findComponent(components, ['p41', 'p42', 'p43', 'p44', 'p45', 'p46', 'p47', 'p48'])).to.be.not.undefined;
290
+ });
291
+
292
+ });
@@ -1,13 +0,0 @@
1
- // TODO: remove
2
- export type OsmRouterOptions = {
3
-
4
- useStairs?: boolean;
5
-
6
- useEscalators?: boolean;
7
-
8
- useElevators?: boolean;
9
-
10
- isTrip?: boolean;
11
-
12
- tspTempCoeff?: number;
13
- }