org.apache.flink.graph.asm.degree.annotate.directed.VertexDegrees.Degrees Java Examples
The following examples show how to use
org.apache.flink.graph.asm.degree.annotate.directed.VertexDegrees.Degrees.
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: EdgeTargetDegrees.java From flink with Apache License 2.0 | 6 votes |
@Override public DataSet<Edge<K, Tuple2<EV, Degrees>>> runInternal(Graph<K, VV, EV> input) throws Exception { // t, d(t) DataSet<Vertex<K, Degrees>> vertexDegrees = input .run(new VertexDegrees<K, VV, EV>() .setParallelism(parallelism)); // s, t, d(t) return input.getEdges() .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND) .where(1) .equalTo(0) .with(new JoinEdgeWithVertexDegree<>()) .setParallelism(parallelism) .name("Edge target degrees"); }
Example #2
Source File: VertexMetrics.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public VertexMetrics<K, VV, EV> run(Graph<K, VV, EV> input) throws Exception { super.run(input); DataSet<Vertex<K, Degrees>> vertexDegree = input .run(new VertexDegrees<K, VV, EV>() .setIncludeZeroDegreeVertices(includeZeroDegreeVertices) .setParallelism(parallelism)); vertexMetricsHelper = new VertexMetricsHelper<>(); vertexDegree .output(vertexMetricsHelper) .name("Vertex metrics"); return this; }
Example #3
Source File: EdgeDegreesPair.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public DataSet<Edge<K, Tuple3<EV, Degrees, Degrees>>> runInternal(Graph<K, VV, EV> input) throws Exception { // s, t, d(s) DataSet<Edge<K, Tuple2<EV, Degrees>>> edgeSourceDegrees = input .run(new EdgeSourceDegrees<K, VV, EV>() .setParallelism(parallelism)); // t, d(t) DataSet<Vertex<K, Degrees>> vertexDegrees = input .run(new VertexDegrees<K, VV, EV>() .setParallelism(parallelism)); // s, t, (d(s), d(t)) return edgeSourceDegrees .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND) .where(1) .equalTo(0) .with(new JoinEdgeDegreeWithVertexDegree<>()) .setParallelism(parallelism) .name("Edge target degree"); }
Example #4
Source File: EdgeTargetDegreesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(3,0,3)))\n" + "(0,2,((null),(3,2,1)))\n" + "(2,1,((null),(3,0,3)))\n" + "(2,3,((null),(4,2,2)))\n" + "(3,1,((null),(3,0,3)))\n" + "(3,4,((null),(1,0,1)))\n" + "(5,3,((null),(4,2,2)))"; DataSet<Edge<IntValue, Tuple2<NullValue, Degrees>>> targetDegrees = directedSimpleGraph .run(new EdgeTargetDegrees<>()); TestBaseUtils.compareResultAsText(targetDegrees.collect(), expectedResult); }
Example #5
Source File: EdgeSourceDegreesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(2,2,0)))\n" + "(0,2,((null),(2,2,0)))\n" + "(2,1,((null),(3,2,1)))\n" + "(2,3,((null),(3,2,1)))\n" + "(3,1,((null),(4,2,2)))\n" + "(3,4,((null),(4,2,2)))\n" + "(5,3,((null),(1,1,0)))"; DataSet<Edge<IntValue, Tuple2<NullValue, Degrees>>> sourceDegrees = directedSimpleGraph .run(new EdgeSourceDegrees<>()); TestBaseUtils.compareResultAsText(sourceDegrees.collect(), expectedResult); }
Example #6
Source File: EdgeSourceDegrees.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public DataSet<Edge<K, Tuple2<EV, Degrees>>> runInternal(Graph<K, VV, EV> input) throws Exception { // s, d(s) DataSet<Vertex<K, Degrees>> vertexDegrees = input .run(new VertexDegrees<K, VV, EV>() .setParallelism(parallelism)); // s, t, d(s) return input.getEdges() .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND) .where(0) .equalTo(0) .with(new JoinEdgeWithVertexDegree<>()) .setParallelism(parallelism) .name("Edge source degrees"); }
Example #7
Source File: TriangleListing.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public Tuple3<T, T, ByteValue> map(Edge<T, Tuple3<ET, Degrees, Degrees>> value) throws Exception { Tuple3<ET, Degrees, Degrees> degrees = value.f2; long sourceDegree = degrees.f1.getDegree().getValue(); long targetDegree = degrees.f2.getDegree().getValue(); if (sourceDegree < targetDegree || (sourceDegree == targetDegree && value.f0.compareTo(value.f1) < 0)) { output.f0 = value.f0; output.f1 = value.f1; output.f2 = forward; } else { output.f0 = value.f1; output.f1 = value.f0; output.f2 = reverse; } return output; }
Example #8
Source File: TriadicCensus.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void writeRecord(Vertex<T, Degrees> record) throws IOException { long degree = record.f1.getDegree().getValue(); long outDegree = record.f1.getOutDegree().getValue(); long inDegree = record.f1.getInDegree().getValue(); long unidirectionalEdgesAsSource = degree - inDegree; long unidirectionalEdgesAsTarget = degree - outDegree; long bidirectionalEdges = inDegree + outDegree - degree; vertexCount++; unidirectionalEdgeCount += unidirectionalEdgesAsSource + unidirectionalEdgesAsTarget; bidirectionalEdgeCount += bidirectionalEdges; triplet021dCount += unidirectionalEdgesAsSource * (unidirectionalEdgesAsSource - 1) / 2; triplet021uCount += unidirectionalEdgesAsTarget * (unidirectionalEdgesAsTarget - 1) / 2; triplet021cCount += unidirectionalEdgesAsSource * unidirectionalEdgesAsTarget; triplet111dCount += unidirectionalEdgesAsTarget * bidirectionalEdges; triplet111uCount += unidirectionalEdgesAsSource * bidirectionalEdges; triplet201Count += bidirectionalEdges * (bidirectionalEdges - 1) / 2; }
Example #9
Source File: VertexDegreesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Vertex<LongValue, Degrees>> degreesWithoutZeroDegreeVertices = emptyGraphWithVertices .run(new VertexDegrees<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(false)); assertEquals(0, degreesWithoutZeroDegreeVertices.collect().size()); DataSet<Vertex<LongValue, Degrees>> degreesWithZeroDegreeVertices = emptyGraphWithVertices .run(new VertexDegrees<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,(0,0,0))\n" + "(1,(0,0,0))\n" + "(2,(0,0,0))"; TestBaseUtils.compareResultAsText(degreesWithZeroDegreeVertices.collect(), expectedResult); }
Example #10
Source File: EdgeMetrics.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void flatMap(Edge<T, Tuple3<ET, Degrees, Degrees>> edge, Collector<Tuple4<T, T, Degrees, LongValue>> out) throws Exception { Tuple3<ET, Degrees, Degrees> degrees = edge.f2; long sourceDegree = degrees.f1.getDegree().getValue(); long targetDegree = degrees.f2.getDegree().getValue(); boolean ordered = (sourceDegree < targetDegree || (sourceDegree == targetDegree && edge.f0.compareTo(edge.f1) < 0)); output.f0 = edge.f0; output.f1 = edge.f1; output.f2 = edge.f2.f1; output.f3 = ordered ? one : zero; out.collect(output); output.f0 = edge.f1; output.f1 = edge.f0; output.f2 = edge.f2.f2; output.f3 = ordered ? zero : one; out.collect(output); }
Example #11
Source File: EdgeDegreesPairTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(2,2,0),(3,0,3)))\n" + "(0,2,((null),(2,2,0),(3,2,1)))\n" + "(2,1,((null),(3,2,1),(3,0,3)))\n" + "(2,3,((null),(3,2,1),(4,2,2)))\n" + "(3,1,((null),(4,2,2),(3,0,3)))\n" + "(3,4,((null),(4,2,2),(1,0,1)))\n" + "(5,3,((null),(1,1,0),(4,2,2)))"; DataSet<Edge<IntValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = directedSimpleGraph .run(new EdgeDegreesPair<>()); TestBaseUtils.compareResultAsText(degreesPair.collect(), expectedResult); }
Example #12
Source File: EdgeMetrics.java From flink with Apache License 2.0 | 6 votes |
@Override public void writeRecord(Tuple3<T, Degrees, LongValue> record) throws IOException { Degrees degrees = record.f1; long degree = degrees.getDegree().getValue(); long lowDegree = record.f2.getValue(); long highDegree = degree - lowDegree; long triangleTriplets = lowDegree * (lowDegree - 1) / 2; long rectangleTriplets = triangleTriplets + lowDegree * highDegree; triangleTripletCount += triangleTriplets; rectangleTripletCount += rectangleTriplets; maximumTriangleTriplets = Math.max(maximumTriangleTriplets, triangleTriplets); maximumRectangleTriplets = Math.max(maximumRectangleTriplets, rectangleTriplets); }
Example #13
Source File: EdgeMetrics.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void writeRecord(Tuple3<T, Degrees, LongValue> record) throws IOException { Degrees degrees = record.f1; long degree = degrees.getDegree().getValue(); long lowDegree = record.f2.getValue(); long highDegree = degree - lowDegree; long triangleTriplets = lowDegree * (lowDegree - 1) / 2; long rectangleTriplets = triangleTriplets + lowDegree * highDegree; triangleTripletCount += triangleTriplets; rectangleTripletCount += rectangleTriplets; maximumTriangleTriplets = Math.max(maximumTriangleTriplets, triangleTriplets); maximumRectangleTriplets = Math.max(maximumRectangleTriplets, rectangleTriplets); }
Example #14
Source File: EdgeMetrics.java From flink with Apache License 2.0 | 6 votes |
@Override public void flatMap(Edge<T, Tuple3<ET, Degrees, Degrees>> edge, Collector<Tuple4<T, T, Degrees, LongValue>> out) throws Exception { Tuple3<ET, Degrees, Degrees> degrees = edge.f2; long sourceDegree = degrees.f1.getDegree().getValue(); long targetDegree = degrees.f2.getDegree().getValue(); boolean ordered = (sourceDegree < targetDegree || (sourceDegree == targetDegree && edge.f0.compareTo(edge.f1) < 0)); output.f0 = edge.f0; output.f1 = edge.f1; output.f2 = edge.f2.f1; output.f3 = ordered ? one : zero; out.collect(output); output.f0 = edge.f1; output.f1 = edge.f0; output.f2 = edge.f2.f2; output.f3 = ordered ? zero : one; out.collect(output); }
Example #15
Source File: EdgeTargetDegrees.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public DataSet<Edge<K, Tuple2<EV, Degrees>>> runInternal(Graph<K, VV, EV> input) throws Exception { // t, d(t) DataSet<Vertex<K, Degrees>> vertexDegrees = input .run(new VertexDegrees<K, VV, EV>() .setParallelism(parallelism)); // s, t, d(t) return input.getEdges() .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND) .where(1) .equalTo(0) .with(new JoinEdgeWithVertexDegree<>()) .setParallelism(parallelism) .name("Edge target degrees"); }
Example #16
Source File: EdgeSourceDegrees.java From flink with Apache License 2.0 | 6 votes |
@Override public DataSet<Edge<K, Tuple2<EV, Degrees>>> runInternal(Graph<K, VV, EV> input) throws Exception { // s, d(s) DataSet<Vertex<K, Degrees>> vertexDegrees = input .run(new VertexDegrees<K, VV, EV>() .setParallelism(parallelism)); // s, t, d(s) return input.getEdges() .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND) .where(0) .equalTo(0) .with(new JoinEdgeWithVertexDegree<>()) .setParallelism(parallelism) .name("Edge source degrees"); }
Example #17
Source File: EdgeDegreesPair.java From flink with Apache License 2.0 | 6 votes |
@Override public DataSet<Edge<K, Tuple3<EV, Degrees, Degrees>>> runInternal(Graph<K, VV, EV> input) throws Exception { // s, t, d(s) DataSet<Edge<K, Tuple2<EV, Degrees>>> edgeSourceDegrees = input .run(new EdgeSourceDegrees<K, VV, EV>() .setParallelism(parallelism)); // t, d(t) DataSet<Vertex<K, Degrees>> vertexDegrees = input .run(new VertexDegrees<K, VV, EV>() .setParallelism(parallelism)); // s, t, (d(s), d(t)) return edgeSourceDegrees .join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND) .where(1) .equalTo(0) .with(new JoinEdgeDegreeWithVertexDegree<>()) .setParallelism(parallelism) .name("Edge target degree"); }
Example #18
Source File: EdgeTargetDegreesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(3,0,3)))\n" + "(0,2,((null),(3,2,1)))\n" + "(2,1,((null),(3,0,3)))\n" + "(2,3,((null),(4,2,2)))\n" + "(3,1,((null),(3,0,3)))\n" + "(3,4,((null),(1,0,1)))\n" + "(5,3,((null),(4,2,2)))"; DataSet<Edge<IntValue, Tuple2<NullValue, Degrees>>> targetDegrees = directedSimpleGraph .run(new EdgeTargetDegrees<>()); TestBaseUtils.compareResultAsText(targetDegrees.collect(), expectedResult); }
Example #19
Source File: VertexDegreesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Vertex<LongValue, Degrees>> degreesWithoutZeroDegreeVertices = emptyGraphWithVertices .run(new VertexDegrees<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(false)); assertEquals(0, degreesWithoutZeroDegreeVertices.collect().size()); DataSet<Vertex<LongValue, Degrees>> degreesWithZeroDegreeVertices = emptyGraphWithVertices .run(new VertexDegrees<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,(0,0,0))\n" + "(1,(0,0,0))\n" + "(2,(0,0,0))"; TestBaseUtils.compareResultAsText(degreesWithZeroDegreeVertices.collect(), expectedResult); }
Example #20
Source File: TriangleListing.java From flink with Apache License 2.0 | 6 votes |
@Override public Tuple3<T, T, ByteValue> map(Edge<T, Tuple3<ET, Degrees, Degrees>> value) throws Exception { Tuple3<ET, Degrees, Degrees> degrees = value.f2; long sourceDegree = degrees.f1.getDegree().getValue(); long targetDegree = degrees.f2.getDegree().getValue(); if (sourceDegree < targetDegree || (sourceDegree == targetDegree && value.f0.compareTo(value.f1) < 0)) { output.f0 = value.f0; output.f1 = value.f1; output.f2 = forward; } else { output.f0 = value.f1; output.f1 = value.f0; output.f2 = reverse; } return output; }
Example #21
Source File: TriadicCensus.java From flink with Apache License 2.0 | 6 votes |
@Override public void writeRecord(Vertex<T, Degrees> record) throws IOException { long degree = record.f1.getDegree().getValue(); long outDegree = record.f1.getOutDegree().getValue(); long inDegree = record.f1.getInDegree().getValue(); long unidirectionalEdgesAsSource = degree - inDegree; long unidirectionalEdgesAsTarget = degree - outDegree; long bidirectionalEdges = inDegree + outDegree - degree; vertexCount++; unidirectionalEdgeCount += unidirectionalEdgesAsSource + unidirectionalEdgesAsTarget; bidirectionalEdgeCount += bidirectionalEdges; triplet021dCount += unidirectionalEdgesAsSource * (unidirectionalEdgesAsSource - 1) / 2; triplet021uCount += unidirectionalEdgesAsTarget * (unidirectionalEdgesAsTarget - 1) / 2; triplet021cCount += unidirectionalEdgesAsSource * unidirectionalEdgesAsTarget; triplet111dCount += unidirectionalEdgesAsTarget * bidirectionalEdges; triplet111uCount += unidirectionalEdgesAsSource * bidirectionalEdges; triplet201Count += bidirectionalEdges * (bidirectionalEdges - 1) / 2; }
Example #22
Source File: VertexMetrics.java From flink with Apache License 2.0 | 6 votes |
@Override public VertexMetrics<K, VV, EV> run(Graph<K, VV, EV> input) throws Exception { super.run(input); DataSet<Vertex<K, Degrees>> vertexDegree = input .run(new VertexDegrees<K, VV, EV>() .setIncludeZeroDegreeVertices(includeZeroDegreeVertices) .setParallelism(parallelism)); vertexMetricsHelper = new VertexMetricsHelper<>(); vertexDegree .output(vertexMetricsHelper) .name("Vertex metrics"); return this; }
Example #23
Source File: VertexMetrics.java From flink with Apache License 2.0 | 6 votes |
@Override public void writeRecord(Vertex<T, Degrees> record) throws IOException { long degree = record.f1.getDegree().getValue(); long outDegree = record.f1.getOutDegree().getValue(); long inDegree = record.f1.getInDegree().getValue(); long bidirectionalEdges = outDegree + inDegree - degree; long triplets = degree * (degree - 1) / 2; vertexCount++; unidirectionalEdgeCount += degree - bidirectionalEdges; bidirectionalEdgeCount += bidirectionalEdges; tripletCount += triplets; maximumDegree = Math.max(maximumDegree, degree); maximumOutDegree = Math.max(maximumOutDegree, outDegree); maximumInDegree = Math.max(maximumInDegree, inDegree); maximumTriplets = Math.max(maximumTriplets, triplets); }
Example #24
Source File: EdgeSourceDegreesTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(2,2,0)))\n" + "(0,2,((null),(2,2,0)))\n" + "(2,1,((null),(3,2,1)))\n" + "(2,3,((null),(3,2,1)))\n" + "(3,1,((null),(4,2,2)))\n" + "(3,4,((null),(4,2,2)))\n" + "(5,3,((null),(1,1,0)))"; DataSet<Edge<IntValue, Tuple2<NullValue, Degrees>>> sourceDegrees = directedSimpleGraph .run(new EdgeSourceDegrees<>()); TestBaseUtils.compareResultAsText(sourceDegrees.collect(), expectedResult); }
Example #25
Source File: EdgeDegreesPairTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,1,((null),(2,2,0),(3,0,3)))\n" + "(0,2,((null),(2,2,0),(3,2,1)))\n" + "(2,1,((null),(3,2,1),(3,0,3)))\n" + "(2,3,((null),(3,2,1),(4,2,2)))\n" + "(3,1,((null),(4,2,2),(3,0,3)))\n" + "(3,4,((null),(4,2,2),(1,0,1)))\n" + "(5,3,((null),(1,1,0),(4,2,2)))"; DataSet<Edge<IntValue, Tuple3<NullValue, Degrees, Degrees>>> degreesPair = directedSimpleGraph .run(new EdgeDegreesPair<>()); TestBaseUtils.compareResultAsText(degreesPair.collect(), expectedResult); }
Example #26
Source File: VertexDegreesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithEmptyGraphWithoutVertices() throws Exception { DataSet<Vertex<LongValue, Degrees>> degreesWithoutZeroDegreeVertices = emptyGraphWithoutVertices .run(new VertexDegrees<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(false)); assertEquals(0, degreesWithoutZeroDegreeVertices.collect().size()); DataSet<Vertex<LongValue, Degrees>> degreesWithZeroDegreeVertices = emptyGraphWithoutVertices .run(new VertexDegrees<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); assertEquals(0, degreesWithZeroDegreeVertices.collect().size()); }
Example #27
Source File: PageRank.java From flink with Apache License 2.0 | 5 votes |
@Override public Edge<T, LongValue> map(Edge<T, Tuple2<ET, Degrees>> edge) throws Exception { output.f0 = edge.f0; output.f1 = edge.f1; output.f2 = edge.f2.f1.getOutDegree(); return output; }
Example #28
Source File: LocalClusteringCoefficient.java From flink with Apache License 2.0 | 5 votes |
@Override public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception { // u, v, w, bitmask DataSet<TriangleListing.Result<K>> triangles = input .run(new TriangleListing<K, VV, EV>() .setParallelism(parallelism)); // u, edge count DataSet<Tuple2<K, LongValue>> triangleVertices = triangles .flatMap(new SplitTriangles<>()) .name("Split triangle vertices"); // u, triangle count DataSet<Tuple2<K, LongValue>> vertexTriangleCount = triangleVertices .groupBy(0) .reduce(new CountTriangles<>()) .setCombineHint(CombineHint.HASH) .name("Count triangles") .setParallelism(parallelism); // u, deg(u) DataSet<Vertex<K, Degrees>> vertexDegree = input .run(new VertexDegrees<K, VV, EV>() .setIncludeZeroDegreeVertices(includeZeroDegreeVertices.get()) .setParallelism(parallelism)); // u, deg(u), triangle count return vertexDegree .leftOuterJoin(vertexTriangleCount) .where(0) .equalTo(0) .with(new JoinVertexDegreeWithTriangleCount<>()) .setParallelism(parallelism) .name("Clustering coefficient"); }
Example #29
Source File: VertexDegreesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithUndirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, Degrees>> degrees = undirectedSimpleGraph .run(new VertexDegrees<>()); String expectedResult = "(0,(2,2,2))\n" + "(1,(3,3,3))\n" + "(2,(3,3,3))\n" + "(3,(4,4,4))\n" + "(4,(1,1,1))\n" + "(5,(1,1,1))"; TestBaseUtils.compareResultAsText(degrees.collect(), expectedResult); }
Example #30
Source File: VertexDegrees.java From flink with Apache License 2.0 | 5 votes |
@Override public Vertex<T, Degrees> join(Vertex<T, TV> vertex, Vertex<T, Degrees> vertexDegree) throws Exception { if (vertexDegree == null) { output.f0 = vertex.f0; return output; } else { return vertexDegree; } }