org.apache.flink.graph.library.metric.undirected.VertexMetrics.Result Java Examples

The following examples show how to use org.apache.flink.graph.library.metric.undirected.VertexMetrics.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: VertexMetrics.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
	if (obj == null) {
		return false;
	}

	if (obj == this) {
		return true;
	}

	if (obj.getClass() != getClass()) {
		return false;
	}

	Result rhs = (Result) obj;

	return new EqualsBuilder()
		.append(vertexCount, rhs.vertexCount)
		.append(edgeCount, rhs.edgeCount)
		.append(tripletCount, rhs.tripletCount)
		.append(maximumDegree, rhs.maximumDegree)
		.append(maximumTriplets, rhs.maximumTriplets)
		.isEquals();
}
 
Example #2
Source File: VertexMetrics.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
	if (obj == null) {
		return false;
	}

	if (obj == this) {
		return true;
	}

	if (obj.getClass() != getClass()) {
		return false;
	}

	Result rhs = (Result) obj;

	return new EqualsBuilder()
		.append(vertexCount, rhs.vertexCount)
		.append(edgeCount, rhs.edgeCount)
		.append(tripletCount, rhs.tripletCount)
		.append(maximumDegree, rhs.maximumDegree)
		.append(maximumTriplets, rhs.maximumTriplets)
		.isEquals();
}
 
Example #3
Source File: VertexMetrics.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
	if (obj == null) {
		return false;
	}

	if (obj == this) {
		return true;
	}

	if (obj.getClass() != getClass()) {
		return false;
	}

	Result rhs = (Result) obj;

	return new EqualsBuilder()
		.append(vertexCount, rhs.vertexCount)
		.append(edgeCount, rhs.edgeCount)
		.append(tripletCount, rhs.tripletCount)
		.append(maximumDegree, rhs.maximumDegree)
		.append(maximumTriplets, rhs.maximumTriplets)
		.isEquals();
}
 
Example #4
Source File: VertexMetrics.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Result getResult() {
	long vertexCount = vertexMetricsHelper.getAccumulator(env, VERTEX_COUNT);
	long edgeCount = vertexMetricsHelper.getAccumulator(env, EDGE_COUNT);
	long tripletCount = vertexMetricsHelper.getAccumulator(env, TRIPLET_COUNT);
	long maximumDegree = vertexMetricsHelper.getAccumulator(env, MAXIMUM_DEGREE);
	long maximumTriplets = vertexMetricsHelper.getAccumulator(env, MAXIMUM_TRIPLETS);

	// each edge is counted twice, once from each vertex, so must be halved
	return new Result(vertexCount, edgeCount / 2, tripletCount, maximumDegree, maximumTriplets);
}
 
Example #5
Source File: VertexMetrics.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Result getResult() {
	long vertexCount = vertexMetricsHelper.getAccumulator(env, VERTEX_COUNT);
	long edgeCount = vertexMetricsHelper.getAccumulator(env, EDGE_COUNT);
	long tripletCount = vertexMetricsHelper.getAccumulator(env, TRIPLET_COUNT);
	long maximumDegree = vertexMetricsHelper.getAccumulator(env, MAXIMUM_DEGREE);
	long maximumTriplets = vertexMetricsHelper.getAccumulator(env, MAXIMUM_TRIPLETS);

	// each edge is counted twice, once from each vertex, so must be halved
	return new Result(vertexCount, edgeCount / 2, tripletCount, maximumDegree, maximumTriplets);
}
 
Example #6
Source File: VertexMetrics.java    From flink with Apache License 2.0 5 votes vote down vote up
public Result(long vertexCount, long edgeCount, long tripletCount, long maximumDegree, long maximumTriplets) {
	this.vertexCount = vertexCount;
	this.edgeCount = edgeCount;
	this.tripletCount = tripletCount;
	this.maximumDegree = maximumDegree;
	this.maximumTriplets = maximumTriplets;
}
 
Example #7
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param includeZeroDegreeVertices whether to include zero-degree vertices
 * @param result expected {@link Result}
 * @param averageDegree result average degree
 * @param density result density
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T>> void validate(
		Graph<T, NullValue, NullValue> graph, boolean includeZeroDegreeVertices,
		Result result, float averageDegree, float density) throws Exception {
	Result vertexMetrics = new VertexMetrics<T, NullValue, NullValue>()
		.setIncludeZeroDegreeVertices(includeZeroDegreeVertices)
		.run(graph)
		.execute();

	assertEquals(result, vertexMetrics);
	assertEquals(averageDegree, vertexMetrics.getAverageDegree(), ACCURACY);
	assertEquals(density, vertexMetrics.getDensity(), ACCURACY);
}
 
Example #8
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCompleteGraph() throws Exception {
	long expectedDegree = completeGraphVertexCount - 1;
	long expectedEdges = completeGraphVertexCount * expectedDegree / 2;
	long expectedMaximumTriplets = CombinatoricsUtils.binomialCoefficient((int) expectedDegree, 2);
	long expectedTriplets = completeGraphVertexCount * expectedMaximumTriplets;

	Result expectedResult = new Result(completeGraphVertexCount, expectedEdges, expectedTriplets,
		expectedDegree, expectedMaximumTriplets);

	validate(completeGraph, false, expectedResult, expectedDegree, 1.0f);
}
 
Example #9
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param includeZeroDegreeVertices whether to include zero-degree vertices
 * @param result expected {@link Result}
 * @param averageDegree result average degree
 * @param density result density
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T>> void validate(
		Graph<T, NullValue, NullValue> graph, boolean includeZeroDegreeVertices,
		Result result, float averageDegree, float density) throws Exception {
	Result vertexMetrics = new VertexMetrics<T, NullValue, NullValue>()
		.setIncludeZeroDegreeVertices(includeZeroDegreeVertices)
		.run(graph)
		.execute();

	assertEquals(result, vertexMetrics);
	assertEquals(averageDegree, vertexMetrics.getAverageDegree(), ACCURACY);
	assertEquals(density, vertexMetrics.getDensity(), ACCURACY);
}
 
Example #10
Source File: VertexMetrics.java    From flink with Apache License 2.0 5 votes vote down vote up
public Result(long vertexCount, long edgeCount, long tripletCount, long maximumDegree, long maximumTriplets) {
	this.vertexCount = vertexCount;
	this.edgeCount = edgeCount;
	this.tripletCount = tripletCount;
	this.maximumDegree = maximumDegree;
	this.maximumTriplets = maximumTriplets;
}
 
Example #11
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCompleteGraph() throws Exception {
	long expectedDegree = completeGraphVertexCount - 1;
	long expectedEdges = completeGraphVertexCount * expectedDegree / 2;
	long expectedMaximumTriplets = CombinatoricsUtils.binomialCoefficient((int) expectedDegree, 2);
	long expectedTriplets = completeGraphVertexCount * expectedMaximumTriplets;

	Result expectedResult = new Result(completeGraphVertexCount, expectedEdges, expectedTriplets,
		expectedDegree, expectedMaximumTriplets);

	validate(completeGraph, false, expectedResult, expectedDegree, 1.0f);
}
 
Example #12
Source File: VertexMetricsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCompleteGraph() throws Exception {
	long expectedDegree = completeGraphVertexCount - 1;
	long expectedEdges = completeGraphVertexCount * expectedDegree / 2;
	long expectedMaximumTriplets = CombinatoricsUtils.binomialCoefficient((int) expectedDegree, 2);
	long expectedTriplets = completeGraphVertexCount * expectedMaximumTriplets;

	Result expectedResult = new Result(completeGraphVertexCount, expectedEdges, expectedTriplets,
		expectedDegree, expectedMaximumTriplets);

	validate(completeGraph, false, expectedResult, expectedDegree, 1.0f);
}
 
Example #13
Source File: VertexMetrics.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Result getResult() {
	long vertexCount = vertexMetricsHelper.getAccumulator(env, VERTEX_COUNT);
	long edgeCount = vertexMetricsHelper.getAccumulator(env, EDGE_COUNT);
	long tripletCount = vertexMetricsHelper.getAccumulator(env, TRIPLET_COUNT);
	long maximumDegree = vertexMetricsHelper.getAccumulator(env, MAXIMUM_DEGREE);
	long maximumTriplets = vertexMetricsHelper.getAccumulator(env, MAXIMUM_TRIPLETS);

	// each edge is counted twice, once from each vertex, so must be halved
	return new Result(vertexCount, edgeCount / 2, tripletCount, maximumDegree, maximumTriplets);
}
 
Example #14
Source File: VertexMetricsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param includeZeroDegreeVertices whether to include zero-degree vertices
 * @param result expected {@link Result}
 * @param averageDegree result average degree
 * @param density result density
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T>> void validate(
		Graph<T, NullValue, NullValue> graph, boolean includeZeroDegreeVertices,
		Result result, float averageDegree, float density) throws Exception {
	Result vertexMetrics = new VertexMetrics<T, NullValue, NullValue>()
		.setIncludeZeroDegreeVertices(includeZeroDegreeVertices)
		.run(graph)
		.execute();

	assertEquals(result, vertexMetrics);
	assertEquals(averageDegree, vertexMetrics.getAverageDegree(), ACCURACY);
	assertEquals(density, vertexMetrics.getDensity(), ACCURACY);
}
 
Example #15
Source File: VertexMetrics.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public Result(long vertexCount, long edgeCount, long tripletCount, long maximumDegree, long maximumTriplets) {
	this.vertexCount = vertexCount;
	this.edgeCount = edgeCount;
	this.tripletCount = tripletCount;
	this.maximumDegree = maximumDegree;
	this.maximumTriplets = maximumTriplets;
}
 
Example #16
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	Result expectedResult = new Result(902, 10442, 1003442, 463, 106953);
	validate(undirectedRMatGraph(10, 16), false, expectedResult, 23.1529933f, 0.0256969f);
}
 
Example #17
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	validate(emptyGraphWithVertices, false, new Result(0, 0, 0, 0, 0), Float.NaN, Float.NaN);
	validate(emptyGraphWithVertices, true, new Result(3, 0, 0, 0, 0), 0.0f, 0.0f);
}
 
Example #18
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	validate(undirectedSimpleGraph, false, new Result(6, 7, 13, 4, 6), 14f / 6, 7f / 15);
}
 
Example #19
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithEmptyGraphWithoutVertices() throws Exception {
	Result expectedResult =  new Result(0, 0, 0, 0, 0);
	validate(emptyGraphWithoutVertices, false, expectedResult, Float.NaN, Float.NaN);
	validate(emptyGraphWithoutVertices, true, expectedResult, Float.NaN, Float.NaN);
}
 
Example #20
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	Result expectedResult = new Result(902, 10442, 1003442, 463, 106953);
	validate(undirectedRMatGraph(10, 16), false, expectedResult, 23.1529933f, 0.0256969f);
}
 
Example #21
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithEmptyGraphWithoutVertices() throws Exception {
	Result expectedResult =  new Result(0, 0, 0, 0, 0);
	validate(emptyGraphWithoutVertices, false, expectedResult, Float.NaN, Float.NaN);
	validate(emptyGraphWithoutVertices, true, expectedResult, Float.NaN, Float.NaN);
}
 
Example #22
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	validate(emptyGraphWithVertices, false, new Result(0, 0, 0, 0, 0), Float.NaN, Float.NaN);
	validate(emptyGraphWithVertices, true, new Result(3, 0, 0, 0, 0), 0.0f, 0.0f);
}
 
Example #23
Source File: VertexMetricsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	validate(undirectedSimpleGraph, false, new Result(6, 7, 13, 4, 6), 14f / 6, 7f / 15);
}
 
Example #24
Source File: VertexMetricsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithRMatGraph() throws Exception {
	Result expectedResult = new Result(902, 10442, 1003442, 463, 106953);
	validate(undirectedRMatGraph(10, 16), false, expectedResult, 23.1529933f, 0.0256969f);
}
 
Example #25
Source File: VertexMetricsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithEmptyGraphWithoutVertices() throws Exception {
	Result expectedResult =  new Result(0, 0, 0, 0, 0);
	validate(emptyGraphWithoutVertices, false, expectedResult, Float.NaN, Float.NaN);
	validate(emptyGraphWithoutVertices, true, expectedResult, Float.NaN, Float.NaN);
}
 
Example #26
Source File: VertexMetricsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	validate(emptyGraphWithVertices, false, new Result(0, 0, 0, 0, 0), Float.NaN, Float.NaN);
	validate(emptyGraphWithVertices, true, new Result(3, 0, 0, 0, 0), 0.0f, 0.0f);
}
 
Example #27
Source File: VertexMetricsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithSimpleGraph() throws Exception {
	validate(undirectedSimpleGraph, false, new Result(6, 7, 13, 4, 6), 14f / 6, 7f / 15);
}