@@ -272,6 +272,7 @@ tp-lib/
272272│ ├── src/
273273│ │ ├── models/ # Data models
274274│ │ ├── projection/ # Projection algorithms
275+ │ │ ├── path/ # Train path calculation
275276│ │ ├── io/ # Input/output parsers
276277│ │ ├── crs/ # Coordinate transformations
277278│ │ └── temporal/ # Timezone utilities
@@ -282,6 +283,87 @@ tp-lib/
282283 └── python/tests/ # Python tests
283284```
284285
286+ ## Train Path Calculation Development
287+
288+ When working on path calculation features (` tp-core/src/path/ ` ):
289+
290+ ### Architecture Overview
291+
292+ The path calculation module consists of several submodules:
293+
294+ - ** ` candidate.rs ` ** : Find candidate netelements for each GNSS position
295+ - ** ` probability.rs ` ** : Calculate HMM-related probabilities (e.g., emission/transition) using distance, heading, and network context
296+ - ** ` viterbi.rs ` ** : Run the HMM/Viterbi algorithm to compute the most likely train path from the candidate sequences
297+ - ** ` graph.rs ` ** : Network topology graph operations
298+ - ** ` spacing.rs ` ** : GNSS resampling for consistent spacing
299+
300+ ### Key Functions
301+
302+ ``` rust
303+ // Main entry point
304+ calculate_train_path (gnss_positions , netelements , netrelations , config ) -> PathResult
305+
306+ // Project onto pre-calculated path
307+ project_onto_path (gnss_positions , path , netelements , config ) -> Vec <ProjectedPosition >
308+ ```
309+
310+ ### Algorithm Flow
311+
312+ 1 . ** Candidate Selection** (` find_candidate_netelements ` )
313+ - Uses R-tree spatial index for O(log n) lookup
314+ - Filters by ` cutoff_distance ` and ` max_candidates `
315+
316+ 2 . ** Probability Calculation** (` calculate_combined_probability ` )
317+ - Distance probability: ` exp(-distance / distance_scale) `
318+ - Heading probability: ` exp(-heading_diff / heading_scale) `
319+ - Combined: ` distance_prob * heading_prob `
320+
321+ 3 . ** Path Construction** (` construct_forward_path ` , ` construct_backward_path ` )
322+ - Traverses network using netrelations (topology)
323+ - Builds path in both directions for validation
324+
325+ 4 . ** Path Selection** (` select_best_path ` )
326+ - Validates bidirectional agreement
327+ - Returns highest probability path
328+
329+ ### Testing Path Calculation
330+
331+ ``` bash
332+ # Run path calculation tests
333+ cargo test --workspace path
334+
335+ # Run integration tests
336+ cargo test --test tests path_calculation
337+
338+ # Run benchmarks
339+ cargo bench --bench projection_bench
340+ cargo bench --bench naive_baseline_bench
341+ ```
342+
343+ ### Creating coverage report
344+
345+ ``` bash
346+ cargo llvm-cov --lib -p tp-lib-core --html --output-dir target/coverage
347+ ```
348+
349+ ### Performance Targets
350+
351+ - ** SC-001** : 1000 positions × 50 netelements in <10 seconds
352+ - ** Current** : ~ 900μs (11,000× faster than target)
353+ - ** Memory** : <500MB for 10k+ positions
354+
355+ ### Configuration Parameters
356+
357+ | Parameter | Default | Purpose |
358+ | -----------| ---------| ---------|
359+ | ` distance_scale ` | 10.0 | Distance decay rate (meters) |
360+ | ` heading_scale ` | 2.0 | Heading decay rate (degrees) |
361+ | ` cutoff_distance ` | 500.0 | Max search distance (meters) |
362+ | ` heading_cutoff ` | 10.0 | Max heading difference (degrees) |
363+ | ` probability_threshold ` | 0.02 | Min probability for inclusion |
364+ | ` max_candidates ` | 3 | Max candidates per position |
365+ | ` resampling_distance ` | None | Optional GNSS resampling |
366+
285367## Constitution Principles
286368
287369TP-Lib follows strict architectural principles (see Constitution v1.1.0):
0 commit comments