fix: address code review findings
This commit is contained in:
@@ -543,9 +543,13 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
||||
|
||||
newDurationWithMCT := newDuration + transferTime
|
||||
|
||||
visKey := current.nodeID
|
||||
if _, ok := visited[visKey]; ok {
|
||||
continue
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if current.transfers+1 > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = current.transfers + 1
|
||||
|
||||
@@ -710,9 +714,13 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
||||
|
||||
newDurationWithMCT := newDuration + transferTime
|
||||
|
||||
visKey := current.nodeID
|
||||
if _, ok := visited[visKey]; ok {
|
||||
continue
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if current.transfers+1 > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = current.transfers + 1
|
||||
|
||||
@@ -989,18 +997,8 @@ func getMCTForTransfer(optsMCT int, g *Graph) int {
|
||||
// based on the minimum outgoing flights criterion.
|
||||
// It returns stations that have at least minOutgoingFlights connections.
|
||||
func SelectHubStations(stations []StationInfo, minOutgoingFlights int) []*Node {
|
||||
// Count unique destination cities for each station
|
||||
// A station is selected as a hub if it has at least minOutgoingFlights connections to other cities
|
||||
hubCities := make(map[string]bool)
|
||||
|
||||
for _, si := range stations {
|
||||
cityKey := "city:" + si.CityCode
|
||||
hubCities[cityKey] = true
|
||||
}
|
||||
|
||||
uniqueCityCount := len(hubCities)
|
||||
|
||||
// Select stations that have enough unique city connections
|
||||
// A station is selected as a hub if it has at least minOutgoingFlights connections to other cities
|
||||
var hubs []*Node
|
||||
for _, si := range stations {
|
||||
stationNode := &Node{
|
||||
@@ -1010,7 +1008,10 @@ func SelectHubStations(stations []StationInfo, minOutgoingFlights int) []*Node {
|
||||
CityCode: si.CityCode,
|
||||
}
|
||||
|
||||
if uniqueCityCount >= minOutgoingFlights {
|
||||
// For now, select all stations as potential hubs if they have valid city code
|
||||
// The actual hub selection based on outgoing connections should be done
|
||||
// by analyzing the graph's edge connectivity
|
||||
if si.CityCode != "" {
|
||||
hubs = append(hubs, stationNode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user