Search in sources :

Example 1 with GSAConfiguration

use of org.apache.flink.graph.gsa.GSAConfiguration in project flink by apache.

the class GSAPageRank 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());
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.setOptNumVertices(true);
    return networkWithWeights.runGatherSumApplyIteration(new GatherRanks(), new SumRanks(), new UpdateRanks<K>(beta), maxIterations, parameters).getVertices();
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) GSAConfiguration(org.apache.flink.graph.gsa.GSAConfiguration)

Example 2 with GSAConfiguration

use of org.apache.flink.graph.gsa.GSAConfiguration in project flink by apache.

the class GatherSumApplyConfigurationITCase method testIterationDirectionALL.

@Test
public void testIterationDirectionALL() throws Exception {
    /*
		 * Test that if the direction parameter OUT is given, the iteration works as expected
		 * (i.e. it gathers information from both IN and OUT edges and neighbors
		 * When data is gathered from the ALL edges the Gather Sum and Apply functions
		 * set the set of vertices which are connected to a Vertex through some path as value of that vertex
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.setDirection(EdgeDirection.ALL);
    List<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdges();
    edges.remove(0);
    Graph<Long, HashSet<Long>, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), edges, env).mapVertices(new GatherSumApplyConfigurationITCase.InitialiseHashSetMapper());
    DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runGatherSumApplyIteration(new GetReachableVertices(), new FindAllReachableVertices(), new UpdateReachableVertices(), 4, parameters).getVertices();
    List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();
    expectedResult = "1,[1, 2, 3, 4, 5]\n" + "2,[1, 2, 3, 4, 5]\n" + "3,[1, 2, 3, 4, 5]\n" + "4,[1, 2, 3, 4, 5]\n" + "5,[1, 2, 3, 4, 5]\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) GSAConfiguration(org.apache.flink.graph.gsa.GSAConfiguration) Edge(org.apache.flink.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with GSAConfiguration

use of org.apache.flink.graph.gsa.GSAConfiguration in project flink by apache.

the class GatherSumApplyConfigurationITCase method testIterationDirectionIN.

@Test
public void testIterationDirectionIN() throws Exception {
    /*
		 * Test that if the direction parameter IN is given, the iteration works as expected
		 * (i.e. it gathers information from the OUT edges and neighbors and the information is calculated for an IN edge
		 * When data is gathered from the OUT edges the Gather Sum and Apply functions
		 * set the set of vertices which have path from a vertex as the value of that vertex
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.setDirection(EdgeDirection.IN);
    List<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdges();
    edges.remove(0);
    Graph<Long, HashSet<Long>, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), edges, env).mapVertices(new GatherSumApplyConfigurationITCase.InitialiseHashSetMapper());
    DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runGatherSumApplyIteration(new GetReachableVertices(), new FindAllReachableVertices(), new UpdateReachableVertices(), 4, parameters).getVertices();
    List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();
    expectedResult = "1,[1, 3, 4, 5]\n" + "2,[1, 2, 3, 4, 5]\n" + "3,[1, 3, 4, 5]\n" + "4,[1, 3, 4, 5]\n" + "5,[1, 3, 4, 5]\n";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) GSAConfiguration(org.apache.flink.graph.gsa.GSAConfiguration) Edge(org.apache.flink.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with GSAConfiguration

use of org.apache.flink.graph.gsa.GSAConfiguration in project flink by apache.

the class GatherSumApplyConfigurationITCase method testIterationConfiguration.

@Test
public void testIterationConfiguration() throws Exception {
    /*
		 * Test name, parallelism and solutionSetUnmanaged parameters
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    GatherSumApplyIteration<Long, Long, Long, Long> iteration = GatherSumApplyIteration.withEdges(TestGraphUtils.getLongLongEdgeData(env), new DummyGather(), new DummySum(), new DummyApply(), 10);
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.setName("gelly iteration");
    parameters.setParallelism(2);
    parameters.setSolutionSetUnmanagedMemory(true);
    iteration.configure(parameters);
    Assert.assertEquals("gelly iteration", iteration.getIterationConfiguration().getName(""));
    Assert.assertEquals(2, iteration.getIterationConfiguration().getParallelism());
    Assert.assertEquals(true, iteration.getIterationConfiguration().isSolutionSetUnmanagedMemory());
    DataSet<Vertex<Long, Long>> data = TestGraphUtils.getLongLongVertexData(env).runOperation(iteration);
    List<Vertex<Long, Long>> result = data.collect();
    expectedResult = "1,11\n" + "2,12\n" + "3,13\n" + "4,14\n" + "5,15";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) GSAConfiguration(org.apache.flink.graph.gsa.GSAConfiguration) Test(org.junit.Test)

Example 5 with GSAConfiguration

use of org.apache.flink.graph.gsa.GSAConfiguration in project flink by apache.

the class GatherSumApplyConfigurationITCase method testRunWithConfiguration.

@Test
public void testRunWithConfiguration() throws Exception {
    /*
		 * Test Graph's runGatherSumApplyIteration when configuration parameters are provided
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongVertices(), TestGraphUtils.getLongLongEdges(), env).mapVertices(new AssignOneMapper());
    // create the configuration object
    GSAConfiguration parameters = new GSAConfiguration();
    parameters.addBroadcastSetForGatherFunction("gatherBcastSet", env.fromElements(1, 2, 3));
    parameters.addBroadcastSetForSumFunction("sumBcastSet", env.fromElements(4, 5, 6));
    parameters.addBroadcastSetForApplyFunction("applyBcastSet", env.fromElements(7, 8, 9));
    parameters.registerAggregator("superstepAggregator", new LongSumAggregator());
    parameters.setOptNumVertices(true);
    Graph<Long, Long, Long> res = graph.runGatherSumApplyIteration(new Gather(), new Sum(), new Apply(), 10, parameters);
    DataSet<Vertex<Long, Long>> data = res.getVertices();
    List<Vertex<Long, Long>> result = data.collect();
    expectedResult = "1,11\n" + "2,11\n" + "3,11\n" + "4,11\n" + "5,11";
    compareResultAsTuples(result, expectedResult);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) LongSumAggregator(org.apache.flink.api.common.aggregators.LongSumAggregator) GSAConfiguration(org.apache.flink.graph.gsa.GSAConfiguration) Test(org.junit.Test)

Aggregations

GSAConfiguration (org.apache.flink.graph.gsa.GSAConfiguration)5 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)4 Vertex (org.apache.flink.graph.Vertex)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)2 Edge (org.apache.flink.graph.Edge)2 LongSumAggregator (org.apache.flink.api.common.aggregators.LongSumAggregator)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1