use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithVertex.
@Test
public void testKneighborPostWithVertex() {
Object markoId = getVertexId("person", "name", "marko");
Object rippleId = getVertexId("software", "name", "ripple");
Object joshId = getVertexId("person", "name", "josh");
Object lopId = getVertexId("software", "name", "lop");
Object vadasId = getVertexId("person", "name", "vadas");
Object peterId = getVertexId("person", "name", "peter");
KneighborRequest.Builder builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(false);
builder.withVertex(true);
KneighborRequest request = builder.build();
Kneighbor kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(3, kneighborResult.size());
Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(3, kneighborResult.vertices().size());
Set<Object> expectedVids = ImmutableSet.of(vadasId, lopId, joshId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(false);
builder.withVertex(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(5, kneighborResult.size());
expected = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(5, kneighborResult.vertices().size());
expectedVids = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(true);
builder.withVertex(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(3, kneighborResult.size());
expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(3, kneighborResult.paths().size());
Set<List<Object>> expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
Assert.assertEquals(4, kneighborResult.vertices().size());
expectedVids = ImmutableSet.of(markoId, vadasId, lopId, joshId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(true);
builder.withVertex(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(5, kneighborResult.size());
expected = ImmutableSet.of(peterId, lopId, joshId, rippleId, vadasId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(5, kneighborResult.paths().size());
expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId), ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
Assert.assertEquals(6, kneighborResult.vertices().size());
expectedVids = ImmutableSet.of(markoId, peterId, lopId, joshId, rippleId, vadasId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathApiTest method testShortestPathWithLabel.
@Test
public void testShortestPathWithLabel() {
Path path = shortestPathAPI.get(1, 6, Direction.BOTH, "link", 6, -1L, 0L, -1L);
Assert.assertEquals(4, path.size());
Assert.assertEquals(ImmutableList.of(1, 10, 11, 6), path.objects());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathApiTest method testShortestPathWithCapacity.
@Test
public void testShortestPathWithCapacity() {
Path path = shortestPathAPI.get(14, 6, Direction.BOTH, null, 6, 5L, 0L, 19L);
Assert.assertEquals(5, path.size());
Assert.assertEquals(ImmutableList.of(14, 7, 8, 9, 6), path.objects());
Assert.assertThrows(ServerException.class, () -> {
shortestPathAPI.get(14, 6, Direction.BOTH, null, 6, 1L, 0L, 2L);
}, e -> {
String expect = "Exceed capacity '2' while finding shortest path";
Assert.assertContains(expect, e.getMessage());
});
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathApiTest method testShortestPathWithSkipDegree.
@Test
public void testShortestPathWithSkipDegree() {
// Path length 5 with min degree 3(v1 degree is 3)
List<Object> path1 = ImmutableList.of(1, 2, 3, 4, 5, 6);
// Path length 4 with middle degree 4(v7 degree is 4)
List<Object> path2 = ImmutableList.of(1, 7, 8, 9, 6);
// Path length 3 with max degree 5(v10 degree is 5)
List<Object> path3 = ImmutableList.of(1, 10, 11, 6);
// (skipped degree == degree) > max degree
Path path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 6L, 6L, -1L);
Assert.assertEquals(4, path.size());
Assert.assertEquals(path3, path.objects());
// (skipped degree == degree) == max degree
path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 5L, 5L, -1L);
Assert.assertEquals(5, path.size());
Assert.assertEquals(path2, path.objects());
// min degree < (skipped degree == degree) == middle degree < max degree
path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 4L, 4L, -1L);
Assert.assertEquals(6, path.size());
Assert.assertEquals(path1, path.objects());
// (skipped degree == degree) <= min degree
path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 3L, 3L, -1L);
Assert.assertEquals(0, path.size());
// Skipped degree > max degree, degree <= min degree
path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 3L, 6L, -1L);
Assert.assertTrue(path.size() == 4 || path.size() == 5 || path.size() == 6);
List<List<Object>> paths = ImmutableList.of(path1, path2, path3);
Assert.assertTrue(paths.contains(path.objects()));
// Skipped degree > max degree, min degree < degree < max degree
path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 4L, 6L, -1L);
Assert.assertTrue(path.size() == 4 || path.size() == 5);
Assert.assertTrue(path2.equals(path.objects()) || path3.equals(path.objects()));
// Skipped degree > max degree, degree >= max degree
path = shortestPathAPI.get(1, 6, Direction.OUT, null, 5, 5L, 6L, -1L);
Assert.assertEquals(4, path.size());
Assert.assertEquals(path3, path.objects());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class AllShortestPathsApiTest method testAllShortestPath.
@Test
public void testAllShortestPath() {
List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH, null, 6, -1L, 0L, -1L);
Assert.assertEquals(4, paths.size());
List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 10, 11, 6), ImmutableList.of(1, 19, 20, 6), ImmutableList.of(1, 21, 22, 6), ImmutableList.of(1, 23, 24, 6));
for (Path path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
}
Aggregations