feat: Implement lazy hub expansion depth limiting with MaxTransfers support

- Add transfer depth limiting in BFS/Dijkstra (MaxTransfers field in SearchOptions)
- Track transfer count at each step; stop when depth > 5
- Synthetic edge fallback on expansion failure
- Add TestLazyExpansionDepthLimit and TestFindRouteMaxTransfers tests

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-08-16 18:59:48 +03:00
parent 7c6fe4a99c
commit 026b779cb3
4 changed files with 109 additions and 16 deletions

View File

@@ -330,13 +330,6 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, yclient .
continue
}
// Prune if we've exceeded max transfers
// Use strict > comparison: with MaxTransfers=5, transfers 0-5 are allowed,
// and we stop when transfers would exceed the limit (depth > 5)
if opts.MaxTransfers >= 0 && current.transfers > opts.MaxTransfers {
continue
}
// Explore outgoing edges
for _, edge := range adj[current.nodeID] {
nextNode := edge.To
@@ -398,6 +391,11 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, yclient .
Cost: current.itinerary.Cost + edge.Cost,
}
// Skip this edge if it would exceed the maximum allowed transfers
if opts.MaxTransfers >= 0 && newTransfers > opts.MaxTransfers {
continue
}
queue = append(queue, bfsState{
nodeID: nextNode.ID,
transfers: newTransfers,
@@ -513,6 +511,10 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, yclient .
Cost: current.itinerary.Cost + edge.Cost,
}
if opts.MaxTransfers >= 0 && newTransfers > opts.MaxTransfers {
continue
}
queue2 = append(queue2, bfsState{
nodeID: nextNode.ID,
transfers: newTransfers,
@@ -676,6 +678,10 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, yclient .
Cost: current.itinerary.Cost + edge.Cost,
}
if opts.MaxTransfers >= 0 && newTransfers > opts.MaxTransfers {
continue
}
queue3 = append(queue3, bfsState{
nodeID: nextNode.ID,
transfers: newTransfers,