/** * Runs a ScatterGather iteration on the graph. * No configuration options are provided. * * @param scatterFunction the scatter function * @param gatherFunction the gather function * @param maximumNumberOfIterations maximum number of iterations to perform * * @return the updated Graph after the scatter-gather iteration has converged or * after maximumNumberOfIterations. */ public <M> Graph<K, VV, EV> runScatterGatherIteration( ScatterFunction<K, VV, M, EV> scatterFunction, org.apache.flink.graph.spargel.GatherFunction<K, VV, M> gatherFunction, int maximumNumberOfIterations) { return this.runScatterGatherIteration(scatterFunction, gatherFunction, maximumNumberOfIterations, null); }
@Override public DataSet<Vertex<K, Double>> run(Graph<K, VV, Double> input) { return input.mapVertices(new InitVerticesMapper<>(srcVertexId)) .runScatterGatherIteration(new MinDistanceMessenger<>(), new VertexDistanceUpdater<>(), maxIterations).getVertices(); }
@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<>(), new VertexRankUpdater<>(beta), maxIterations, parameters) .getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> input) { TypeInformation<VV> valueType = ((TupleTypeInfo<?>) input.getVertices().getType()).getTypeAt(1); // iteratively adopt the most frequent label among the neighbors of each vertex return input .mapEdges(new MapTo<>(NullValue.getInstance())) .runScatterGatherIteration( new SendNewLabelToNeighbors<>(valueType), new UpdateVertexLabel<>(), maxIterations) .getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception { // get type information for vertex value TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1); Graph<K, VV, NullValue> undirectedGraph = graph .mapEdges(new MapTo<>(NullValue.getInstance())) .getUndirected(); return undirectedGraph.runScatterGatherIteration( new CCMessenger<>(valueTypeInfo), new CCUpdater<>(), maxIterations).getVertices(); }
@Override public Graph<K, Long, Double> run(Graph<K, Long, Double> graph) { DataSet<Vertex<K, Tuple2<Long, Double>>> initializedVertices = graph.getVertices() .map(new AddScoreToVertexValuesMapper<>()); Graph<K, Tuple2<Long, Double>, Double> graphWithScoredVertices = Graph.fromDataSet(initializedVertices, graph.getEdges(), graph.getContext()).getUndirected(); return graphWithScoredVertices.runScatterGatherIteration(new LabelMessenger<>(), new VertexLabelUpdater<>(delta), maxIterations) .mapVertices(new RemoveScoreFromVertexValuesMapper<>()); }
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(srcVertexId), env); // Execute the scatter-gather iteration Graph<Long, Double, Double> result = graph.runScatterGatherIteration( new MinDistanceMessenger(), new VertexDistanceUpdater(), 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("Single Source Shortest Paths Example"); } else { singleSourceShortestPaths.print(); } }
Graph<Long, Double, Double> result = ssspGraph.runScatterGatherIteration(new InvalidateMessenger(edgeToBeRemoved), new VertexDistanceUpdater(), maxIterations, parameters);
@Override public DataSet<Vertex<K, Double>> run(Graph<K, VV, Double> input) { return input.mapVertices(new InitVerticesMapper<>(srcVertexId)) .runScatterGatherIteration(new MinDistanceMessenger<>(), new VertexDistanceUpdater<>(), maxIterations).getVertices(); }
@Override public DataSet<Vertex<K, Double>> run(Graph<K, VV, Double> input) { return input.mapVertices(new InitVerticesMapper<>(srcVertexId)) .runScatterGatherIteration(new MinDistanceMessenger<>(), new VertexDistanceUpdater<>(), maxIterations).getVertices(); }
@Override public DataSet<Vertex<K, Double>> run(Graph<K, VV, Double> input) { return input.mapVertices(new InitVerticesMapper<K, VV>(srcVertexId)) .runScatterGatherIteration(new MinDistanceMessenger<K>(), new VertexDistanceUpdater<K>(), maxIterations).getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> input) { TypeInformation<VV> valueType = ((TupleTypeInfo<?>) input.getVertices().getType()).getTypeAt(1); // iteratively adopt the most frequent label among the neighbors of each vertex return input .mapEdges(new MapTo<>(NullValue.getInstance())) .runScatterGatherIteration( new SendNewLabelToNeighbors<>(valueType), new UpdateVertexLabel<>(), maxIterations) .getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> input) { TypeInformation<VV> valueType = ((TupleTypeInfo<?>) input.getVertices().getType()).getTypeAt(1); // iteratively adopt the most frequent label among the neighbors of each vertex return input .mapEdges(new MapTo<>(NullValue.getInstance())) .runScatterGatherIteration( new SendNewLabelToNeighbors<>(valueType), new UpdateVertexLabel<>(), maxIterations) .getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> input) { TypeInformation<VV> valueType = ((TupleTypeInfo<?>) input.getVertices().getType()).getTypeAt(1); // iteratively adopt the most frequent label among the neighbors of each vertex return input .mapEdges(new MapTo<Edge<K, EV>, NullValue>(NullValue.getInstance())) .runScatterGatherIteration( new SendNewLabelToNeighbors<K, VV>(valueType), new UpdateVertexLabel<K, VV>(), maxIterations) .getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception { // get type information for vertex value TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1); Graph<K, VV, NullValue> undirectedGraph = graph .mapEdges(new MapTo<>(NullValue.getInstance())) .getUndirected(); return undirectedGraph.runScatterGatherIteration( new CCMessenger<>(valueTypeInfo), new CCUpdater<>(), maxIterations).getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception { // get type information for vertex value TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1); Graph<K, VV, NullValue> undirectedGraph = graph .mapEdges(new MapTo<>(NullValue.getInstance())) .getUndirected(); return undirectedGraph.runScatterGatherIteration( new CCMessenger<>(valueTypeInfo), new CCUpdater<>(), maxIterations).getVertices(); }
@Override public DataSet<Vertex<K, VV>> run(Graph<K, VV, EV> graph) throws Exception { // get type information for vertex value TypeInformation<VV> valueTypeInfo = ((TupleTypeInfo<?>) graph.getVertices().getType()).getTypeAt(1); Graph<K, VV, NullValue> undirectedGraph = graph .mapEdges(new MapTo<Edge<K, EV>, NullValue>(NullValue.getInstance())) .getUndirected(); return undirectedGraph.runScatterGatherIteration( new CCMessenger<K, VV>(valueTypeInfo), new CCUpdater<K, VV>(), maxIterations).getVertices(); }
@Override public Graph<K, Long, Double> run(Graph<K, Long, Double> graph) { DataSet<Vertex<K, Tuple2<Long, Double>>> initializedVertices = graph.getVertices() .map(new AddScoreToVertexValuesMapper<>()); Graph<K, Tuple2<Long, Double>, Double> graphWithScoredVertices = Graph.fromDataSet(initializedVertices, graph.getEdges(), graph.getContext()).getUndirected(); return graphWithScoredVertices.runScatterGatherIteration(new LabelMessenger<>(), new VertexLabelUpdater<>(delta), maxIterations) .mapVertices(new RemoveScoreFromVertexValuesMapper<>()); }
@Override public Graph<K, Long, Double> run(Graph<K, Long, Double> graph) { DataSet<Vertex<K, Tuple2<Long, Double>>> initializedVertices = graph.getVertices() .map(new AddScoreToVertexValuesMapper<K>()); Graph<K, Tuple2<Long, Double>, Double> graphWithScoredVertices = Graph.fromDataSet(initializedVertices, graph.getEdges(), graph.getContext()).getUndirected(); return graphWithScoredVertices.runScatterGatherIteration(new LabelMessenger<K>(), new VertexLabelUpdater<K>(delta), maxIterations) .mapVertices(new RemoveScoreFromVertexValuesMapper<K>()); }
@Override public Graph<K, Long, Double> run(Graph<K, Long, Double> graph) { DataSet<Vertex<K, Tuple2<Long, Double>>> initializedVertices = graph.getVertices() .map(new AddScoreToVertexValuesMapper<>()); Graph<K, Tuple2<Long, Double>, Double> graphWithScoredVertices = Graph.fromDataSet(initializedVertices, graph.getEdges(), graph.getContext()).getUndirected(); return graphWithScoredVertices.runScatterGatherIteration(new LabelMessenger<>(), new VertexLabelUpdater<>(delta), maxIterations) .mapVertices(new RemoveScoreFromVertexValuesMapper<>()); }