use of org.apache.flink.graph.Edge in project flink by apache.
the class JoinWithEdgesITCase method testWithLessElements.
@Test
public void testWithLessElements() throws Exception {
/*
* Test joinWithEdges with the input DataSet passed as a parameter containing
* less elements than the edge DataSet, but of the same type
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
Graph<Long, Long, Long> res = graph.joinWithEdges(graph.getEdges().first(3).map(new EdgeToTuple3Map<>()), new AddValuesMapper());
DataSet<Edge<Long, Long>> data = res.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,24\n" + "1,3,26\n" + "2,3,46\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class JoinWithEdgesITCase method testWithEdgesOnSource.
@Test
public void testWithEdgesOnSource() throws Exception {
/*
* Test joinWithEdgesOnSource with the input DataSet parameter identical
* to the edge DataSet
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
Graph<Long, Long, Long> res = graph.joinWithEdgesOnSource(graph.getEdges().map(new ProjectSourceAndValueMapper()), new AddValuesMapper());
DataSet<Edge<Long, Long>> data = res.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,24\n" + "1,3,25\n" + "2,3,46\n" + "3,4,68\n" + "3,5,69\n" + "4,5,90\n" + "5,1,102\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class JoinWithEdgesITCase method testWithCustomType.
@Test
public void testWithCustomType() throws Exception {
/*
* Test joinWithEdges with a DataSet containing custom parametrised type input values
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
Graph<Long, Long, Long> res = graph.joinWithEdges(TestGraphUtils.getLongLongCustomTuple3Data(env), new CustomValueMapper());
DataSet<Edge<Long, Long>> data = res.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,10\n" + "1,3,20\n" + "2,3,30\n" + "3,4,40\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class PageRank method runInternal.
@Override
public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception {
// vertex degree
DataSet<Vertex<K, Degrees>> vertexDegree = input.run(new VertexDegrees<K, VV, EV>().setParallelism(parallelism));
// vertex count
DataSet<LongValue> vertexCount = GraphUtils.count(vertexDegree);
// s, t, d(s)
DataSet<Edge<K, LongValue>> edgeSourceDegree = input.run(new EdgeSourceDegrees<K, VV, EV>().setParallelism(parallelism)).map(new ExtractSourceDegree<K, EV>()).setParallelism(parallelism).name("Extract source degree");
// vertices with zero in-edges
DataSet<Tuple2<K, DoubleValue>> sourceVertices = vertexDegree.flatMap(new InitializeSourceVertices<K>()).withBroadcastSet(vertexCount, VERTEX_COUNT).setParallelism(parallelism).name("Initialize source vertex scores");
// s, initial pagerank(s)
DataSet<Tuple2<K, DoubleValue>> initialScores = vertexDegree.map(new InitializeVertexScores<K>()).withBroadcastSet(vertexCount, VERTEX_COUNT).setParallelism(parallelism).name("Initialize scores");
IterativeDataSet<Tuple2<K, DoubleValue>> iterative = initialScores.iterate(maxIterations);
// s, projected pagerank(s)
DataSet<Tuple2<K, DoubleValue>> vertexScores = iterative.coGroup(edgeSourceDegree).where(0).equalTo(0).with(new SendScore<K>()).setParallelism(parallelism).name("Send score").groupBy(0).reduce(new SumScore<K>()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
// ignored ID, total pagerank
DataSet<Tuple2<K, DoubleValue>> sumOfScores = vertexScores.reduce(new SumVertexScores<K>()).setParallelism(parallelism).name("Sum");
// s, adjusted pagerank(s)
DataSet<Tuple2<K, DoubleValue>> adjustedScores = vertexScores.union(sourceVertices).setParallelism(parallelism).name("Union with source vertices").map(new AdjustScores<K>(dampingFactor)).withBroadcastSet(sumOfScores, SUM_OF_SCORES).withBroadcastSet(vertexCount, VERTEX_COUNT).setParallelism(parallelism).name("Adjust scores");
DataSet<Tuple2<K, DoubleValue>> passThrough;
if (convergenceThreshold < Double.MAX_VALUE) {
passThrough = iterative.join(adjustedScores).where(0).equalTo(0).with(new ChangeInScores<K>()).setParallelism(parallelism).name("Change in scores");
iterative.registerAggregationConvergenceCriterion(CHANGE_IN_SCORES, new DoubleSumAggregator(), new ScoreConvergence(convergenceThreshold));
} else {
passThrough = adjustedScores;
}
return iterative.closeWith(passThrough).map(new TranslateResult<K>()).setParallelism(parallelism).name("Map result");
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class SimplifyTest method setup.
@Before
public void setup() {
ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();
Object[][] edges = new Object[][] { new Object[] { 0, 0 }, new Object[] { 0, 1 }, new Object[] { 0, 1 }, new Object[] { 0, 2 }, new Object[] { 0, 2 }, new Object[] { 1, 0 }, new Object[] { 2, 2 } };
List<Edge<IntValue, NullValue>> edgeList = new LinkedList<>();
for (Object[] edge : edges) {
edgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance()));
}
graph = Graph.fromCollection(edgeList, env);
}
Aggregations