Search in sources :

Example 11 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class EdgeTargetDegreeTest method testWithRMatGraph.

@Test
public void testWithRMatGraph() throws Exception {
    DataSet<Edge<LongValue, Tuple2<NullValue, LongValue>>> targetDegreeOnTargetId = undirectedRMatGraph(10, 16).run(new EdgeTargetDegree<LongValue, NullValue, NullValue>().setReduceOnSourceId(false));
    Checksum checksumOnTargetId = new ChecksumHashCode<Edge<LongValue, Tuple2<NullValue, LongValue>>>().run(targetDegreeOnTargetId).execute();
    assertEquals(20884, checksumOnTargetId.getCount());
    assertEquals(0x000000019d8f0070L, checksumOnTargetId.getChecksum());
    DataSet<Edge<LongValue, Tuple2<NullValue, LongValue>>> targetDegreeOnSourceId = undirectedRMatGraph(10, 16).run(new EdgeTargetDegree<LongValue, NullValue, NullValue>().setReduceOnSourceId(true));
    Checksum checksumOnSourceId = new ChecksumHashCode<Edge<LongValue, Tuple2<NullValue, LongValue>>>().run(targetDegreeOnSourceId).execute();
    assertEquals(checksumOnTargetId, checksumOnSourceId);
}
Also used : NullValue(org.apache.flink.types.NullValue) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 12 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class SummarizationITCase method testWithVertexAndEdgeStringValues.

@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    Graph<Long, String, String> input = Graph.fromDataSet(SummarizationData.getVertices(env), SummarizationData.getEdges(env), env);
    List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
    List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();
    Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output = input.run(new Summarization<>());
    output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
    output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));
    env.execute();
    validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
    validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ArrayList(java.util.ArrayList) EdgeValue(org.apache.flink.graph.library.Summarization.EdgeValue) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Example 13 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GSASingleSourceShortestPaths method main.

// --------------------------------------------------------------------------------------------
// Program
// --------------------------------------------------------------------------------------------
public static void main(String[] args) throws Exception {
    if (!parseParameters(args)) {
        return;
    }
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Edge<Long, Double>> edges = getEdgeDataSet(env);
    Graph<Long, Double, Double> graph = Graph.fromDataSet(edges, new InitVertices(srcVertexId), env);
    // Execute the GSA iteration
    Graph<Long, Double, Double> result = graph.runGatherSumApplyIteration(new CalculateDistances(), new ChooseMinDistance(), new UpdateDistance(), maxIterations);
    // Extract the vertices as the result
    DataSet<Vertex<Long, Double>> singleSourceShortestPaths = result.getVertices();
    // emit result
    if (fileOutput) {
        singleSourceShortestPaths.writeAsCsv(outputPath, "\n", ",");
        // since file sinks are lazy, we trigger the execution explicitly
        env.execute("GSA Single Source Shortest Paths");
    } else {
        singleSourceShortestPaths.print();
    }
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge)

Example 14 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class PregelSSSP method main.

public static void main(String[] args) throws Exception {
    if (!parseParameters(args)) {
        return;
    }
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Edge<Long, Double>> edges = getEdgesDataSet(env);
    Graph<Long, Double, Double> graph = Graph.fromDataSet(edges, new InitVertices(), env);
    // Execute the vertex-centric iteration
    Graph<Long, Double, Double> result = graph.runVertexCentricIteration(new SSSPComputeFunction(srcVertexId), new SSSPCombiner(), maxIterations);
    // Extract the vertices as the result
    DataSet<Vertex<Long, Double>> singleSourceShortestPaths = result.getVertices();
    // emit result
    if (fileOutput) {
        singleSourceShortestPaths.writeAsCsv(outputPath, "\n", ",");
        env.execute("Pregel Single Source Shortest Paths Example");
    } else {
        singleSourceShortestPaths.print();
    }
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Edge(org.apache.flink.graph.Edge)

Example 15 with Edge

use of org.apache.flink.graph.Edge in project flink by apache.

the class GatherSumApplyITCase method testConnectedComponentsWithObjectReuseEnabled.

@Test
public void testConnectedComponentsWithObjectReuseEnabled() throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().enableObjectReuse();
    DataSet<Edge<LongValue, NullValue>> edges = Translate.translateEdgeIds(ConnectedComponentsDefaultData.getDefaultEdgeDataSet(env), new LongToLongValue());
    Graph<LongValue, LongValue, NullValue> inputGraph = Graph.fromDataSet(edges, new IdentityMapper<>(), env);
    List<Vertex<LongValue, LongValue>> result = inputGraph.run(new GSAConnectedComponents<>(16)).collect();
    compareResultAsTuples(result, expectedResultCC);
}
Also used : Vertex(org.apache.flink.graph.Vertex) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) NullValue(org.apache.flink.types.NullValue) LongToLongValue(org.apache.flink.graph.asm.translate.translators.LongToLongValue) LongValue(org.apache.flink.types.LongValue) LongToLongValue(org.apache.flink.graph.asm.translate.translators.LongToLongValue) GSAConnectedComponents(org.apache.flink.graph.library.GSAConnectedComponents) Edge(org.apache.flink.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.apache.flink.graph.Edge)87 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)72 Test (org.junit.Test)69 Vertex (org.apache.flink.graph.Vertex)46 NullValue (org.apache.flink.types.NullValue)20 LongValue (org.apache.flink.types.LongValue)16 ArrayList (java.util.ArrayList)14 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)12 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)7 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)7 Plan (org.apache.flink.api.common.Plan)6 FieldList (org.apache.flink.api.common.operators.util.FieldList)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)6 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)6 PlanNode (org.apache.flink.optimizer.plan.PlanNode)6 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)6 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)6 LinkedList (java.util.LinkedList)5 LongValueSequenceIterator (org.apache.flink.util.LongValueSequenceIterator)5