Java Code Examples for org.apache.flink.graph.Graph#outDegrees()

The following examples show how to use org.apache.flink.graph.Graph#outDegrees() . 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: DegreesITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutDegrees() throws Exception {
	/*
	* Test outDegrees()
	*/
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,2\n" +
		"4,1\n" +
		"5,1\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 2
Source File: DegreesITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutDegreesWithNoOutEdges() throws Exception {
	/*
	 * Test outDegrees() no outgoing edges
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeDataWithZeroDegree(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,3\n" +
		"2,1\n" +
		"3,1\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 3
Source File: DegreesITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDegreesWithDisconnectedData() throws Exception {
	/*
	 * Test getDegrees() with disconnected data
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, NullValue, Long> graph =
		Graph.fromDataSet(TestGraphUtils.getDisconnectedLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,0\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 4
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutDegrees() throws Exception {
	/*
	* Test outDegrees()
	*/
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,2\n" +
		"4,1\n" +
		"5,1\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 5
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutDegreesWithNoOutEdges() throws Exception {
	/*
	 * Test outDegrees() no outgoing edges
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeDataWithZeroDegree(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,3\n" +
		"2,1\n" +
		"3,1\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 6
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDegreesWithDisconnectedData() throws Exception {
	/*
	 * Test getDegrees() with disconnected data
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, NullValue, Long> graph =
		Graph.fromDataSet(TestGraphUtils.getDisconnectedLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,0\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 7
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutDegrees() throws Exception {
	/*
	* Test outDegrees()
	*/
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,2\n" +
		"4,1\n" +
		"5,1\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 8
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutDegreesWithNoOutEdges() throws Exception {
	/*
	 * Test outDegrees() no outgoing edges
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeDataWithZeroDegree(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,3\n" +
		"2,1\n" +
		"3,1\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 9
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDegreesWithDisconnectedData() throws Exception {
	/*
	 * Test getDegrees() with disconnected data
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, NullValue, Long> graph =
		Graph.fromDataSet(TestGraphUtils.getDisconnectedLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,0\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 10
Source File: GSAPageRank.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, Double>> run(Graph<K, Double, Double> network) throws Exception {
	DataSet<Tuple2<K, LongValue>> vertexOutDegrees = network.outDegrees();

	Graph<K, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(vertexOutDegrees, new InitWeights());

	GSAConfiguration parameters = new GSAConfiguration();
	parameters.setOptNumVertices(true);

	return networkWithWeights.runGatherSumApplyIteration(new GatherRanks(), new SumRanks(),
		new UpdateRanks<>(beta), maxIterations, parameters)
			.getVertices();
}
 
Example 11
Source File: PageRank.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, Double>> run(Graph<K, Double, Double> network) throws Exception {
	DataSet<Tuple2<K, LongValue>> vertexOutDegrees = network.outDegrees();

	Graph<K, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(vertexOutDegrees, new InitWeights());

	ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
	parameters.setOptNumVertices(true);

	return networkWithWeights.runScatterGatherIteration(new RankMessenger<>(),
		new VertexRankUpdater<>(beta), maxIterations, parameters)
			.getVertices();
}
 
Example 12
Source File: GSAPageRank.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, Double>> run(Graph<K, Double, Double> network) throws Exception {
	DataSet<Tuple2<K, LongValue>> vertexOutDegrees = network.outDegrees();

	Graph<K, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(vertexOutDegrees, new InitWeights());

	GSAConfiguration parameters = new GSAConfiguration();
	parameters.setOptNumVertices(true);

	return networkWithWeights.runGatherSumApplyIteration(new GatherRanks(), new SumRanks(),
		new UpdateRanks<>(beta), maxIterations, parameters)
			.getVertices();
}
 
Example 13
Source File: PageRank.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, Double>> run(Graph<K, Double, Double> network) throws Exception {
	DataSet<Tuple2<K, LongValue>> vertexOutDegrees = network.outDegrees();

	Graph<K, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(vertexOutDegrees, new InitWeights());

	ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
	parameters.setOptNumVertices(true);

	return networkWithWeights.runScatterGatherIteration(new RankMessenger<>(),
		new VertexRankUpdater<>(beta), maxIterations, parameters)
			.getVertices();
}
 
Example 14
Source File: GSAPageRank.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, Double>> run(Graph<K, Double, Double> network) throws Exception {
	DataSet<Tuple2<K, LongValue>> vertexOutDegrees = network.outDegrees();

	Graph<K, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(vertexOutDegrees, new InitWeights());

	GSAConfiguration parameters = new GSAConfiguration();
	parameters.setOptNumVertices(true);

	return networkWithWeights.runGatherSumApplyIteration(new GatherRanks(), new SumRanks(),
		new UpdateRanks<>(beta), maxIterations, parameters)
			.getVertices();
}
 
Example 15
Source File: PageRank.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, Double>> run(Graph<K, Double, Double> network) throws Exception {
	DataSet<Tuple2<K, LongValue>> vertexOutDegrees = network.outDegrees();

	Graph<K, Double, Double> networkWithWeights = network
			.joinWithEdgesOnSource(vertexOutDegrees, new InitWeights());

	ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
	parameters.setOptNumVertices(true);

	return networkWithWeights.runScatterGatherIteration(new RankMessenger<>(),
		new VertexRankUpdater<>(beta), maxIterations, parameters)
			.getVertices();
}