use of org.apache.flink.graph.spargel.ScatterGatherConfiguration in project flink by apache.
the class PageRank method run.
@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<K>(), new VertexRankUpdater<K>(beta), maxIterations, parameters).getVertices();
}
use of org.apache.flink.graph.spargel.ScatterGatherConfiguration in project flink by apache.
the class ScatterGatherConfigurationITCase method testOutDegreesSet.
@Test
public void testOutDegreesSet() throws Exception {
/*
* Test that if the degrees are set, they can be accessed in every superstep
* inside the update function and the value
* is correctly computed for degrees in the scatter function.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env);
// configure the iteration
ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
parameters.setOptDegrees(true);
DataSet<Vertex<Long, Long>> verticesWithDegrees = graph.runScatterGatherIteration(new DegreesMessageFunction(), new UpdateFunctionOutDegrees(), 5, parameters).getVertices();
List<Vertex<Long, Long>> result = verticesWithDegrees.collect();
expectedResult = "1,2\n" + "2,1\n" + "3,2\n" + "4,1\n" + "5,1";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.spargel.ScatterGatherConfiguration in project flink by apache.
the class ScatterGatherConfigurationITCase method testIterationALLDirection.
@Test
public void testIterationALLDirection() throws Exception {
/*
* Test that if the direction parameter is set to ALL,
* messages are collected from all the neighbors and sent to all the neighbors.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, HashSet<Long>, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env).mapVertices(new InitialiseHashSetMapper());
// configure the iteration
ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
parameters.setDirection(EdgeDirection.ALL);
DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runScatterGatherIteration(new IdMessengerAll(), new VertexUpdateDirection(), 5, parameters).getVertices();
List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();
expectedResult = "1,[2, 3, 5]\n" + "2,[1, 3]\n" + "3,[1, 2, 4, 5]\n" + "4,[3, 5]\n" + "5,[1, 3, 4]";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.spargel.ScatterGatherConfiguration in project flink by apache.
the class ScatterGatherConfigurationITCase method testSendToAllDirectionIN.
@Test
public void testSendToAllDirectionIN() throws Exception {
/*
* Test that sendMessageToAllNeighbors() works correctly
* when the direction is set to IN
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, HashSet<Long>, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env).mapVertices(new InitialiseHashSetMapper());
// configure the iteration
ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
parameters.setDirection(EdgeDirection.IN);
DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runScatterGatherIteration(new SendMsgToAll(), new VertexUpdateDirection(), 5, parameters).getVertices();
List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();
expectedResult = "1,[2, 3]\n" + "2,[3]\n" + "3,[4, 5]\n" + "4,[5]\n" + "5,[1]";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.spargel.ScatterGatherConfiguration in project flink by apache.
the class ScatterGatherConfigurationITCase method testDirectionALLAndDegrees.
@Test
public void testDirectionALLAndDegrees() throws Exception {
/*
* Compute the number of neighbors in a vertex - centric manner, and verify that it is equal to
* the sum: inDegree + outDegree.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Boolean, Long> graph = Graph.fromCollection(TestGraphUtils.getLongBooleanVertices(), TestGraphUtils.getLongLongEdges(), env);
// configure the iteration
ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
parameters.setOptDegrees(true);
parameters.setDirection(EdgeDirection.ALL);
DataSet<Vertex<Long, Boolean>> verticesWithNumNeighbors = graph.runScatterGatherIteration(new IdMessenger(), new VertexUpdateNumNeighbors(), 1, parameters).getVertices();
List<Vertex<Long, Boolean>> result = verticesWithNumNeighbors.collect();
expectedResult = "1,true\n" + "2,true\n" + "3,true\n" + "4,true\n" + "5,true";
compareResultAsTuples(result, expectedResult);
}
Aggregations