Skip to content

Commit

Permalink
fix shortest path bug (#5675)
Browse files Browse the repository at this point in the history
* fix shortest path bug

* fix case error

---------

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
nevermore3 and Sophie-Xie authored Aug 16, 2023
1 parent 18813f3 commit 7c32088
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 47 deletions.
3 changes: 3 additions & 0 deletions src/graph/executor/algo/BFSShortestPathExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ DataSet BFSShortestPathExecutor::doConjunct(const std::vector<Value>& meetVids,
Path result = leftPath.second;
result.reverse();
result.append(rightPath->second);
if (result.hasDuplicateEdges()) {
continue;
}
Row row;
row.emplace_back(std::move(result));
ds.rows.emplace_back(std::move(row));
Expand Down
13 changes: 7 additions & 6 deletions src/graph/executor/algo/MultiShortestPathExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ void MultiShortestPathExecutor::init() {
}
for (const auto& leftVid : leftVids) {
for (const auto& rightVid : rightVids) {
if (leftVid != rightVid) {
terminationMap_.emplace(leftVid, std::make_pair(rightVid, true));
}
terminationMap_.emplace(leftVid, std::make_pair(rightVid, true));
}
}
}
Expand Down Expand Up @@ -240,13 +238,16 @@ DataSet MultiShortestPathExecutor::doConjunct(
[this](const std::vector<Path>& leftPaths, const std::vector<Path>& rightPaths, DataSet& ds) {
for (const auto& leftPath : leftPaths) {
for (const auto& rightPath : rightPaths) {
if (++cnt_ > limit_) {
break;
}
auto forwardPath = leftPath;
auto backwardPath = rightPath;
backwardPath.reverse();
forwardPath.append(std::move(backwardPath));
if (forwardPath.hasDuplicateEdges()) {
continue;
}
if (++cnt_ > limit_) {
return;
}
Row row;
row.values.emplace_back(std::move(forwardPath));
ds.rows.emplace_back(std::move(row));
Expand Down
8 changes: 5 additions & 3 deletions tests/tck/features/path/ShortestPath.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ Feature: Integer Vid Shortest Path
| FIND SHORTEST PATH FROM $a.src TO $-.dst OVER like UPTO 5 STEPS YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")-[:like]->("Manu Ginobili")> |
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")> |
| p |
| <("Tim Duncan")-[:like@0{}]->("Manu Ginobili")> |
| <("Tim Duncan")-[:like@0{}]->("Tony Parker")-[:like@0{}]->("LaMarcus Aldridge")> |
| <("Tim Duncan")-[:like@0{}]->("Tony Parker")-[:like@0{}]->("Tim Duncan")> |
| <("Tim Duncan")-[:like@0{}]->("Manu Ginobili")-[:like@0{}]->("Tim Duncan")> |

Scenario: Integer Vid [1] Shortest Path With Limit
When executing query:
Expand Down
32 changes: 29 additions & 3 deletions tests/tck/features/path/ShortestPath.feature
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,11 @@ Feature: Shortest Path
| FIND SHORTEST PATH FROM $a.src TO $-.dst OVER like UPTO 5 STEPS YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")-[:like]->("Manu Ginobili")> |
| <("Tim Duncan")-[:like]->("Tony Parker")-[:like]->("LaMarcus Aldridge")> |
| p |
| <("Tim Duncan")-[:like@0{}]->("Manu Ginobili")> |
| <("Tim Duncan")-[:like@0{}]->("Tony Parker")-[:like@0{}]->("LaMarcus Aldridge")> |
| <("Tim Duncan")-[:like@0{}]->("Tony Parker")-[:like@0{}]->("Tim Duncan")> |
| <("Tim Duncan")-[:like@0{}]->("Manu Ginobili")-[:like@0{}]->("Tim Duncan")> |

Scenario: [1] Shortest Path With Limit
When executing query:
Expand Down Expand Up @@ -639,3 +641,27 @@ Feature: Shortest Path
Then the result should be, in any order, with relax comparison:
| relationships |
| [[:like "Tiago Splitter"->"Tim Duncan" @0 {}]] |

Scenario: Shortest Path With Loop
When executing query:
"""
FIND SHORTEST PATH FROM "Tim Duncan" TO "Tim Duncan" OVER like BIDIRECT YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")<-[:like@0 {}]-("Manu Ginobili")<-[:like@0 {}]-("Tim Duncan")> |
| <("Tim Duncan")-[:like@0 {}]->("Manu Ginobili")-[:like@0 {}]->("Tim Duncan")> |
| <("Tim Duncan")<-[:like@0 {}]-("Tony Parker")<-[:like@0 {}]-("Tim Duncan")> |
| <("Tim Duncan")-[:like@0 {}]->("Tony Parker")-[:like@0 {}]->("Tim Duncan")> |
When executing query:
"""
FIND SHORTEST PATH FROM "Tim Duncan" TO "Tim Duncan", "Tony Parker" OVER like BIDIRECT YIELD path as p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Tim Duncan")<-[:like@0 {}]-("Tony Parker")> |
| <("Tim Duncan")-[:like@0 {}]->("Tony Parker")> |
| <("Tim Duncan")<-[:like@0 {}]-("Manu Ginobili")<-[:like@0 {}]-("Tim Duncan")> |
| <("Tim Duncan")-[:like@0 {}]->("Manu Ginobili")-[:like@0 {}]->("Tim Duncan")> |
| <("Tim Duncan")<-[:like@0 {}]-("Tony Parker")<-[:like@0 {}]-("Tim Duncan")> |
| <("Tim Duncan")-[:like@0 {}]->("Tony Parker")-[:like@0 {}]->("Tim Duncan")> |
Loading

0 comments on commit 7c32088

Please sign in to comment.