org.apache.flink.graph.library.clustering.undirected.TriangleListing.Result Java Examples
The following examples show how to use
org.apache.flink.graph.library.clustering.undirected.TriangleListing.Result.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public Result<T> map(Result<T> value) throws Exception { // by the triangle listing algorithm we know f1 < f2 if (value.getVertexId0().compareTo(value.getVertexId1()) > 0) { T tempVal = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); if (tempVal.compareTo(value.getVertexId2()) <= 0) { value.setVertexId1(tempVal); } else { value.setVertexId1(value.getVertexId2()); value.setVertexId2(tempVal); } } return value; }
Example #2
Source File: TriangleListing.java From flink with Apache License 2.0 | 6 votes |
@Override public Result<T> map(Result<T> value) throws Exception { // by the triangle listing algorithm we know f1 < f2 if (value.getVertexId0().compareTo(value.getVertexId1()) > 0) { T tempVal = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); if (tempVal.compareTo(value.getVertexId2()) <= 0) { value.setVertexId1(tempVal); } else { value.setVertexId1(value.getVertexId2()); value.setVertexId2(tempVal); } } return value; }
Example #3
Source File: TriangleListing.java From flink with Apache License 2.0 | 6 votes |
@Override public Result<T> map(Result<T> value) throws Exception { // by the triangle listing algorithm we know f1 < f2 if (value.getVertexId0().compareTo(value.getVertexId1()) > 0) { T tempVal = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); if (tempVal.compareTo(value.getVertexId2()) <= 0) { value.setVertexId1(tempVal); } else { value.setVertexId1(value.getVertexId2()); value.setVertexId2(tempVal); } } return value; }
Example #4
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphPermuted() throws Exception { DataSet<Result<IntValue>> tl = undirectedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setPermuteResults(true)); String expectedResult = // permutation of (0,1,2) "1st vertex ID: 0, 2nd vertex ID: 1, 3rd vertex ID: 2\n" + "1st vertex ID: 0, 2nd vertex ID: 2, 3rd vertex ID: 1\n" + "1st vertex ID: 1, 2nd vertex ID: 0, 3rd vertex ID: 2\n" + "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 0\n" + "1st vertex ID: 2, 2nd vertex ID: 0, 3rd vertex ID: 1\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 0\n" + // permutation of (1,2,3) "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 3\n" + "1st vertex ID: 1, 2nd vertex ID: 3, 3rd vertex ID: 2\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 3\n" + "1st vertex ID: 2, 2nd vertex ID: 3, 3rd vertex ID: 1\n" + "1st vertex ID: 3, 2nd vertex ID: 1, 3rd vertex ID: 2\n" + "1st vertex ID: 3, 2nd vertex ID: 2, 3rd vertex ID: 1"; List<String> printableStrings = new ArrayList<>(); for (Result<IntValue> result : tl.collect()) { printableStrings.add(result.toPrintableString()); } TestBaseUtils.compareResultAsText(printableStrings, expectedResult); }
Example #5
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRMatGraph() throws Exception { DataSet<Result<LongValue>> tl = undirectedRMatGraph(10, 16) .run(new TriangleListing<LongValue, NullValue, NullValue>() .setSortTriangleVertices(true)); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(75049, checksum.getCount()); assertEquals(0x000092826c991dd9L, checksum.getChecksum()); }
Example #6
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithoutVertices() throws Exception { DataSet<Result<LongValue>> tl = emptyGraphWithoutVertices .run(new TriangleListing<>()); assertEquals(0, tl.collect().size()); }
Example #7
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Result<LongValue>> tl = emptyGraphWithVertices .run(new TriangleListing<>()); assertEquals(0, tl.collect().size()); }
Example #8
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCompleteGraph() throws Exception { long expectedDegree = completeGraphVertexCount - 1; long expectedCount = completeGraphVertexCount * CombinatoricsUtils.binomialCoefficient((int) expectedDegree, 2) / 3; DataSet<Result<LongValue>> tl = completeGraph .run(new TriangleListing<>()); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(expectedCount, checksum.getCount()); }
Example #9
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphPermuted() throws Exception { DataSet<Result<IntValue>> tl = undirectedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setPermuteResults(true)); String expectedResult = // permutation of (0,1,2) "1st vertex ID: 0, 2nd vertex ID: 1, 3rd vertex ID: 2\n" + "1st vertex ID: 0, 2nd vertex ID: 2, 3rd vertex ID: 1\n" + "1st vertex ID: 1, 2nd vertex ID: 0, 3rd vertex ID: 2\n" + "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 0\n" + "1st vertex ID: 2, 2nd vertex ID: 0, 3rd vertex ID: 1\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 0\n" + // permutation of (1,2,3) "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 3\n" + "1st vertex ID: 1, 2nd vertex ID: 3, 3rd vertex ID: 2\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 3\n" + "1st vertex ID: 2, 2nd vertex ID: 3, 3rd vertex ID: 1\n" + "1st vertex ID: 3, 2nd vertex ID: 1, 3rd vertex ID: 2\n" + "1st vertex ID: 3, 2nd vertex ID: 2, 3rd vertex ID: 1"; List<String> printableStrings = new ArrayList<>(); for (Result<IntValue> result : tl.collect()) { printableStrings.add(result.toPrintableString()); } TestBaseUtils.compareResultAsText(printableStrings, expectedResult); }
Example #10
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphSorted() throws Exception { DataSet<Result<IntValue>> tl = undirectedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setSortTriangleVertices(true)); String expectedResult = "(0,1,2)\n" + "(1,2,3)"; TestBaseUtils.compareResultAsText(tl.collect(), expectedResult); }
Example #11
Source File: TriangleListing.java From flink with Apache License 2.0 | 5 votes |
@Override public Result<T> join(Tuple3<T, T, T> triplet, Tuple2<T, T> edge) throws Exception { output.setVertexId0(triplet.f0); output.setVertexId1(triplet.f1); output.setVertexId2(triplet.f2); return output; }
Example #12
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRMatGraph() throws Exception { DataSet<Result<LongValue>> tl = undirectedRMatGraph(10, 16) .run(new TriangleListing<LongValue, NullValue, NullValue>() .setSortTriangleVertices(true)); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(75049, checksum.getCount()); assertEquals(0x000092826c991dd9L, checksum.getChecksum()); }
Example #13
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithoutVertices() throws Exception { DataSet<Result<LongValue>> tl = emptyGraphWithoutVertices .run(new TriangleListing<>()); assertEquals(0, tl.collect().size()); }
Example #14
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Result<LongValue>> tl = emptyGraphWithVertices .run(new TriangleListing<>()); assertEquals(0, tl.collect().size()); }
Example #15
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCompleteGraph() throws Exception { long expectedDegree = completeGraphVertexCount - 1; long expectedCount = completeGraphVertexCount * CombinatoricsUtils.binomialCoefficient((int) expectedDegree, 2) / 3; DataSet<Result<LongValue>> tl = completeGraph .run(new TriangleListing<>()); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(expectedCount, checksum.getCount()); }
Example #16
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphSorted() throws Exception { DataSet<Result<IntValue>> tl = undirectedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setSortTriangleVertices(true)); String expectedResult = "(0,1,2)\n" + "(1,2,3)"; TestBaseUtils.compareResultAsText(tl.collect(), expectedResult); }
Example #17
Source File: TriangleListing.java From flink with Apache License 2.0 | 5 votes |
@Override public Result<T> join(Tuple3<T, T, T> triplet, Tuple2<T, T> edge) throws Exception { output.setVertexId0(triplet.f0); output.setVertexId1(triplet.f1); output.setVertexId2(triplet.f2); return output; }
Example #18
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testRMatGraph() throws Exception { DataSet<Result<LongValue>> tl = undirectedRMatGraph(10, 16) .run(new TriangleListing<LongValue, NullValue, NullValue>() .setSortTriangleVertices(true)); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(75049, checksum.getCount()); assertEquals(0x000092826c991dd9L, checksum.getChecksum()); }
Example #19
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithoutVertices() throws Exception { DataSet<Result<LongValue>> tl = emptyGraphWithoutVertices .run(new TriangleListing<>()); assertEquals(0, tl.collect().size()); }
Example #20
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Result<LongValue>> tl = emptyGraphWithVertices .run(new TriangleListing<>()); assertEquals(0, tl.collect().size()); }
Example #21
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testCompleteGraph() throws Exception { long expectedDegree = completeGraphVertexCount - 1; long expectedCount = completeGraphVertexCount * CombinatoricsUtils.binomialCoefficient((int) expectedDegree, 2) / 3; DataSet<Result<LongValue>> tl = completeGraph .run(new TriangleListing<>()); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(expectedCount, checksum.getCount()); }
Example #22
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphPermuted() throws Exception { DataSet<Result<IntValue>> tl = undirectedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setPermuteResults(true)); String expectedResult = // permutation of (0,1,2) "1st vertex ID: 0, 2nd vertex ID: 1, 3rd vertex ID: 2\n" + "1st vertex ID: 0, 2nd vertex ID: 2, 3rd vertex ID: 1\n" + "1st vertex ID: 1, 2nd vertex ID: 0, 3rd vertex ID: 2\n" + "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 0\n" + "1st vertex ID: 2, 2nd vertex ID: 0, 3rd vertex ID: 1\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 0\n" + // permutation of (1,2,3) "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 3\n" + "1st vertex ID: 1, 2nd vertex ID: 3, 3rd vertex ID: 2\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 3\n" + "1st vertex ID: 2, 2nd vertex ID: 3, 3rd vertex ID: 1\n" + "1st vertex ID: 3, 2nd vertex ID: 1, 3rd vertex ID: 2\n" + "1st vertex ID: 3, 2nd vertex ID: 2, 3rd vertex ID: 1"; List<String> printableStrings = new ArrayList<>(); for (Result<IntValue> result : tl.collect()) { printableStrings.add(result.toPrintableString()); } TestBaseUtils.compareResultAsText(printableStrings, expectedResult); }
Example #23
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphSorted() throws Exception { DataSet<Result<IntValue>> tl = undirectedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setSortTriangleVertices(true)); String expectedResult = "(0,1,2)\n" + "(1,2,3)"; TestBaseUtils.compareResultAsText(tl.collect(), expectedResult); }
Example #24
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public Result<T> join(Tuple3<T, T, T> triplet, Tuple2<T, T> edge) throws Exception { output.setVertexId0(triplet.f0); output.setVertexId1(triplet.f1); output.setVertexId2(triplet.f2); return output; }
Example #25
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception { // u, v where u < v DataSet<Tuple2<K, K>> filteredByID = input .getEdges() .flatMap(new FilterByID<>()) .setParallelism(parallelism) .name("Filter by ID"); // u, v, (edge value, deg(u), deg(v)) DataSet<Edge<K, Tuple3<EV, LongValue, LongValue>>> pairDegree = input .run(new EdgeDegreePair<K, VV, EV>() .setParallelism(parallelism)); // u, v where deg(u) < deg(v) or (deg(u) == deg(v) and u < v) DataSet<Tuple2<K, K>> filteredByDegree = pairDegree .flatMap(new FilterByDegree<>()) .setParallelism(parallelism) .name("Filter by degree"); // u, v, w where (u, v) and (u, w) are edges in graph, v < w DataSet<Tuple3<K, K, K>> triplets = filteredByDegree .groupBy(0) .sortGroup(1, Order.ASCENDING) .reduceGroup(new GenerateTriplets<>()) .name("Generate triplets"); // u, v, w where (u, v), (u, w), and (v, w) are edges in graph, v < w DataSet<Result<K>> triangles = triplets .join(filteredByID, JoinOperatorBase.JoinHint.REPARTITION_HASH_SECOND) .where(1, 2) .equalTo(0, 1) .with(new ProjectTriangles<>()) .name("Triangle listing"); if (permuteResults) { triangles = triangles .flatMap(new PermuteResult<>()) .name("Permute triangle vertices"); } else if (sortTriangleVertices.get()) { triangles = triangles .map(new SortTriangleVertices<>()) .name("Sort triangle vertices"); } return triangles; }
Example #26
Source File: TriangleListing.java From flink with Apache License 2.0 | 4 votes |
@Override public void flatMap(Result<T> value, Collector<Result<T>> out) throws Exception { T tmp; // 0, 1, 2 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); // 1, 0, 2 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); // 1, 2, 0 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId2()); value.setVertexId2(tmp); // 0, 2, 1 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); // 2, 0, 1 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); // 2, 1, 0 out.collect(value); }
Example #27
Source File: TriangleListing.java From flink with Apache License 2.0 | 4 votes |
@Override public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception { // u, v where u < v DataSet<Tuple2<K, K>> filteredByID = input .getEdges() .flatMap(new FilterByID<>()) .setParallelism(parallelism) .name("Filter by ID"); // u, v, (edge value, deg(u), deg(v)) DataSet<Edge<K, Tuple3<EV, LongValue, LongValue>>> pairDegree = input .run(new EdgeDegreePair<K, VV, EV>() .setParallelism(parallelism)); // u, v where deg(u) < deg(v) or (deg(u) == deg(v) and u < v) DataSet<Tuple2<K, K>> filteredByDegree = pairDegree .flatMap(new FilterByDegree<>()) .setParallelism(parallelism) .name("Filter by degree"); // u, v, w where (u, v) and (u, w) are edges in graph, v < w DataSet<Tuple3<K, K, K>> triplets = filteredByDegree .groupBy(0) .sortGroup(1, Order.ASCENDING) .reduceGroup(new GenerateTriplets<>()) .name("Generate triplets"); // u, v, w where (u, v), (u, w), and (v, w) are edges in graph, v < w DataSet<Result<K>> triangles = triplets .join(filteredByID, JoinOperatorBase.JoinHint.REPARTITION_HASH_SECOND) .where(1, 2) .equalTo(0, 1) .with(new ProjectTriangles<>()) .name("Triangle listing"); if (permuteResults) { triangles = triangles .flatMap(new PermuteResult<>()) .name("Permute triangle vertices"); } else if (sortTriangleVertices.get()) { triangles = triangles .map(new SortTriangleVertices<>()) .name("Sort triangle vertices"); } return triangles; }
Example #28
Source File: TriangleListing.java From flink with Apache License 2.0 | 4 votes |
@Override public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception { // u, v where u < v DataSet<Tuple2<K, K>> filteredByID = input .getEdges() .flatMap(new FilterByID<>()) .setParallelism(parallelism) .name("Filter by ID"); // u, v, (edge value, deg(u), deg(v)) DataSet<Edge<K, Tuple3<EV, LongValue, LongValue>>> pairDegree = input .run(new EdgeDegreePair<K, VV, EV>() .setParallelism(parallelism)); // u, v where deg(u) < deg(v) or (deg(u) == deg(v) and u < v) DataSet<Tuple2<K, K>> filteredByDegree = pairDegree .flatMap(new FilterByDegree<>()) .setParallelism(parallelism) .name("Filter by degree"); // u, v, w where (u, v) and (u, w) are edges in graph, v < w DataSet<Tuple3<K, K, K>> triplets = filteredByDegree .groupBy(0) .sortGroup(1, Order.ASCENDING) .reduceGroup(new GenerateTriplets<>()) .name("Generate triplets"); // u, v, w where (u, v), (u, w), and (v, w) are edges in graph, v < w DataSet<Result<K>> triangles = triplets .join(filteredByID, JoinOperatorBase.JoinHint.REPARTITION_HASH_SECOND) .where(1, 2) .equalTo(0, 1) .with(new ProjectTriangles<>()) .name("Triangle listing"); if (permuteResults) { triangles = triangles .flatMap(new PermuteResult<>()) .name("Permute triangle vertices"); } else if (sortTriangleVertices.get()) { triangles = triangles .map(new SortTriangleVertices<>()) .name("Sort triangle vertices"); } return triangles; }
Example #29
Source File: TriangleListing.java From flink with Apache License 2.0 | 4 votes |
@Override public void flatMap(Result<T> value, Collector<Result<T>> out) throws Exception { T tmp; // 0, 1, 2 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); // 1, 0, 2 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); // 1, 2, 0 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId2()); value.setVertexId2(tmp); // 0, 2, 1 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); // 2, 0, 1 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); // 2, 1, 0 out.collect(value); }
Example #30
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public void flatMap(Result<T> value, Collector<Result<T>> out) throws Exception { T tmp; // 0, 1, 2 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); // 1, 0, 2 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); // 1, 2, 0 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId2()); value.setVertexId2(tmp); // 0, 2, 1 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); // 2, 0, 1 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); // 2, 1, 0 out.collect(value); }