public Double gather(Neighbor<Double, Double> neighbor) { return neighbor.getNeighborValue() + neighbor.getEdgeValue(); } }
@Override public void close() throws Exception { this.gatherFunction.postSuperstep(); }
@Override public void close() throws Exception { this.sumFunction.postSuperstep(); }
if (this.configuration != null && this.configuration.isOptNumVertices()) { try { numberOfVertices = GraphUtils.count(this.vertexDataSet); GatherUdf<K, VV, EV, M> gatherUdf = new GatherUdf<>(gather, innerType); SumUdf<K, VV, EV, M> sumUdf = new SumUdf<>(sum, innerType); ApplyUdf<K, VV, EV, M> applyUdf = new ApplyUdf<>(apply, outputType); iteration.name(this.configuration.getName( "Gather-sum-apply iteration (" + gather + " | " + sum + " | " + apply + ")")); iteration.parallelism(this.configuration.getParallelism()); iteration.setSolutionSetUnManaged(this.configuration.isSolutionSetUnmanagedMemory()); for (Map.Entry<String, Aggregator<?>> entry : this.configuration.getAggregators().entrySet()) { iteration.registerAggregator(entry.getKey(), entry.getValue()); direction = this.configuration.getDirection(); neighbors = iteration .getWorkset().join(edgeDataSet) .where(0).equalTo(0).with(new ProjectKeyWithNeighborOUT<>()); break; case IN: neighbors = iteration .getWorkset().join(edgeDataSet) .where(0).equalTo(1).with(new ProjectKeyWithNeighborIN<>()); break; case ALL: neighbors = iteration
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.gatherFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.gatherFunction.init(getIterationRuntimeContext()); } this.gatherFunction.preSuperstep(); }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.applyFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.applyFunction.init(getIterationRuntimeContext()); } this.applyFunction.preSuperstep(); }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.sumFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.sumFunction.init(getIterationRuntimeContext()); } this.sumFunction.preSuperstep(); }
/** * Runs a Gather-Sum-Apply iteration on the graph with configuration options. * * @param gatherFunction the gather function collects information about adjacent vertices and edges * @param sumFunction the sum function aggregates the gathered information * @param applyFunction the apply function updates the vertex values with the aggregates * @param maximumNumberOfIterations maximum number of iterations to perform * @param parameters the iteration configuration parameters * @param <M> the intermediate type used between gather, sum and apply * * @return the updated Graph after the gather-sum-apply iteration has converged or * after maximumNumberOfIterations. */ public <M> Graph<K, VV, EV> runGatherSumApplyIteration( org.apache.flink.graph.gsa.GatherFunction<VV, EV, M> gatherFunction, SumFunction<VV, EV, M> sumFunction, ApplyFunction<K, VV, M> applyFunction, int maximumNumberOfIterations, GSAConfiguration parameters) { GatherSumApplyIteration<K, VV, EV, M> iteration = GatherSumApplyIteration.withEdges( edges, gatherFunction, sumFunction, applyFunction, maximumNumberOfIterations); iteration.configure(parameters); DataSet<Vertex<K, VV>> newVertices = vertices.runOperation(iteration); return new Graph<>(newVertices, this.edges, this.context); }
public VV gather(Neighbor<VV, NullValue> neighbor) { return neighbor.getNeighborValue(); }
@Override public void close() throws Exception { this.applyFunction.postSuperstep(); }
public void join(Vertex<K, VV> vertex, Edge<K, EV> edge, Collector<Tuple2<K, Neighbor<VV, EV>>> out) { out.collect(new Tuple2<>( edge.getTarget(), new Neighbor<>(vertex.getValue(), edge.getValue()))); } }
@Override public Tuple2<K, M> reduce(Tuple2<K, M> arg0, Tuple2<K, M> arg1) throws Exception { M result = this.sumFunction.sum(arg0.f1, arg1.f1); // if the user returns value from the right argument then swap as // in ReduceDriver.run() if (result == arg1.f1) { M tmp = arg1.f1; arg1.f1 = arg0.f1; arg0.f1 = tmp; } else { arg0.f1 = result; } return arg0; }
/** * Creates a new gather-sum-apply iteration operator for graphs. * * @param edges The edge DataSet * * @param gather The gather function of the GSA iteration * @param sum The sum function of the GSA iteration * @param apply The apply function of the GSA iteration * * @param maximumNumberOfIterations The maximum number of iterations executed * * @param <K> The type of the vertex key in the graph * @param <VV> The type of the vertex value in the graph * @param <EV> The type of the edge value in the graph * @param <M> The intermediate type used by the gather, sum and apply functions * * @return An in stance of the gather-sum-apply graph computation operator. */ public static <K, VV, EV, M> GatherSumApplyIteration<K, VV, EV, M> withEdges(DataSet<Edge<K, EV>> edges, GatherFunction<VV, EV, M> gather, SumFunction<VV, EV, M> sum, ApplyFunction<K, VV, M> apply, int maximumNumberOfIterations) { return new GatherSumApplyIteration<>(gather, sum, apply, edges, maximumNumberOfIterations); }
@Override public Tuple2<K, M> map(Tuple2<K, Neighbor<VV, EV>> neighborTuple) { M result = this.gatherFunction.gather(neighborTuple.f1); return new Tuple2<>(neighborTuple.f0, result); }
@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<>(beta), maxIterations, parameters) .getVertices(); }
public Double gather(Neighbor<Double, Double> neighbor) { return neighbor.getNeighborValue() + neighbor.getEdgeValue(); } }
@Override public void close() throws Exception { this.applyFunction.postSuperstep(); }
public void join(Vertex<K, VV> vertex, Edge<K, EV> edge, Collector<Tuple2<K, Neighbor<VV, EV>>> out) { out.collect(new Tuple2<>( edge.getSource(), new Neighbor<>(vertex.getValue(), edge.getValue()))); } }
@Override public Double gather(Neighbor<Double, Double> neighbor) { double neighborRank = neighbor.getNeighborValue(); if (getSuperstepNumber() == 1) { neighborRank = 1.0 / this.getNumberOfVertices(); } return neighborRank * neighbor.getEdgeValue(); } }