Skip to content

Commit

Permalink
fix local nxm search
Browse files Browse the repository at this point in the history
  • Loading branch information
LdDl committed Jun 6, 2023
1 parent b53af98 commit 2d61de4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 5 additions & 4 deletions bidirectional_ch_n_to_n.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ func (graph *Graph) initShortestPathManyToMany(endpointCounts [directionsCount]i
queues[d] = make([]*vertexDistHeap, endpointCounts[d])
for endpointIdx := 0; endpointIdx < endpointCounts[d]; endpointIdx++ {
queryDist[d][endpointIdx] = make(map[int64]float64)
for i := range queryDist[d][endpointIdx] {
queryDist[d][endpointIdx][i] = Infinity
}
processed[d][endpointIdx] = make(map[int64]bool)
queues[d][endpointIdx] = &vertexDistHeap{}
heap.Init(queues[d][endpointIdx])
Expand Down Expand Up @@ -129,8 +126,12 @@ func (graph *Graph) directionalSearchManyToMany(d direction, endpointIndex int,
if !ok {
localDist = Infinity
}
localDistTemp, ok := localQueryDist[temp]
if !ok {
localDistTemp = Infinity
}
alt := localDist + cost
if localQueryDist[temp] > alt {
if localDistTemp > alt {
localQueryDist[temp] = alt
prev[temp] = vertex.id
node := &vertexDist{
Expand Down
3 changes: 0 additions & 3 deletions bidirectional_ch_n_to_n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ func TestManyToManyShortestPath(t *testing.T) {
// t.Log("ShortestPathManyToMany returned", ans, path)
for sourceIdx := range u {
for targetIdx := range v {
// @failing
if correctPath[sourceIdx][targetIdx] != -2 && len(path[sourceIdx][targetIdx]) != correctPath[sourceIdx][targetIdx] {
t.Errorf("Num of vertices in path should be %d, but got %d", correctPath[sourceIdx][targetIdx], len(path[sourceIdx][targetIdx]))
return
}
// @failing
if correctAns[sourceIdx][targetIdx] != -2 && math.Abs(ans[sourceIdx][targetIdx]-correctAns[sourceIdx][targetIdx]) > eps {
t.Errorf("Cost of path should be %f, but got %f", correctAns[sourceIdx][targetIdx], ans[sourceIdx][targetIdx])
return
Expand Down Expand Up @@ -197,7 +195,6 @@ func TestManyToManyAlternatives(t *testing.T) {
}
}
correctCost := 4.0
// @failing
if math.Abs(ans[0][0]-correctCost) > eps {
t.Errorf("Cost of path should be %f, but got %f", correctCost, ans[0][0])
return
Expand Down

0 comments on commit 2d61de4

Please sign in to comment.