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

Custom kout/kneighbor, multi-node-shortest-path, jaccard-similar and template paths #1174

Merged
merged 20 commits into from
Oct 28, 2020

Conversation

zhoney
Copy link
Contributor

@zhoney zhoney commented Sep 15, 2020

No description provided.

@zhoney zhoney force-pushed the custom-kout-knei-template-path branch from b2cab74 to 9eb68d8 Compare September 15, 2020 03:32
@codecov
Copy link

codecov bot commented Sep 15, 2020

Codecov Report

Merging #1174 into master will increase coverage by 0.14%.
The diff coverage is 2.72%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1174      +/-   ##
============================================
+ Coverage     64.98%   65.12%   +0.14%     
- Complexity     5652     5748      +96     
============================================
  Files           361      366       +5     
  Lines         29429    29875     +446     
  Branches       4158     4222      +64     
============================================
+ Hits          19123    19456     +333     
- Misses         8352     8443      +91     
- Partials       1954     1976      +22     
Impacted Files Coverage Δ Complexity Δ
.../hugegraph/api/traversers/AllShortestPathsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...graph/api/traversers/CustomizedCrosspointsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...u/hugegraph/api/traversers/CustomizedPathsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...ugegraph/api/traversers/FusiformSimilarityAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...hugegraph/api/traversers/JaccardSimilarityAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...m/baidu/hugegraph/api/traversers/KneighborAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...va/com/baidu/hugegraph/api/traversers/KoutAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...graph/api/traversers/MultiNodeShortestPathAPI.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> (ø)
...idu/hugegraph/api/traversers/SameNeighborsAPI.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
... and 67 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 e35f9fb...20c1ff5. Read the comment docs.

import com.baidu.hugegraph.util.ExecutorUtil;
import com.baidu.hugegraph.util.Log;

public class Consumers<V> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move Consumers to com/baidu/hugegraph/util

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhoney zhoney mentioned this pull request Sep 21, 2020
zhoney and others added 13 commits September 21, 2020 17:48
…h and jaccard similar

* fix OLTP algorithm not check if source/target vertex exist (#1156)
* support customized kout and kneighbor
* support multi node shortest path API
* support template paths api
* support jaccard similars find oltp api
* use multi-thread to accelerate customized kout/kneighbor, multi-node-shortest-path, jaccard-similar and template-paths
* big depth and both direction use multi threads, otherwise single threead
* fix shortest path api NLP

Change-Id: I7eb4ceaccdc4a6b2a4a7b944edc83dff64a98f5d
* template path use concurrent hashset to save paths in concurrent mode
* support property filter for paths api

Change-Id: I2e589f58cdfc48b4b8d16b7780b78cc17ab107d6
also paths and template paths use single thread

Change-Id: I4375c455f377d9e4d43c0284ec30da1725fdf6bc
paths supports nearest args
oltp multiple threads reuse
add multiple thread depth config

Change-Id: I8c2f921ffb56302fb8d300c09a5a13857dac187a
Change-Id: I6d972894f3eec339181e5626bf45d01f36dbd4c0
implements: #1173

Change-Id: I85aa1d4274554d65f85a0deb7ac596e65dbb503b
Change-Id: I73d877fbd2099d9e63ef29ee0a10df30354595f9
Change-Id: Ib6fa985ff48fab203611218cc955079ad8cc90c3
Change-Id: Ia6ff5efd7e2a195f85427992b7bff875d30dec48
Change-Id: Ib43614c252912427c6ddaeb52c974a59b06934e6
Change-Id: I5ef4b33e8c5b4ade0b372d3810e596d335f37f29
Change-Id: Icbc65aa24e069b67bd5653b79473da48e2f973c6
Change-Id: I606772946a2a55f7472274242fb18f4ca91c189a
@zhoney zhoney force-pushed the custom-kout-knei-template-path branch from 5635e57 to 25cb47a Compare September 21, 2020 10:04
Change-Id: I4ab46bc68644d35fab1fa966e27a0d7ab87b433b
houzhizhen
houzhizhen previously approved these changes Sep 22, 2020

// Traversal vertices of previous level
RepeatEdgeStep finalCurrentStep = currentStep;
traverseIds(this.sources.keySet().iterator(), vid -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add common method

Change-Id: If6f0c1370a2376ef176ce2db39e002ae11590e8d
@@ -551,6 +551,26 @@ public static void checkSkipDegree(long skipDegree, long degree,
return new MultivaluedHashMap<>();
}

protected static List<Id> joinPath(Node pre, Node back, boolean ring) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename pre to prev

new ConcurrentMultiValuedMap<>();
private ConcurrentMultiValuedMap<Id, Node> targetsAll =
new ConcurrentMultiValuedMap<>();
private void traverseOne(Id v, RepeatEdgeStep step, boolean forward) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename v to source

// Re-init sources
if (currentStep.remainTimes() > 0) {
this.sources = newVertices;
private void reInitCurrentIfNeeded(RepeatEdgeStep step,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reInitCurrentStepIfNeeded

private void reInitAllIfNeeded(boolean forward) {
if (forward) {
// Re-init source all if last forward finished one super step
// and not last super step
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not finished last super step? or current step is not the last super step?
and use /*

}
} else {
// Re-init target all if last forward finished one super step
// and not last super step
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@Override
public void traverseOneLayer(
Map<Id, List<Node>> vertices, RepeatEdgeStep step,
BiConsumer<Id, RepeatEdgeStep> biConsumer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

protected boolean lastStep() {
return this.stepCount == this.totalSteps - 1;
public RepeatEdgeStep step(boolean forward) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer nextStep

this.sourceIndex = i;
break;
private void processOneForForward(Id source, Id target) {
for (Node n : this.sources.get(source)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename source to sourceV, and rename n to source, same as target

if (this.reachLimit()) {
return;
private void processOneForBackward(Id source, Id target) {
for (Node n : this.targets.get(source)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if (forward) {
processOneForForward(source, target);
} else {
processOneForBackward(source, target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we merge the two methods with one, and pass sourcesAll or targetsAll to that method

@@ -165,7 +165,7 @@ private HugeAuthenticator authenticator() {

@SuppressWarnings("unused")
private void installLicense(HugeConfig config, String md5) {
LicenseVerifier.instance().install(config, this, md5);
// LicenseVerifier.instance().install(config, this, md5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep origin

Iterator<Vertex> iterator,
boolean countOnly) {
List<Map<String, Object>> pathList;
pathList = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep in one line

rangeInt(0, 65535),
10
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line

private Traverser concurrentTraverser(List<Id> sources, List<Id> targets,
EdgeStep step, boolean nearest,
long capacity, long limit) {
return new ConcurrentTraverser(sources, targets, step, capacity, limit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also refactor this class, and can we share code with templatepath?

}

public Set<Node> customizedKneighborSingle(Id source, EdgeStep step,
int maxDepth, long limit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor with one method and call newSet() of Single and Concurrent

if (groupProperty == null) {
E.checkArgument(minGroups == 0,
"Can not set min group count when " +
"group property not set");
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 (groupProperty != null) {
if (groupProperty == null) {
E.checkArgument(minGroups == 0,
"Can not set min group count when " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't

@@ -259,6 +262,35 @@ public double jaccardSimilarity(Id vertex, Id other, Directions dir,
});
}

protected Set<Node> adjacentVertices(Set<Node> vertices, EdgeStep step,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move Iterator adjacentVertices() to line 293

return jaccardSimilarity(sourceNeighbors, targetNeighbors);
}

public double jaccardSimilarity(Set<Id> set1, Set<Id> set2) {
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 kout/jaccardSimilarity out of this class

return results;
}

public Map<Id, Double> jaccardSimilarsSingle(Id source, EdgeStep step,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Change-Id: I7d6912f33836ac9a36fd0dda82b446780675a390
Change-Id: I5b7441f562106fa3810d6d844c897add3010ef30
} else {
strategy = new SingleTraverseStrategy(this.graph());
if (nearest) {
traverser = new SingleNearestTraverser(sourceList, targetList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no nearest when Concurrent?

if (--depth < 0 || traverser.reachLimit()) {
break;
Traverser traverser;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused empty line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused empty line

return newSet(true);
}

protected static <V> Set<V> newSet(boolean single) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer rename to concurrent


}

public abstract class PathTraverser {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a new java file

Change-Id: I760194b0f02a41873c2157a5ddf59dd4d1c3ceff
this.beforeTraverse(true);

// Traversal vertices of previous level
traverseOneLayer(this.sources, currentStep, this::forward);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.traverseOneLayer


currentStep.swithDirection();
// Traversal vertices of previous level
traverseOneLayer(this.targets, currentStep, this::backward);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


private void processOne(Id source, Id target, boolean forward) {
if (forward) {
processOneForForward(source, target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if (forward) {
processOneForForward(source, target);
} else {
processOneForBackward(source, target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

return this.paths.size();
}

protected boolean finish() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finished

@Override
public Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep) {
return super.edgesOfVertex(source, edgeStep);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it

@@ -44,4 +47,6 @@ public abstract void addNode(Map<Id, List<HugeTraverser.Node>> vertices,
public abstract void addNewVerticesToAll(
Map<Id, List<HugeTraverser.Node>> newVertices,
Map<Id, List<HugeTraverser.Node>> targets);

public Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it

Change-Id: I68226c55ca387ecfdd103e4af8b5e45faa9a934e
import com.baidu.hugegraph.util.Consumers;

import jersey.repackaged.com.google.common.base.Objects;

public abstract class TpTraverser extends HugeTraverser
implements AutoCloseable {

protected static ExecutorService executor;
private static final String EXECUTOR_NAME = "oltp";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also rename TpTraverser to OltpTraverser

public static TraverseStrategy create(boolean concurrent, HugeGraph graph) {
return concurrent ? new ConcurrentTraverseStrategy(graph) :
new SingleTraverseStrategy(graph);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

if (executor == null) {
int workers = this.config().get(CoreOptions.OLTP_CONCURRENT_THREADS);
if (workers > 0) {
executor = Consumers.newThreadPool(name, workers);
executor = Consumers.newThreadPool(EXECUTOR_NAME, workers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock for null judgment and assignment

if (--depth < 0 || traverser.reachLimit()) {
break;
Traverser traverser;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused empty line

Change-Id: I882e472d001c40c0f1ffdc89c1c3c28bd6d34a17
@zhoney zhoney merged commit d5cc79b into master Oct 28, 2020
@zhoney zhoney deleted the custom-kout-knei-template-path branch October 28, 2020 09:58
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

4 participants