Search in sources :

Example 1 with ScatterGatherConfiguration

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();
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) ScatterGatherConfiguration(org.apache.flink.graph.spargel.ScatterGatherConfiguration)

Example 2 with ScatterGatherConfiguration

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);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ScatterGatherConfiguration(org.apache.flink.graph.spargel.ScatterGatherConfiguration) Test(org.junit.Test)

Example 3 with ScatterGatherConfiguration

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);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ScatterGatherConfiguration(org.apache.flink.graph.spargel.ScatterGatherConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ScatterGatherConfiguration

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);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ScatterGatherConfiguration(org.apache.flink.graph.spargel.ScatterGatherConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ScatterGatherConfiguration

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);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ScatterGatherConfiguration(org.apache.flink.graph.spargel.ScatterGatherConfiguration) Test(org.junit.Test)

Aggregations

ScatterGatherConfiguration (org.apache.flink.graph.spargel.ScatterGatherConfiguration)13 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)12 Vertex (org.apache.flink.graph.Vertex)12 Test (org.junit.Test)11 HashSet (java.util.HashSet)5 LongSumAggregator (org.apache.flink.api.common.aggregators.LongSumAggregator)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Edge (org.apache.flink.graph.Edge)1 IncrementalSSSP (org.apache.flink.graph.examples.IncrementalSSSP)1