org.apache.flink.graph.library.clustering.directed.LocalClusteringCoefficient.Result Java Examples

The following examples show how to use org.apache.flink.graph.library.clustering.directed.LocalClusteringCoefficient.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: LocalClusteringCoefficient.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(TriangleListing.Result<T> value, Collector<Tuple2<T, LongValue>> out)
		throws Exception {
	byte bitmask = value.getBitmask().getValue();

	output.f0 = value.getVertexId0();
	output.f1 = ((bitmask & 0b000011) == 0b000011) ? two : one;
	out.collect(output);

	output.f0 = value.getVertexId1();
	output.f1 = ((bitmask & 0b001100) == 0b001100) ? two : one;
	out.collect(output);

	output.f0 = value.getVertexId2();
	output.f1 = ((bitmask & 0b110000) == 0b110000) ? two : one;
	out.collect(output);
}
 
Example #2
Source File: LocalClusteringCoefficient.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(TriangleListing.Result<T> value, Collector<Tuple2<T, LongValue>> out)
		throws Exception {
	byte bitmask = value.getBitmask().getValue();

	output.f0 = value.getVertexId0();
	output.f1 = ((bitmask & 0b000011) == 0b000011) ? two : one;
	out.collect(output);

	output.f0 = value.getVertexId1();
	output.f1 = ((bitmask & 0b001100) == 0b001100) ? two : one;
	out.collect(output);

	output.f0 = value.getVertexId2();
	output.f1 = ((bitmask & 0b110000) == 0b110000) ? two : one;
	out.collect(output);
}
 
Example #3
Source File: LocalClusteringCoefficient.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(TriangleListing.Result<T> value, Collector<Tuple2<T, LongValue>> out)
		throws Exception {
	byte bitmask = value.getBitmask().getValue();

	output.f0 = value.getVertexId0();
	output.f1 = ((bitmask & 0b000011) == 0b000011) ? two : one;
	out.collect(output);

	output.f0 = value.getVertexId1();
	output.f1 = ((bitmask & 0b001100) == 0b001100) ? two : one;
	out.collect(output);

	output.f0 = value.getVertexId2();
	output.f1 = ((bitmask & 0b110000) == 0b110000) ? two : one;
	out.collect(output);
}
 
Example #4
Source File: LocalClusteringCoefficientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMatGraph() throws Exception {
	DataSet<Result<LongValue>> cc = directedRMatGraph(10, 16)
		.run(new LocalClusteringCoefficient<>());

	Checksum checksum = new org.apache.flink.graph.asm.dataset.ChecksumHashCode<Result<LongValue>>()
		.run(cc)
		.execute();

	assertEquals(902, checksum.getCount());
	assertEquals(0x000001bf83866775L, checksum.getChecksum());
}
 
Example #5
Source File: LocalClusteringCoefficient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: LocalClusteringCoefficientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example #7
Source File: LocalClusteringCoefficientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleGraph() throws Exception {
	String expectedResult =
		"(0,2,1)\n" +
		"(1,3,2)\n" +
		"(2,3,2)\n" +
		"(3,4,1)\n" +
		"(4,1,0)\n" +
		"(5,1,0)";

	DataSet<Result<IntValue>> cc = directedSimpleGraph
		.run(new LocalClusteringCoefficient<>());

	TestBaseUtils.compareResultAsText(cc.collect(), expectedResult);
}
 
Example #8
Source File: LocalClusteringCoefficient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Result<T> join(Vertex<T, Degrees> vertexAndDegree, Tuple2<T, LongValue> vertexAndTriangleCount)
		throws Exception {
	output.setVertexId0(vertexAndDegree.f0);
	output.setDegree(vertexAndDegree.f1.f0);
	output.setTriangleCount((vertexAndTriangleCount == null) ? zero : vertexAndTriangleCount.f1);

	return output;
}
 
Example #9
Source File: LocalClusteringCoefficient.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: LocalClusteringCoefficientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMatGraph() throws Exception {
	DataSet<Result<LongValue>> cc = directedRMatGraph(10, 16)
		.run(new LocalClusteringCoefficient<>());

	Checksum checksum = new org.apache.flink.graph.asm.dataset.ChecksumHashCode<Result<LongValue>>()
		.run(cc)
		.execute();

	assertEquals(902, checksum.getCount());
	assertEquals(0x000001bf83866775L, checksum.getChecksum());
}
 
Example #11
Source File: LocalClusteringCoefficientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example #12
Source File: LocalClusteringCoefficientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleGraph() throws Exception {
	String expectedResult =
		"(0,2,1)\n" +
		"(1,3,2)\n" +
		"(2,3,2)\n" +
		"(3,4,1)\n" +
		"(4,1,0)\n" +
		"(5,1,0)";

	DataSet<Result<IntValue>> cc = directedSimpleGraph
		.run(new LocalClusteringCoefficient<>());

	TestBaseUtils.compareResultAsText(cc.collect(), expectedResult);
}
 
Example #13
Source File: LocalClusteringCoefficient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Result<T> join(Vertex<T, Degrees> vertexAndDegree, Tuple2<T, LongValue> vertexAndTriangleCount)
		throws Exception {
	output.setVertexId0(vertexAndDegree.f0);
	output.setDegree(vertexAndDegree.f1.f0);
	output.setTriangleCount((vertexAndTriangleCount == null) ? zero : vertexAndTriangleCount.f1);

	return output;
}
 
Example #14
Source File: LocalClusteringCoefficient.java    From flink with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: LocalClusteringCoefficientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMatGraph() throws Exception {
	DataSet<Result<LongValue>> cc = directedRMatGraph(10, 16)
		.run(new LocalClusteringCoefficient<>());

	Checksum checksum = new org.apache.flink.graph.asm.dataset.ChecksumHashCode<Result<LongValue>>()
		.run(cc)
		.execute();

	assertEquals(902, checksum.getCount());
	assertEquals(0x000001bf83866775L, checksum.getChecksum());
}
 
Example #16
Source File: LocalClusteringCoefficientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example #17
Source File: LocalClusteringCoefficientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleGraph() throws Exception {
	String expectedResult =
		"(0,2,1)\n" +
		"(1,3,2)\n" +
		"(2,3,2)\n" +
		"(3,4,1)\n" +
		"(4,1,0)\n" +
		"(5,1,0)";

	DataSet<Result<IntValue>> cc = directedSimpleGraph
		.run(new LocalClusteringCoefficient<>());

	TestBaseUtils.compareResultAsText(cc.collect(), expectedResult);
}
 
Example #18
Source File: LocalClusteringCoefficient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Result<T> join(Vertex<T, Degrees> vertexAndDegree, Tuple2<T, LongValue> vertexAndTriangleCount)
		throws Exception {
	output.setVertexId0(vertexAndDegree.f0);
	output.setDegree(vertexAndDegree.f1.f0);
	output.setTriangleCount((vertexAndTriangleCount == null) ? zero : vertexAndTriangleCount.f1);

	return output;
}