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

add 5 TP algorithm #919

Merged
merged 4 commits into from
Apr 5, 2020
Merged

add 5 TP algorithm #919

merged 4 commits into from
Apr 5, 2020

Conversation

zhoney
Copy link
Contributor

@zhoney zhoney commented Mar 30, 2020

  1. same neighbors
  2. jaccard similarity
  3. all shortest paths
  4. weighted shortest path
  5. single source shortest paths

Change-Id: I13a04267c6c91cc8bb00ca2aed1ef54c8e6eeeb6

1. same neighbors
2. jaccard similarity
3. all shortest paths
4. weighted shortest path
5. single source shortest paths

Change-Id: I13a04267c6c91cc8bb00ca2aed1ef54c8e6eeeb6
@codecov
Copy link

codecov bot commented Mar 30, 2020

Codecov Report

Merging #919 into master will increase coverage by 0.26%.
The diff coverage is 1.38%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
.../hugegraph/api/traversers/AllShortestPathsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...baidu/hugegraph/api/traversers/CrosspointsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...hugegraph/api/traversers/JaccardSimilarityAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...a/com/baidu/hugegraph/api/traversers/PathsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...va/com/baidu/hugegraph/api/traversers/RaysAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...a/com/baidu/hugegraph/api/traversers/RingsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...idu/hugegraph/api/traversers/SameNeighborsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...ph/api/traversers/SingleSourceShortestPathAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...egraph/api/traversers/WeightedShortestPathAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...com/baidu/hugegraph/serializer/JsonSerializer.java 50.00% <0.00%> (-1.29%) 0.00 <0.00> (ø)
... and 61 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca9ee32...0a8c81d. Read the comment docs.

public String get(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("v1") String v1,
@QueryParam("v2") String v2,
Copy link
Contributor

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);
Copy link
Contributor

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(
Copy link
Contributor

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(
Copy link
Contributor

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(
Copy link
Contributor

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;
Copy link
Contributor

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(
Copy link
Contributor

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
Copy link
Contributor

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

Change-Id: I25709ed8af68fba565f1c6d3d3ed16376644b48e
Copy link
Contributor

@javeme javeme left a 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");
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

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);
Copy link
Contributor

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,
Copy link
Contributor

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();
Copy link
Contributor

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()) {
/*
Copy link
Contributor

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'",
Copy link
Contributor

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());
Copy link
Contributor

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,
Copy link
Contributor

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)

Copy link
Contributor Author

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

Change-Id: Ib232cedf775eca8b7dee333c1db5c4cfa8912e12
@@ -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");
Copy link
Contributor

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));
Copy link
Contributor

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> {
Copy link
Contributor

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
@Linary Linary merged commit 04607d0 into master Apr 5, 2020
@Linary Linary deleted the 5-tp-algorithm branch April 5, 2020 11:05
@zhoney zhoney mentioned this pull request Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants