Skip to content

Commit 2d61de4

Browse files
committed
fix local nxm search
1 parent b53af98 commit 2d61de4

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

bidirectional_ch_n_to_n.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ func (graph *Graph) initShortestPathManyToMany(endpointCounts [directionsCount]i
3030
queues[d] = make([]*vertexDistHeap, endpointCounts[d])
3131
for endpointIdx := 0; endpointIdx < endpointCounts[d]; endpointIdx++ {
3232
queryDist[d][endpointIdx] = make(map[int64]float64)
33-
for i := range queryDist[d][endpointIdx] {
34-
queryDist[d][endpointIdx][i] = Infinity
35-
}
3633
processed[d][endpointIdx] = make(map[int64]bool)
3734
queues[d][endpointIdx] = &vertexDistHeap{}
3835
heap.Init(queues[d][endpointIdx])
@@ -129,8 +126,12 @@ func (graph *Graph) directionalSearchManyToMany(d direction, endpointIndex int,
129126
if !ok {
130127
localDist = Infinity
131128
}
129+
localDistTemp, ok := localQueryDist[temp]
130+
if !ok {
131+
localDistTemp = Infinity
132+
}
132133
alt := localDist + cost
133-
if localQueryDist[temp] > alt {
134+
if localDistTemp > alt {
134135
localQueryDist[temp] = alt
135136
prev[temp] = vertex.id
136137
node := &vertexDist{

bidirectional_ch_n_to_n_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ func TestManyToManyShortestPath(t *testing.T) {
3333
// t.Log("ShortestPathManyToMany returned", ans, path)
3434
for sourceIdx := range u {
3535
for targetIdx := range v {
36-
// @failing
3736
if correctPath[sourceIdx][targetIdx] != -2 && len(path[sourceIdx][targetIdx]) != correctPath[sourceIdx][targetIdx] {
3837
t.Errorf("Num of vertices in path should be %d, but got %d", correctPath[sourceIdx][targetIdx], len(path[sourceIdx][targetIdx]))
3938
return
4039
}
41-
// @failing
4240
if correctAns[sourceIdx][targetIdx] != -2 && math.Abs(ans[sourceIdx][targetIdx]-correctAns[sourceIdx][targetIdx]) > eps {
4341
t.Errorf("Cost of path should be %f, but got %f", correctAns[sourceIdx][targetIdx], ans[sourceIdx][targetIdx])
4442
return
@@ -197,7 +195,6 @@ func TestManyToManyAlternatives(t *testing.T) {
197195
}
198196
}
199197
correctCost := 4.0
200-
// @failing
201198
if math.Abs(ans[0][0]-correctCost) > eps {
202199
t.Errorf("Cost of path should be %f, but got %f", correctCost, ans[0][0])
203200
return

0 commit comments

Comments
 (0)