-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat(algorithm): support single source shortest path algorithm #285
feat(algorithm): support single source shortest path algorithm #285
Conversation
...m/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/ShortestPathValue.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/ShortestPathMessage.java
Outdated
Show resolved
Hide resolved
...m/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/ShortestPathValue.java
Outdated
Show resolved
Hide resolved
computer-api/src/main/java/org/apache/hugegraph/computer/core/graph/value/ListValue.java
Outdated
Show resolved
Hide resolved
computer-api/src/main/java/org/apache/hugegraph/computer/core/graph/value/ListValue.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SourceTargetShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SourceTargetShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SourceTargetShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SourceTargetShortestPath.java
Outdated
Show resolved
Hide resolved
...m/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/ShortestPathValue.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SourceTargetShortestPath.java
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #285 +/- ##
============================================
- Coverage 85.03% 84.97% -0.07%
- Complexity 3246 3359 +113
============================================
Files 345 360 +15
Lines 12298 12678 +380
Branches 1102 1149 +47
============================================
+ Hits 10458 10773 +315
- Misses 1315 1341 +26
- Partials 525 564 +39 ☔ View full report in Codecov by Sentry. |
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
computer-api/src/main/java/org/apache/hugegraph/computer/core/combiner/IdListMergeCombiner.java
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
computer-api/src/main/java/org/apache/hugegraph/computer/core/graph/id/IdFactory.java
Outdated
Show resolved
Hide resolved
computer-api/src/main/java/org/apache/hugegraph/computer/core/graph/id/IdFactory.java
Outdated
Show resolved
Hide resolved
computer-test/src/main/java/org/apache/hugegraph/computer/core/util/IdUtilTest.java
Outdated
Show resolved
Hide resolved
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public enum IdCategory { |
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.
not sure why not reuse IdType
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.
IdType
: LONG
, UTF8
, UUID
.
IdCategory
: NUMBER
, STRING
, UUID
.
I suppose that IdType
is too technical and IdCategory
is more user-friendly.
In fact, they correspond one to one.·
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.
remove IdCategory, reuse IdType if necessary.
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java
Outdated
Show resolved
Hide resolved
if (this.targetQuantityType != QuantityType.ALL) { | ||
this.targetIdSet = new IdSet(); | ||
for (String targetIdStr : this.targetIdStr.split(",")) { | ||
targetIdSet.add(IdUtil.parseId(this.vertexIdType, targetIdStr)); |
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 the targets id should be different types? like [111, "abc", "222", 333, U"uuid..."]
@@ -40,8 +40,8 @@ public class SingleSourceShortestPathTest extends AlgorithmTestBase { | |||
public static final String EL = "road"; | |||
public static final String PROPERTY_KEY = "distance"; | |||
|
|||
public static final String SOURCE_ID = "A"; | |||
public static final String TARGET_ID = "E"; | |||
public static final String SOURCE_ID = "{\"id\": \"A\", \"idType\": \"string\"}"; |
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.
we can use id format like this (ref VertexAPI.checkAndParseVertexId()
):
String SOURCE_ID = "\"abc\"";
String SOURCE_ID = "\"123\"";
String SOURCE_ID = "123";
String SOURCE_ID = "U\"uuid-xxxx\"";
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
// todo move to org.apache.hugegraph.util.JsonUtil later |
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.
expect format // TODO: xx
vertex.inactivate(); | ||
return; | ||
} | ||
|
||
if (vertex.numEdges() <= 0) { | ||
// isolated vertex | ||
LOG.debug("source vertex {} can not reach target vertex {}", | ||
this.sourceIdStr, this.targetIdStr); | ||
LOG.debug("source vertex {} is isolated", this.sourceId); |
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.
this format is more convenient for retrieving logs: The source vertex is isolated: {}
@@ -157,17 +158,16 @@ public void compute0(ComputationContext context, Vertex vertex) { | |||
|
|||
// single target && source == target | |||
if (this.targetQuantityType == QuantityType.SINGLE && | |||
this.sourceIdStr.equals(this.targetIdStr)) { | |||
this.sourceId.equals(this.targetIdSet.value().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 a private method targetIdOne()
for this.targetIdSet.value().iterator().next()
? we can also check there exist one element in targetIdOne()
Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, uuid).idType()); | ||
String utf81 = "\"abc\""; | ||
String utf82 = "\"222\""; | ||
String l = "222"; |
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.
idLong
Assert.assertEquals(IdType.LONG, IdUtil.parseId(IdCategory.NUMBER, "222").idType()); | ||
Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, "aaa222").idType()); | ||
Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, uuid).idType()); | ||
String utf81 = "\"abc\""; |
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.
idUtf8WithString
Assert.assertEquals(IdType.UTF8, IdUtil.parseId(IdCategory.STRING, "aaa222").idType()); | ||
Assert.assertEquals(IdType.UUID, IdUtil.parseId(IdCategory.UUID, uuid).idType()); | ||
String utf81 = "\"abc\""; | ||
String utf82 = "\"222\""; |
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.
idUtf8WithNumber
Assert.assertEquals(IdType.UTF8, IdUtil.parseId(utf81).idType()); | ||
Assert.assertEquals(IdType.UTF8, IdUtil.parseId(utf82).idType()); | ||
Assert.assertEquals(IdType.LONG, IdUtil.parseId(l).idType()); | ||
Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType()); |
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.
can we also add some exception cases, like idEmpty/idDouble/uuidInvalid
if (idCategory == null) { | ||
// automatic inference | ||
return parseId(idStr); | ||
if (idStr.startsWith("U\"")) { |
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.
also move to try-catch?
Assert.assertThrows(ComputerException.class, () -> { | ||
IdUtil.parseId(idNull).idType(); | ||
}); | ||
Assert.assertThrows(ComputerException.class, () -> { |
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.
also keep IllegalArgumentException?
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.
LGTM
Purpose of the PR
Main Changes
Add single source shortest path algorithm.
There are 3 types of
target vertex
:Verifying these changes
Unit test:
org.apache.hugegraph.computer.algorithm.path.shortest.SingleSourceShortestPathTest#testRunAlgorithm
Does this PR potentially affect the following parts?
Documentation Status
Doc - TODO
Doc - Done
Doc - No Need