@Override public Edge<K, NullValue> map(Edge<K, NullValue> inEdge) throws Exception { // flip vertices if necessary if (inEdge.getSource().compareTo(inEdge.getTarget()) > 0) { inEdge = inEdge.reverse(); } return inEdge; } }
@Override public void reduce(Iterable<Edge<K, NullValue>> edgesIter, Collector<Triad<K>> out) throws Exception { final Iterator<Edge<K, NullValue>> edges = edgesIter.iterator(); // clear vertex list vertices.clear(); // read first edge Edge<K, NullValue> firstEdge = edges.next(); outTriad.setFirstVertex(firstEdge.getSource()); vertices.add(firstEdge.getTarget()); // build and emit triads while (edges.hasNext()) { K higherVertexId = edges.next().getTarget(); // combine vertex with all previously read vertices for (K lowerVertexId : vertices) { outTriad.setSecondVertex(lowerVertexId); outTriad.setThirdVertex(higherVertexId); out.collect(outTriad); } vertices.add(higherVertexId); } } }
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 Edge<K, EV> join(Edge<K, EV> edge, VertexWithRepresentative<K> vertex) throws Exception { reuseEdge.setSource(vertex.getGroupRepresentativeId()); reuseEdge.setTarget(edge.getTarget()); reuseEdge.setValue(edge.getValue()); return reuseEdge; } }
@Override public void join(Vertex<K, VV> vertex, Edge<K, EV> edge, Collector<Tuple4<K, K, VV, EV>> collector) throws Exception { collector.collect(new Tuple4<>(edge.getSource(), edge.getTarget(), vertex.getValue(), edge.getValue())); } }
public void flatMap(Edge<K, EV> edge, Collector<Tuple2<K, Edge<K, EV>>> out) { out.collect(new Tuple2<>(edge.getSource(), edge)); out.collect(new Tuple2<>(edge.getTarget(), edge)); } }
@Override public void sendMessages(Vertex<K, Double> vertex) { if (vertex.getValue() < Double.POSITIVE_INFINITY) { for (Edge<K, Double> edge : getEdges()) { sendMessageTo(edge.getTarget(), vertex.getValue() + edge.getValue()); } } } }
@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()); } } } }
public void iterateEdges(Vertex<String, NullValue> vertex, Iterable<Edge<String, Integer>> edges, Collector<Tuple2<String, String>> out) throws Exception { int maxPlaycount = 0; String topSong = ""; for (Edge<String, Integer> edge : edges) { if (edge.getValue() > maxPlaycount) { maxPlaycount = edge.getValue(); topSong = edge.getTarget(); } } out.collect(new Tuple2<>(vertex.getId(), topSong)); } }
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 void sendMessages(Vertex<K, Tuple2<Long, Double>> vertex) throws Exception { for (Edge<K, Double> edge : getEdges()) { sendMessageTo(edge.getTarget(), new Tuple2<>(vertex.getValue().f0, vertex.getValue().f1 * edge.getValue())); } } }
@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()); } } }
public void flatMap(Edge<K, EV> edge, Collector<Tuple2<K, EV>> out) { out.collect(new Tuple2<>(edge.getSource(), edge.getValue())); out.collect(new Tuple2<>(edge.getTarget(), edge.getValue())); } }
@Override public void reduce(Iterable<Edge<K, EV>> values, Collector<Edge<K, EdgeValue<EV>>> out) throws Exception { K sourceVertexId = null; K targetVertexId = null; EV edgeGroupValue = null; Long edgeGroupCount = 0L; boolean isFirstElement = true; for (Edge<K, EV> edge : values) { if (isFirstElement) { sourceVertexId = edge.getSource(); targetVertexId = edge.getTarget(); edgeGroupValue = edge.getValue(); isFirstElement = false; } edgeGroupCount++; } reuseEdgeValue.setEdgeGroupValue(edgeGroupValue); reuseEdgeValue.setEdgeGroupCount(edgeGroupCount); reuseEdge.setSource(sourceVertexId); reuseEdge.setTarget(targetVertexId); reuseEdge.setValue(reuseEdgeValue); out.collect(reuseEdge); } }
@Override public Edge<K, NullValue> map(Edge<K, NullValue> inEdge) throws Exception { // flip vertices if necessary if (inEdge.getSource().compareTo(inEdge.getTarget()) > 0) { inEdge = inEdge.reverse(); } return inEdge; } }
@Override public void join(Vertex<K, VV> vertex, Edge<K, EV> edge, Collector<Tuple4<K, K, VV, EV>> collector) throws Exception { collector.collect(new Tuple4<>(edge.getSource(), edge.getTarget(), vertex.getValue(), edge.getValue())); } }
public void flatMap(Edge<K, EV> edge, Collector<Tuple2<K, Edge<K, EV>>> out) { out.collect(new Tuple2<>(edge.getSource(), edge)); out.collect(new Tuple2<>(edge.getTarget(), edge)); } }
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()))); } }