-
Notifications
You must be signed in to change notification settings - Fork 504
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
add 5 TP algorithm #919
add 5 TP algorithm #919
Conversation
1. same neighbors 2. jaccard similarity 3. all shortest paths 4. weighted shortest path 5. single source shortest paths Change-Id: I13a04267c6c91cc8bb00ca2aed1ef54c8e6eeeb6
Codecov Report
@@ Coverage Diff @@
## master #919 +/- ##
============================================
+ Coverage 71.76% 72.02% +0.26%
- Complexity 4455 4568 +113
============================================
Files 287 295 +8
Lines 21430 21809 +379
Branches 3022 3081 +59
============================================
+ Hits 15380 15709 +329
- Misses 4544 4565 +21
- Partials 1506 1535 +29
Continue to review full report at Codecov.
|
public String get(@Context GraphManager manager, | ||
@PathParam("graph") String graph, | ||
@QueryParam("v1") String v1, | ||
@QueryParam("v2") String v2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve var name
graph, v1, v2, direction, edgeLabel, degree, limit); | ||
|
||
Id sourceId = VertexAPI.checkAndParseVertexId(v1); | ||
Id targetId = VertexAPI.checkAndParseVertexId(v2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
||
Id labelId = this.getEdgeLabelId(label); | ||
|
||
List<Id> sourceNeighbors = IteratorUtils.toList(this.adjacentVertices( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toSet
|
||
List<Id> sourceNeighbors = IteratorUtils.toList(this.adjacentVertices( | ||
v1, direction, labelId, degree)); | ||
List<Id> targetNeighbors = IteratorUtils.toList(this.adjacentVertices( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
v1, direction, labelId, degree)); | ||
List<Id> targetNeighbors = IteratorUtils.toList(this.adjacentVertices( | ||
v2, direction, labelId, degree)); | ||
Set<Id> sameNeighbors = new HashSet<>(CollectionUtils.intersection( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert via "(Set)"
double edgeWeight; | ||
if (this.weight == null || | ||
!edge.property(this.weight).isPresent()) { | ||
edgeWeight = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.0
|
||
Id labelId = this.getEdgeLabelId(label); | ||
|
||
List<Id> sourceNeighbors = IteratorUtils.toList(this.adjacentVertices( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
} | ||
|
||
List<NodeWithWeight> sorted = this.findingNodes.values().stream() | ||
.sorted(Comparator.comparing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call method HugeTraverser.topN or CollectionUtil.sortByValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix fusiform issue
String weight, long degree, | ||
long skipDegree, long capacity) { | ||
E.checkNotNull(sourceV, "source vertex id"); | ||
E.checkNotNull(dir, "direction"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check weight must be set
} | ||
|
||
@Override | ||
public int compareTo(NodeWithWeight o) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other
|
||
@Override | ||
public int hashCode() { | ||
return new HashSet<>(this.vertices()).hashCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't new HashSet in hashCode(), prefer use for-loop: elem1 hash ^ elem2 hash ^ ...
return false; | ||
} | ||
List<Id> reverse = new ArrayList<>(this.vertices()); | ||
Collections.reverse(reverse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't copy and reverse, use for-loop instead
public List<Path> rings(Id sourceV, Directions dir, String label, int depth, | ||
boolean sourceInRing, long degree, long capacity, | ||
long limit) { | ||
public Set<Path> rings(Id sourceV, Directions dir, String label, int depth, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define PathSet class, let it extends HashSet, and add vertices() method to PathSet
Set<NodeWithWeight> newSources = new HashSet<>(); | ||
for (Map.Entry<Id, NodeWithWeight> entry : sorted.entrySet()) { | ||
Id id = entry.getKey(); | ||
NodeWithWeight nw = entry.getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to node or wn
NodeWithWeight nw = new NodeWithWeight(weight, target, node); | ||
if (!this.findingNodes.containsKey(target) || | ||
weight < this.findingNodes.get(target).weight()) { | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node = this.findingNodes.get(target);
node == null || weight < node.weight()
if (skipDegree > 0L) { | ||
E.checkArgument(degree != NO_LIMIT && skipDegree >= degree, | ||
"The skipped degree must be >= degree, " + | ||
"but got skipped degree '%s' and degree '%s'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align
|
||
if (!(paths = traverser.backward(false)).isEmpty() || | ||
--depth <= 0) { | ||
Collections.reverse(paths.iterator().next()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add var for paths.iterator().next()
vertex, dir, labelId, degree)); | ||
Set<Id> targetNeighbors = IteratorUtils.set(this.adjacentVertices( | ||
other, dir, labelId, degree)); | ||
int interNum = CollectionUtils.intersection(sourceNeighbors, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't convert to set at line 207, we support CollectionUtils.intersect(list,list):
intersect(Collection<T> first, Collection<T> second)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjacentVertices() returns Iterator. Convert to list or set is necessary
@@ -76,6 +76,7 @@ public NodeWithWeight weightedShortestPath(Id sourceV, Id targetV, | |||
long skipDegree, long capacity) { | |||
E.checkNotNull(sourceV, "source vertex id"); | |||
E.checkNotNull(dir, "direction"); | |||
E.checkNotNull(weight, "weight property"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems it's not checked at upper layer
|
||
Id sourceId = VertexAPI.checkAndParseVertexId(source); | ||
Id targetId = VertexAPI.checkAndParseVertexId(target); | ||
Directions dir = Directions.convert(EdgeAPI.parseDirection(direction)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check weight
} | ||
} | ||
|
||
public static class PathSet extends HashSet<Path> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer move to HugeTraverser.java
Change-Id: I84788b5145fadb91b8b0d97c66c2f62e12c8294e
Change-Id: I13a04267c6c91cc8bb00ca2aed1ef54c8e6eeeb6