Skip to content

Commit

Permalink
fix match shortestPath find loop (vesoft-inc#5738)
Browse files Browse the repository at this point in the history
fix shortestPath find loop
  • Loading branch information
nevermore3 authored Oct 16, 2023
1 parent 213dfa0 commit 496cfb0
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 311 deletions.
13 changes: 10 additions & 3 deletions src/graph/executor/algo/BatchShortestPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ size_t BatchShortestPath::init(const HashSet& startVids, const HashSet& endVids)
std::unordered_multimap<StartVid, std::pair<EndVid, bool>> terminationMap;
for (auto& _startVid : _startVids) {
for (auto& _endVid : _endVids) {
if (_startVid != _endVid) {
terminationMap.emplace(_startVid, std::make_pair(_endVid, true));
}
terminationMap.emplace(_startVid, std::make_pair(_endVid, true));
}
}
terminationMaps_.emplace_back(std::move(terminationMap));
Expand Down Expand Up @@ -401,6 +399,9 @@ folly::Future<bool> BatchShortestPath::conjunctPath(size_t rowNum, bool oddStep)
}
auto& rightPaths = findCommonVid->second;
for (const auto& srcPaths : leftPathMap.second) {
if (srcPaths.second.empty()) {
continue;
}
auto range = terminationMap.equal_range(srcPaths.first);
if (range.first == range.second) {
continue;
Expand Down Expand Up @@ -440,6 +441,9 @@ void BatchShortestPath::doConjunctPath(const std::vector<CustomPath>& leftPaths,
auto& resultDs = resultDs_[rowNum];
if (rightPaths.empty()) {
for (const auto& leftPath : leftPaths) {
if (hasSameEdge(leftPath.values)) {
continue;
}
auto forwardPath = leftPath.values;
auto src = forwardPath.front();
forwardPath.erase(forwardPath.begin());
Expand Down Expand Up @@ -467,6 +471,9 @@ void BatchShortestPath::doConjunctPath(const std::vector<CustomPath>& leftPaths,
std::make_move_iterator(backwardPath.end()));
auto dst = forwardPath.back();
forwardPath.pop_back();
if (hasSameEdge(forwardPath)) {
continue;
}
Row row;
row.emplace_back(std::move(src));
row.emplace_back(List(std::move(forwardPath)));
Expand Down
13 changes: 13 additions & 0 deletions src/graph/executor/algo/ShortestPathBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ folly::Future<std::vector<Value>> ShortestPathBase::getMeetVidsProps(
});
}

bool ShortestPathBase::hasSameEdge(const std::vector<Value>& values) {
for (size_t i = 0; i < values.size(); ++i) {
if (values[i].isEdge()) {
for (size_t j = i + 1; j < values.size(); ++j) {
if (values[j].isEdge() && values[j].getEdge() == values[i].getEdge()) {
return true;
}
}
}
}
return false;
}

std::vector<Value> ShortestPathBase::handlePropResp(PropRpcResponse&& resps) {
std::vector<Value> vertices;
auto result = handleCompleteness(resps, FLAGS_accept_partial_success);
Expand Down
2 changes: 2 additions & 0 deletions src/graph/executor/algo/ShortestPathBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ShortestPathBase {

void addStats(PropRpcResponse& resp, int64_t timeInUSec) const;

bool hasSameEdge(const std::vector<Value>& values);

folly::Executor* runner() const;

template <typename Resp>
Expand Down
6 changes: 6 additions & 0 deletions src/graph/executor/algo/SingleShortestPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ void SingleShortestPath::buildOddPath(size_t rowNum, const std::vector<Value>& m
Row path = leftPath;
auto& steps = path.values.back().mutableList().values;
steps.insert(steps.end(), rightPath.values.begin(), rightPath.values.end() - 1);
if (hasSameEdge(steps)) {
continue;
}
path.emplace_back(rightPath.values.back());
resultDs_[rowNum].rows.emplace_back(std::move(path));
if (singleShortest_) {
Expand Down Expand Up @@ -285,6 +288,9 @@ folly::Future<bool> SingleShortestPath::buildEvenPath(size_t rowNum,
auto& steps = path.values.back().mutableList().values;
steps.emplace_back(meetVertex);
steps.insert(steps.end(), rightPath.values.begin(), rightPath.values.end() - 1);
if (hasSameEdge(steps)) {
continue;
}
path.emplace_back(rightPath.values.back());
resultDs_[rowNum].rows.emplace_back(std::move(path));
if (singleShortest_) {
Expand Down
Loading

0 comments on commit 496cfb0

Please sign in to comment.