@Override public void updateVertex(Vertex<K, Double> vertex, MessageIterator<Double> inMessages) { double rankSum = 0.0; for (double msg : inMessages) { rankSum += msg; } // apply the dampening factor / random jump double newRank = (beta * rankSum) + (1 - beta) / this.getNumberOfVertices(); setNewVertexValue(newRank); } }
public void apply(Double newDistance, Double oldDistance) { if (newDistance < oldDistance) { setResult(newDistance); } } }
@Override public void apply(Double rankSum, Double currentValue) { setResult((1 - beta) / this.getNumberOfVertices() + beta * rankSum); } }
public static void main(String [] args) throws Exception { if (!parseParameters(args)) { return; Edge<Long, Double> edgeToBeRemoved = getEdgeToBeRemoved(); Graph<Long, Double, Double> graph = IncrementalSSSP.getGraph(env); Graph<Long, Double, Double> ssspGraph = IncrementalSSSP.getSSSPGraph(env); if (isInSSSP(edgeToBeRemoved, ssspGraph.getEdges())) { Graph<Long, Double, Double> result = ssspGraph.runScatterGatherIteration(new InvalidateMessenger(edgeToBeRemoved), new VertexDistanceUpdater(), maxIterations, parameters);
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(); } }
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(); } }
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(); } }
@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(); }
@Override public void sendMessages(Vertex<K, Double> vertex) { if (getSuperstepNumber() == 1) { // initialize vertex ranks vertex.setValue(1.0 / this.getNumberOfVertices()); } for (Edge<K, Double> edge : getEdges()) { sendMessageTo(edge.getTarget(), vertex.getValue() * edge.getValue()); } } }
@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 void sendMessages(Vertex<Long, Double> vertex) throws Exception { if (getSuperstepNumber() == 1) { if (vertex.getId().equals(edgeToBeRemoved.getSource())) { // activate the edge target sendMessageTo(edgeToBeRemoved.getSource(), Double.MAX_VALUE); } } if (getSuperstepNumber() > 1) { // invalidate all edges for (Edge<Long, Double> edge : getEdges()) { sendMessageTo(edge.getSource(), Double.MAX_VALUE); } } } }
public void compute(Vertex<Long, Double> vertex, MessageIterator<Double> messages) { double minDistance = (vertex.getId().equals(srcId)) ? 0d : Double.POSITIVE_INFINITY; for (Double msg : messages) { minDistance = Math.min(minDistance, msg); } if (minDistance < vertex.getValue()) { setNewVertexValue(minDistance); for (Edge<Long, Double> e: getEdges()) { sendMessageTo(e.getTarget(), minDistance + e.getValue()); } } } }
@Override public void updateVertex(Vertex<Long, Double> vertex, MessageIterator<Double> inMessages) throws Exception { if (inMessages.hasNext()) { Long outDegree = getOutDegree() - 1; // check if the vertex has another SP-Edge if (outDegree <= 0) { // set own value to infinity setNewVertexValue(Double.MAX_VALUE); } } } }
@Override public Double gather(Neighbor<Double, Double> neighbor) { double neighborRank = neighbor.getNeighborValue(); if (getSuperstepNumber() == 1) { neighborRank = 1.0 / this.getNumberOfVertices(); } return neighborRank * neighbor.getEdgeValue(); } }
@Override public void sendMessages(Vertex<Long, Double> vertex) { if (vertex.getValue() < Double.POSITIVE_INFINITY) { for (Edge<Long, Double> edge : getEdges()) { sendMessageTo(edge.getTarget(), vertex.getValue() + edge.getValue()); } } } }
@Override public Vertex<Long, Point> map(Tuple3<Long, Double, Double> value) throws Exception { return new Vertex<>(value.f0, new Point(value.f1, value.f2)); } });
public void combineMessages(MessageIterator<Double> messages) { double minMessage = Double.POSITIVE_INFINITY; for (Double msg: messages) { minMessage = Math.min(minMessage, msg); } sendCombinedMessage(minMessage); } }
@Override public void updateVertex(Vertex<Long, Double> vertex, MessageIterator<Double> inMessages) { Double minDistance = Double.MAX_VALUE; for (double msg : inMessages) { if (msg < minDistance) { minDistance = msg; } } if (vertex.getValue() > minDistance) { setNewVertexValue(minDistance); } } }
@Override public Tuple3<Long, Long, Double> map(Triplet<Long, Point, Double> triplet) throws Exception { Vertex<Long, Point> srcVertex = triplet.getSrcVertex(); Vertex<Long, Point> trgVertex = triplet.getTrgVertex(); return new Tuple3<>(srcVertex.getId(), trgVertex.getId(), srcVertex.getValue().euclideanDistance(trgVertex.getValue())); } });
public static DataSet<Vertex<Long, EuclideanGraphWeighing.Point>> getDefaultVertexDataSet(ExecutionEnvironment env) { List<Vertex<Long, EuclideanGraphWeighing.Point>> vertices = new ArrayList<>(); for (int i = 1; i <= NUM_VERTICES; i++) { vertices.add(new Vertex<>(new Long(i), new EuclideanGraphWeighing.Point(new Double(i), new Double(i)))); } return env.fromCollection(vertices); }