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

@@ -172,11 +172,34 @@ func RouteSearch(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
// In a full implementation, would search routes using the graph and Yandex API
// For now, return a simple JSON response
// Build query parameters for route search
// Use city codes as origin/destination identifiers
// In a full implementation, this would use Yandex /search, but for now
// we use the in-memory graph with Pareto-optimal routing
// Create search options with default max transfers
opts := routing.SearchOptions{
MaxTransfers: 5,
}
// Run Pareto-optimal route search using the graph
results := hc.Router.FindRoutesPareto(req.FromCityID, req.ToCityID, opts)
// Build response routes
routeResponses := make([]interface{}, 0, len(results))
for _, route := range results {
routeResponses = append(routeResponses, map[string]interface{}{
"duration": route.TotalDuration,
"transfers": route.TotalTransfers,
"cost": route.Cost,
"id": route.ID,
})
}
resp := routeSearchResponse{
Routes: []interface{}{},
Count: 0,
Routes: routeResponses,
Count: len(routeResponses),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)