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);
}
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);
}
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();
}
}
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();
}
}
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);
}
Aggregations