@Override public VertexWithRepresentative<K> map(VertexGroupItem<K, VV> vertexGroupItem) throws Exception { reuseVertexWithRepresentative.setVertexId(vertexGroupItem.getVertexId()); reuseVertexWithRepresentative.setGroupRepresentativeId(vertexGroupItem.getGroupRepresentativeId()); return reuseVertexWithRepresentative; } }
public void apply(Double newDistance, Double oldDistance) { if (newDistance < oldDistance) { setResult(newDistance); } } }
public void copyFrom(final EdgeWithDegrees<K> edge) { this.setFirstVertex(edge.getFirstVertex()); this.setSecondVertex(edge.getSecondVertex()); this.setFirstDegree(edge.getFirstDegree()); this.setSecondDegree(edge.getSecondDegree()); } }
@Override public EdgeWithDegrees<K> reduce(EdgeWithDegrees<K> edge1, EdgeWithDegrees<K> edge2) throws Exception { // copy first edge outEdge.copyFrom(edge1); // set missing degree if (edge1.getFirstDegree() == 0 && edge1.getSecondDegree() != 0) { outEdge.setFirstDegree(edge2.getFirstDegree()); } else if (edge1.getFirstDegree() != 0 && edge1.getSecondDegree() == 0) { outEdge.setSecondDegree(edge2.getSecondDegree()); } return outEdge; } }
@Override public Vertex<K, VertexValue<VV>> map(VertexGroupItem<K, VV> value) throws Exception { K vertexId = value.getVertexId(); reuseSummarizedVertexValue.setVertexGroupValue(value.getVertexGroupValue()); reuseSummarizedVertexValue.setVertexGroupCount(value.getVertexGroupCount()); return new Vertex<>(vertexId, reuseSummarizedVertexValue); } }
@Override public DataSet<Vertex<K, Double>> run(Graph<K, VV, Double> input) { return input.mapVertices(new InitVerticesMapper<>(srcVertexId)) .runGatherSumApplyIteration(new CalculateDistances(), new ChooseMinDistance(), new UpdateDistance<>(), 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<>()); }
/** * Creates one tuple representing the whole group. This tuple is later used to create a summarized vertex for each * group. * * @param vertexGroupRepresentativeId group representative vertex identifier * @param vertexGroupValue group property value * @param vertexGroupCount total group count */ private void createGroupRepresentativeTuple(K vertexGroupRepresentativeId, VV vertexGroupValue, Long vertexGroupCount) { reuseVertexGroupItem.setVertexId(vertexGroupRepresentativeId); reuseVertexGroupItem.setVertexGroupValue(vertexGroupValue); reuseVertexGroupItem.setVertexGroupCount(vertexGroupCount); } }
@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(); }
public void setFirstDegree(final Integer degree1) { this.setField(degree1, D1); }
public void setSecondVertex(final K vertex2) { this.setField(vertex2, V2); }
public K getFirstVertex() { return this.getField(V1); }
public K getThirdVertex() { return this.getField(V3); }
public VertexGroupItem() { reset(); }
private VertexGroupItemToSummarizedVertexMapper() { reuseSummarizedVertexValue = new VertexValue<>(); }
public void setSecondDegree(final Integer degree2) { this.setField(degree2, D2); }
public void setFirstVertex(final K vertex1) { this.setField(vertex1, V1); }
public K getSecondVertex() { return this.getField(V2); }
public void setSecondVertex(final K vertex2) { this.setField(vertex2, V2); }
public void setThirdVertex(final K vertex3) { this.setField(vertex3, V3); } }