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

improve shortest path by traversing from less direction #1569

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,10 @@ public PathSet allShortestPaths(Id sourceV, Id targetV, Directions dir,
Traverser traverser = new Traverser(sourceV, targetV, dir, labelMap,
degree, skipDegree, capacity);
while (true) {
paths = traverser.forward() ?
traverser.forward(true) : traverser.backward(true);
// Found, reach max depth or reach capacity, stop searching
if (!(paths = traverser.forward(true)).isEmpty() ||
--depth <= 0) {
break;
}
checkCapacity(traverser.capacity, traverser.accessed(),
"shortest path");

if (!(paths = traverser.backward(true)).isEmpty() ||
--depth <= 0) {
if (!paths.isEmpty() || --depth <= 0) {
break;
}
checkCapacity(traverser.capacity, traverser.accessed(),
Expand Down Expand Up @@ -238,6 +232,10 @@ public PathSet backward(boolean all) {
return results;
}

public boolean forward() {
return this.record.lessSources();
}

private boolean superNode(Id vertex, Directions direction) {
if (this.skipDegree <= 0L) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public PathSet findPath(Id target, Function<Id, Boolean> filter,
return results;
}

public boolean lessSources() {
return this.sourceRecords.peek().size() <=
this.targetRecords.peek().size();
}

@Override
public long accessed() {
return this.accessed;
Expand Down