fix: address code review findings
This commit is contained in:
@@ -418,21 +418,21 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
||||
|
||||
newDurationWithMCT := newDuration + transferTime
|
||||
|
||||
// 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
|
||||
|
||||
newTransfers := current.transfers
|
||||
if edge.IsTransfer {
|
||||
newTransfers++
|
||||
}
|
||||
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if newTransfers > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = newTransfers
|
||||
|
||||
// Build new itinerary legs
|
||||
newLegs := make([]RouteLeg, len(current.itinerary.Legs)+1)
|
||||
copy(newLegs, current.itinerary.Legs)
|
||||
@@ -831,27 +831,6 @@ func (g *Graph) ApplyMCT(itinerary *Itinerary, mctBase int) *Itinerary {
|
||||
|
||||
// Add the MCT to the total duration (as waiting time at transfer)
|
||||
totalMCT += mct
|
||||
}
|
||||
|
||||
// Update leg durations to include MCT for transfer legs
|
||||
for i := 1; i < len(adjustedLegs); i++ {
|
||||
prevLeg := &adjustedLegs[i-1]
|
||||
currLeg := &adjustedLegs[i]
|
||||
|
||||
// Determine MCT based on node types and transfer kinds
|
||||
mct := mctBase
|
||||
|
||||
// Reduce MCT for city hub transfers (the transfer point node is a city)
|
||||
// The transfer point is the destination of the previous leg / start of current leg
|
||||
transferPoint := prevLeg.To // = currLeg.From
|
||||
if transferPoint.Type == NodeTypeCity {
|
||||
mct = mctBase / 2 // 30 min -> 15 min for city hub transfers
|
||||
}
|
||||
|
||||
// Increase MCT for mode changes (different transport types)
|
||||
if prevLeg.Transport != currLeg.Transport {
|
||||
mct = mctBase + 600 // 30 min + 10 min for mode change
|
||||
}
|
||||
|
||||
// Add MCT to the current leg's duration (transfer wait time)
|
||||
adjustedLegs[i].Duration += mct
|
||||
|
||||
Reference in New Issue
Block a user