Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish find path when we meet the dead end. #1124

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/graph/FindPathExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void FindPathExecutor::execute() {
}

void FindPathExecutor::getNeighborsAndFindPath() {
// We meet the dead end.
if (fromVids_.empty() || toVids_.empty()) {
onFinish_();
return;
}

fPro_ = std::make_unique<folly::Promise<folly::Unit>>();
tPro_ = std::make_unique<folly::Promise<folly::Unit>>();
std::vector<folly::Future<folly::Unit>> futures;
Expand Down Expand Up @@ -213,6 +219,8 @@ void FindPathExecutor::findPath() {
VLOG(2) << "Find Path.";
visitedFrom_.clear();
std::multimap<VertexID, Path> pathF;
VLOG(2) << "Get froms: " << fromFrontiers_.second.size();
VLOG(2) << "Get tos: " << toFrontiers_.second.size();
for (auto &frontier : fromFrontiers_.second) {
// Notice: we treat edges with different ranking
// between two vertices as different path
Expand Down Expand Up @@ -275,7 +283,7 @@ void FindPathExecutor::findPath() {
onFinish_();
return;
} else {
LOG(INFO) << "Current step:" << currentStep_;
VLOG(2) << "Current step:" << currentStep_;
++currentStep_;
}
getNeighborsAndFindPath();
Expand Down
63 changes: 63 additions & 0 deletions src/graph/test/FindPathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,68 @@ TEST_F(FindPathTest, multiEdgesAll) {
ASSERT_TRUE(verifyPath(resp, expected));
}
}

TEST_F(FindPathTest, vertexNotExist) {
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto query = folly::stringPrintf(fmt,
std::hash<std::string>()("Nobody1"), std::hash<std::string>()("Nobody2"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, tim.vid(), std::hash<std::string>()("Nobody"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, std::hash<std::string>()("Nobody"), tim.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto query = folly::stringPrintf(fmt,
std::hash<std::string>()("Nobody1"), std::hash<std::string>()("Nobody2"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, tim.vid(), std::hash<std::string>()("Nobody"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, std::hash<std::string>()("Nobody"), tim.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
}
} // namespace graph
} // namespace nebula