org.apache.flink.graph.library.clustering.directed.TriangleListing.Result Java Examples
The following examples show how to use
org.apache.flink.graph.library.clustering.directed.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: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphSorted() throws Exception { DataSet<Result<IntValue>> tl = directedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setSortTriangleVertices(true)); String expectedResult = "(0,1,2,41)\n" + "(1,2,3,22)"; TestBaseUtils.compareResultAsText(tl.collect(), expectedResult); }
Example #2
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRMatGraph() throws Exception { DataSet<Result<LongValue>> tl = directedRMatGraph(10, 16) .run(new TriangleListing<LongValue, NullValue, NullValue>() .setSortTriangleVertices(true)); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(75049, checksum.getCount()); assertEquals(0x000092399c79299eL, checksum.getChecksum()); }
Example #3
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 #4
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 #5
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphPermuted() throws Exception { DataSet<Result<IntValue>> tl = directedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setPermuteResults(true)); String expectedResult = // permutation of (0,1,2,41) "1st vertex ID: 0, 2nd vertex ID: 1, 3rd vertex ID: 2, edge directions: 0->1, 0->2, 1<-2\n" + "1st vertex ID: 0, 2nd vertex ID: 2, 3rd vertex ID: 1, edge directions: 0->2, 0->1, 2->1\n" + "1st vertex ID: 1, 2nd vertex ID: 0, 3rd vertex ID: 2, edge directions: 1<-0, 1<-2, 0->2\n" + "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 0, edge directions: 1<-2, 1<-0, 2<-0\n" + "1st vertex ID: 2, 2nd vertex ID: 0, 3rd vertex ID: 1, edge directions: 2<-0, 2->1, 0->1\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 0, edge directions: 2->1, 2<-0, 1<-0\n" + // permutation of (1,2,3,22) "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 3, edge directions: 1<-2, 1<-3, 2->3\n" + "1st vertex ID: 1, 2nd vertex ID: 3, 3rd vertex ID: 2, edge directions: 1<-3, 1<-2, 3<-2\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 3, edge directions: 2->1, 2->3, 1<-3\n" + "1st vertex ID: 2, 2nd vertex ID: 3, 3rd vertex ID: 1, edge directions: 2->3, 2->1, 3->1\n" + "1st vertex ID: 3, 2nd vertex ID: 1, 3rd vertex ID: 2, edge directions: 3->1, 3<-2, 1<-2\n" + "1st vertex ID: 3, 2nd vertex ID: 2, 3rd vertex ID: 1, edge directions: 3<-2, 3->1, 2->1"; List<String> printableStrings = new ArrayList<>(); for (Result<IntValue> result : tl.collect()) { printableStrings.add(result.toPrintableString()); } TestBaseUtils.compareResultAsText(printableStrings, expectedResult); }
Example #6
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphSorted() throws Exception { DataSet<Result<IntValue>> tl = directedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setSortTriangleVertices(true)); String expectedResult = "(0,1,2,41)\n" + "(1,2,3,22)"; TestBaseUtils.compareResultAsText(tl.collect(), expectedResult); }
Example #7
Source File: TriangleListing.java From flink with Apache License 2.0 | 5 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) { byte bitmask = value.getBitmask().getValue(); T tempVal = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); if (tempVal.compareTo(value.getVertexId2()) < 0) { value.setVertexId1(tempVal); int f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); int f0f2 = (bitmask & 0b001100) >>> 2; int f1f2 = (bitmask & 0b000011) << 2; value.setBitmask((byte) (f0f1 | f0f2 | f1f2)); } else { value.setVertexId1(value.getVertexId2()); value.setVertexId2(tempVal); int f0f1 = (bitmask & 0b000011) << 4; int f0f2 = ((bitmask & 0b100000) >>> 3) | ((bitmask & 0b010000) >>> 1); int f1f2 = ((bitmask & 0b001000) >>> 3) | ((bitmask & 0b000100) >>> 1); value.setBitmask((byte) (f0f1 | f0f2 | f1f2)); } } return value; }
Example #8
Source File: TriangleListing.java From flink with Apache License 2.0 | 5 votes |
@Override public Result<T> join(Tuple4<T, T, T, ByteValue> triplet, Tuple3<T, T, ByteValue> edge) throws Exception { output.setVertexId0(triplet.f0); output.setVertexId1(triplet.f1); output.setVertexId2(triplet.f2); output.setBitmask((byte) (triplet.f3.getValue() | edge.f2.getValue())); return output; }
Example #9
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRMatGraph() throws Exception { DataSet<Result<LongValue>> tl = directedRMatGraph(10, 16) .run(new TriangleListing<LongValue, NullValue, NullValue>() .setSortTriangleVertices(true)); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(75049, checksum.getCount()); assertEquals(0x000092399c79299eL, checksum.getChecksum()); }
Example #10
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 #11
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 #12
Source File: TriangleListingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphPermuted() throws Exception { DataSet<Result<IntValue>> tl = directedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setPermuteResults(true)); String expectedResult = // permutation of (0,1,2,41) "1st vertex ID: 0, 2nd vertex ID: 1, 3rd vertex ID: 2, edge directions: 0->1, 0->2, 1<-2\n" + "1st vertex ID: 0, 2nd vertex ID: 2, 3rd vertex ID: 1, edge directions: 0->2, 0->1, 2->1\n" + "1st vertex ID: 1, 2nd vertex ID: 0, 3rd vertex ID: 2, edge directions: 1<-0, 1<-2, 0->2\n" + "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 0, edge directions: 1<-2, 1<-0, 2<-0\n" + "1st vertex ID: 2, 2nd vertex ID: 0, 3rd vertex ID: 1, edge directions: 2<-0, 2->1, 0->1\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 0, edge directions: 2->1, 2<-0, 1<-0\n" + // permutation of (1,2,3,22) "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 3, edge directions: 1<-2, 1<-3, 2->3\n" + "1st vertex ID: 1, 2nd vertex ID: 3, 3rd vertex ID: 2, edge directions: 1<-3, 1<-2, 3<-2\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 3, edge directions: 2->1, 2->3, 1<-3\n" + "1st vertex ID: 2, 2nd vertex ID: 3, 3rd vertex ID: 1, edge directions: 2->3, 2->1, 3->1\n" + "1st vertex ID: 3, 2nd vertex ID: 1, 3rd vertex ID: 2, edge directions: 3->1, 3<-2, 1<-2\n" + "1st vertex ID: 3, 2nd vertex ID: 2, 3rd vertex ID: 1, edge directions: 3<-2, 3->1, 2->1"; List<String> printableStrings = new ArrayList<>(); for (Result<IntValue> result : tl.collect()) { printableStrings.add(result.toPrintableString()); } TestBaseUtils.compareResultAsText(printableStrings, expectedResult); }
Example #13
Source File: TriangleListing.java From flink with Apache License 2.0 | 5 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) { byte bitmask = value.getBitmask().getValue(); T tempVal = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); if (tempVal.compareTo(value.getVertexId2()) < 0) { value.setVertexId1(tempVal); int f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); int f0f2 = (bitmask & 0b001100) >>> 2; int f1f2 = (bitmask & 0b000011) << 2; value.setBitmask((byte) (f0f1 | f0f2 | f1f2)); } else { value.setVertexId1(value.getVertexId2()); value.setVertexId2(tempVal); int f0f1 = (bitmask & 0b000011) << 4; int f0f2 = ((bitmask & 0b100000) >>> 3) | ((bitmask & 0b010000) >>> 1); int f1f2 = ((bitmask & 0b001000) >>> 3) | ((bitmask & 0b000100) >>> 1); value.setBitmask((byte) (f0f1 | f0f2 | f1f2)); } } return value; }
Example #14
Source File: TriangleListing.java From flink with Apache License 2.0 | 5 votes |
@Override public Result<T> join(Tuple4<T, T, T, ByteValue> triplet, Tuple3<T, T, ByteValue> edge) throws Exception { output.setVertexId0(triplet.f0); output.setVertexId1(triplet.f1); output.setVertexId2(triplet.f2); output.setBitmask((byte) (triplet.f3.getValue() | edge.f2.getValue())); return output; }
Example #15
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testRMatGraph() throws Exception { DataSet<Result<LongValue>> tl = directedRMatGraph(10, 16) .run(new TriangleListing<LongValue, NullValue, NullValue>() .setSortTriangleVertices(true)); Checksum checksum = new ChecksumHashCode<Result<LongValue>>() .run(tl) .execute(); assertEquals(75049, checksum.getCount()); assertEquals(0x000092399c79299eL, checksum.getChecksum()); }
Example #16
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 #17
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 #18
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphPermuted() throws Exception { DataSet<Result<IntValue>> tl = directedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setPermuteResults(true)); String expectedResult = // permutation of (0,1,2,41) "1st vertex ID: 0, 2nd vertex ID: 1, 3rd vertex ID: 2, edge directions: 0->1, 0->2, 1<-2\n" + "1st vertex ID: 0, 2nd vertex ID: 2, 3rd vertex ID: 1, edge directions: 0->2, 0->1, 2->1\n" + "1st vertex ID: 1, 2nd vertex ID: 0, 3rd vertex ID: 2, edge directions: 1<-0, 1<-2, 0->2\n" + "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 0, edge directions: 1<-2, 1<-0, 2<-0\n" + "1st vertex ID: 2, 2nd vertex ID: 0, 3rd vertex ID: 1, edge directions: 2<-0, 2->1, 0->1\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 0, edge directions: 2->1, 2<-0, 1<-0\n" + // permutation of (1,2,3,22) "1st vertex ID: 1, 2nd vertex ID: 2, 3rd vertex ID: 3, edge directions: 1<-2, 1<-3, 2->3\n" + "1st vertex ID: 1, 2nd vertex ID: 3, 3rd vertex ID: 2, edge directions: 1<-3, 1<-2, 3<-2\n" + "1st vertex ID: 2, 2nd vertex ID: 1, 3rd vertex ID: 3, edge directions: 2->1, 2->3, 1<-3\n" + "1st vertex ID: 2, 2nd vertex ID: 3, 3rd vertex ID: 1, edge directions: 2->3, 2->1, 3->1\n" + "1st vertex ID: 3, 2nd vertex ID: 1, 3rd vertex ID: 2, edge directions: 3->1, 3<-2, 1<-2\n" + "1st vertex ID: 3, 2nd vertex ID: 2, 3rd vertex ID: 1, edge directions: 3<-2, 3->1, 2->1"; List<String> printableStrings = new ArrayList<>(); for (Result<IntValue> result : tl.collect()) { printableStrings.add(result.toPrintableString()); } TestBaseUtils.compareResultAsText(printableStrings, expectedResult); }
Example #19
Source File: TriangleListingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraphSorted() throws Exception { DataSet<Result<IntValue>> tl = directedSimpleGraph .run(new TriangleListing<IntValue, NullValue, NullValue>() .setSortTriangleVertices(true)); String expectedResult = "(0,1,2,41)\n" + "(1,2,3,22)"; TestBaseUtils.compareResultAsText(tl.collect(), expectedResult); }
Example #20
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 5 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) { byte bitmask = value.getBitmask().getValue(); T tempVal = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); if (tempVal.compareTo(value.getVertexId2()) < 0) { value.setVertexId1(tempVal); int f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); int f0f2 = (bitmask & 0b001100) >>> 2; int f1f2 = (bitmask & 0b000011) << 2; value.setBitmask((byte) (f0f1 | f0f2 | f1f2)); } else { value.setVertexId1(value.getVertexId2()); value.setVertexId2(tempVal); int f0f1 = (bitmask & 0b000011) << 4; int f0f2 = ((bitmask & 0b100000) >>> 3) | ((bitmask & 0b010000) >>> 1); int f1f2 = ((bitmask & 0b001000) >>> 3) | ((bitmask & 0b000100) >>> 1); value.setBitmask((byte) (f0f1 | f0f2 | f1f2)); } } return value; }
Example #21
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public Result<T> join(Tuple4<T, T, T, ByteValue> triplet, Tuple3<T, T, ByteValue> edge) throws Exception { output.setVertexId0(triplet.f0); output.setVertexId1(triplet.f1); output.setVertexId2(triplet.f2); output.setBitmask((byte) (triplet.f3.getValue() | edge.f2.getValue())); return output; }
Example #22
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, bitmask where u < v DataSet<Tuple3<K, K, ByteValue>> filteredByID = input .getEdges() .map(new OrderByID<>()) .setParallelism(parallelism) .name("Order by ID") .groupBy(0, 1) .reduceGroup(new ReduceBitmask<>()) .setParallelism(parallelism) .name("Flatten by ID"); // u, v, (deg(u), deg(v)) DataSet<Edge<K, Tuple3<EV, Degrees, Degrees>>> pairDegrees = input .run(new EdgeDegreesPair<K, VV, EV>() .setParallelism(parallelism)); // u, v, bitmask where deg(u) < deg(v) or (deg(u) == deg(v) and u < v) DataSet<Tuple3<K, K, ByteValue>> filteredByDegree = pairDegrees .map(new OrderByDegree<>()) .setParallelism(parallelism) .name("Order by degree") .groupBy(0, 1) .reduceGroup(new ReduceBitmask<>()) .setParallelism(parallelism) .name("Flatten by degree"); // u, v, w, bitmask where (u, v) and (u, w) are edges in graph DataSet<Tuple4<K, K, K, ByteValue>> triplets = filteredByDegree .groupBy(0) .sortGroup(1, Order.ASCENDING) .reduceGroup(new GenerateTriplets<>()) .name("Generate triplets"); // u, v, w, bitmask where (u, v), (u, w), and (v, w) are edges in graph 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 #23
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; int f0f1, f0f2, f1f2; byte bitmask = value.getBitmask().getValue(); // 0, 1, 2 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); f0f2 = (bitmask & 0b001100) >>> 2; f1f2 = (bitmask & 0b000011) << 2; bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 1, 0, 2 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = (bitmask & 0b110000) >>> 2; f0f2 = (bitmask & 0b001100) << 2; f1f2 = ((bitmask & 0b000010) >>> 1) | ((bitmask & 0b000001) << 1); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 1, 2, 0 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = ((bitmask & 0b100000) >>> 5) | ((bitmask & 0b010000) >>> 3); f0f2 = ((bitmask & 0b001000) >>> 1) | ((bitmask & 0b000100) << 1); f1f2 = ((bitmask & 0b000010) << 3) | ((bitmask & 0b000001) << 5); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 0, 2, 1 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); f0f2 = (bitmask & 0b001100) >>> 2; f1f2 = (bitmask & 0b000011) << 2; bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 2, 0, 1 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = (bitmask & 0b110000) >>> 2; f0f2 = (bitmask & 0b001100) << 2; f1f2 = ((bitmask & 0b000010) >>> 1) | ((bitmask & 0b000001) << 1); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 2, 1, 0 out.collect(value); }
Example #24
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, bitmask where u < v DataSet<Tuple3<K, K, ByteValue>> filteredByID = input .getEdges() .map(new OrderByID<>()) .setParallelism(parallelism) .name("Order by ID") .groupBy(0, 1) .reduceGroup(new ReduceBitmask<>()) .setParallelism(parallelism) .name("Flatten by ID"); // u, v, (deg(u), deg(v)) DataSet<Edge<K, Tuple3<EV, Degrees, Degrees>>> pairDegrees = input .run(new EdgeDegreesPair<K, VV, EV>() .setParallelism(parallelism)); // u, v, bitmask where deg(u) < deg(v) or (deg(u) == deg(v) and u < v) DataSet<Tuple3<K, K, ByteValue>> filteredByDegree = pairDegrees .map(new OrderByDegree<>()) .setParallelism(parallelism) .name("Order by degree") .groupBy(0, 1) .reduceGroup(new ReduceBitmask<>()) .setParallelism(parallelism) .name("Flatten by degree"); // u, v, w, bitmask where (u, v) and (u, w) are edges in graph DataSet<Tuple4<K, K, K, ByteValue>> triplets = filteredByDegree .groupBy(0) .sortGroup(1, Order.ASCENDING) .reduceGroup(new GenerateTriplets<>()) .name("Generate triplets"); // u, v, w, bitmask where (u, v), (u, w), and (v, w) are edges in graph 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 #25
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, bitmask where u < v DataSet<Tuple3<K, K, ByteValue>> filteredByID = input .getEdges() .map(new OrderByID<>()) .setParallelism(parallelism) .name("Order by ID") .groupBy(0, 1) .reduceGroup(new ReduceBitmask<>()) .setParallelism(parallelism) .name("Flatten by ID"); // u, v, (deg(u), deg(v)) DataSet<Edge<K, Tuple3<EV, Degrees, Degrees>>> pairDegrees = input .run(new EdgeDegreesPair<K, VV, EV>() .setParallelism(parallelism)); // u, v, bitmask where deg(u) < deg(v) or (deg(u) == deg(v) and u < v) DataSet<Tuple3<K, K, ByteValue>> filteredByDegree = pairDegrees .map(new OrderByDegree<>()) .setParallelism(parallelism) .name("Order by degree") .groupBy(0, 1) .reduceGroup(new ReduceBitmask<>()) .setParallelism(parallelism) .name("Flatten by degree"); // u, v, w, bitmask where (u, v) and (u, w) are edges in graph DataSet<Tuple4<K, K, K, ByteValue>> triplets = filteredByDegree .groupBy(0) .sortGroup(1, Order.ASCENDING) .reduceGroup(new GenerateTriplets<>()) .name("Generate triplets"); // u, v, w, bitmask where (u, v), (u, w), and (v, w) are edges in graph 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; int f0f1, f0f2, f1f2; byte bitmask = value.getBitmask().getValue(); // 0, 1, 2 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); f0f2 = (bitmask & 0b001100) >>> 2; f1f2 = (bitmask & 0b000011) << 2; bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 1, 0, 2 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = (bitmask & 0b110000) >>> 2; f0f2 = (bitmask & 0b001100) << 2; f1f2 = ((bitmask & 0b000010) >>> 1) | ((bitmask & 0b000001) << 1); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 1, 2, 0 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = ((bitmask & 0b100000) >>> 5) | ((bitmask & 0b010000) >>> 3); f0f2 = ((bitmask & 0b001000) >>> 1) | ((bitmask & 0b000100) << 1); f1f2 = ((bitmask & 0b000010) << 3) | ((bitmask & 0b000001) << 5); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 0, 2, 1 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); f0f2 = (bitmask & 0b001100) >>> 2; f1f2 = (bitmask & 0b000011) << 2; bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 2, 0, 1 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = (bitmask & 0b110000) >>> 2; f0f2 = (bitmask & 0b001100) << 2; f1f2 = ((bitmask & 0b000010) >>> 1) | ((bitmask & 0b000001) << 1); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 2, 1, 0 out.collect(value); }
Example #27
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; int f0f1, f0f2, f1f2; byte bitmask = value.getBitmask().getValue(); // 0, 1, 2 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); f0f2 = (bitmask & 0b001100) >>> 2; f1f2 = (bitmask & 0b000011) << 2; bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 1, 0, 2 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = (bitmask & 0b110000) >>> 2; f0f2 = (bitmask & 0b001100) << 2; f1f2 = ((bitmask & 0b000010) >>> 1) | ((bitmask & 0b000001) << 1); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 1, 2, 0 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = ((bitmask & 0b100000) >>> 5) | ((bitmask & 0b010000) >>> 3); f0f2 = ((bitmask & 0b001000) >>> 1) | ((bitmask & 0b000100) << 1); f1f2 = ((bitmask & 0b000010) << 3) | ((bitmask & 0b000001) << 5); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 0, 2, 1 out.collect(value); tmp = value.getVertexId0(); value.setVertexId0(value.getVertexId1()); value.setVertexId1(tmp); f0f1 = ((bitmask & 0b100000) >>> 1) | ((bitmask & 0b010000) << 1); f0f2 = (bitmask & 0b001100) >>> 2; f1f2 = (bitmask & 0b000011) << 2; bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 2, 0, 1 out.collect(value); tmp = value.getVertexId1(); value.setVertexId1(value.getVertexId2()); value.setVertexId2(tmp); f0f1 = (bitmask & 0b110000) >>> 2; f0f2 = (bitmask & 0b001100) << 2; f1f2 = ((bitmask & 0b000010) >>> 1) | ((bitmask & 0b000001) << 1); bitmask = (byte) (f0f1 | f0f2 | f1f2); value.setBitmask(bitmask); // 2, 1, 0 out.collect(value); }