Java Code Examples for org.apache.flink.graph.Vertex#getValue()

The following examples show how to use org.apache.flink.graph.Vertex#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Summarization.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Vertex<K, VV>> values, Collector<VertexGroupItem<K, VV>> out) throws Exception {
	K vertexGroupRepresentativeID = null;
	long vertexGroupCount = 0L;
	VV vertexGroupValue = null;
	boolean isFirstElement = true;

	for (Vertex<K, VV> vertex : values) {
		if (isFirstElement) {
			// take final group representative vertex id from first tuple
			vertexGroupRepresentativeID = vertex.getId();
			vertexGroupValue = vertex.getValue();
			isFirstElement = false;
		}
		// no need to set group value for those tuples
		reuseVertexGroupItem.setVertexId(vertex.getId());
		reuseVertexGroupItem.setGroupRepresentativeId(vertexGroupRepresentativeID);
		out.collect(reuseVertexGroupItem);
		vertexGroupCount++;
	}

	createGroupRepresentativeTuple(vertexGroupRepresentativeID, vertexGroupValue, vertexGroupCount);
	out.collect(reuseVertexGroupItem);
	reuseVertexGroupItem.reset();
}
 
Example 2
Source File: SingleSourceShortestPaths.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void updateVertex(Vertex<K, 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);
	}
}
 
Example 3
Source File: Summarization.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Vertex<K, VV>> values, Collector<VertexGroupItem<K, VV>> out) throws Exception {
	K vertexGroupRepresentativeID = null;
	long vertexGroupCount = 0L;
	VV vertexGroupValue = null;
	boolean isFirstElement = true;

	for (Vertex<K, VV> vertex : values) {
		if (isFirstElement) {
			// take final group representative vertex id from first tuple
			vertexGroupRepresentativeID = vertex.getId();
			vertexGroupValue = vertex.getValue();
			isFirstElement = false;
		}
		// no need to set group value for those tuples
		reuseVertexGroupItem.setVertexId(vertex.getId());
		reuseVertexGroupItem.setGroupRepresentativeId(vertexGroupRepresentativeID);
		out.collect(reuseVertexGroupItem);
		vertexGroupCount++;
	}

	createGroupRepresentativeTuple(vertexGroupRepresentativeID, vertexGroupValue, vertexGroupCount);
	out.collect(reuseVertexGroupItem);
	reuseVertexGroupItem.reset();
}
 
Example 4
Source File: LabelPropagation.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public void updateVertex(Vertex<K, VV> vertex, MessageIterator<VV> inMessages) {
	Map<VV, Long> labelsWithFrequencies = new HashMap<>();

	long maxFrequency = 1;
	VV mostFrequentLabel = vertex.getValue();

	// store the labels with their frequencies
	for (VV msg : inMessages) {
		if (labelsWithFrequencies.containsKey(msg)) {
			long currentFreq = labelsWithFrequencies.get(msg);
			labelsWithFrequencies.put(msg, currentFreq + 1);
		} else {
			labelsWithFrequencies.put(msg, 1L);
		}
	}
	// select the most frequent label: if two or more labels have the
	// same frequency, the node adopts the label with the highest value
	for (Entry<VV, Long> entry : labelsWithFrequencies.entrySet()) {
		if (entry.getValue() == maxFrequency) {
			// check the label value to break ties
			if (entry.getKey().compareTo(mostFrequentLabel) > 0) {
				mostFrequentLabel = entry.getKey();
			}
		} else if (entry.getValue() > maxFrequency) {
			maxFrequency = entry.getValue();
			mostFrequentLabel = entry.getKey();
		}
	}
	setNewVertexValue(mostFrequentLabel);
}
 
Example 5
Source File: ReduceOnEdgesMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateEdges(Vertex<Long, Long> v, Iterable<Edge<Long, Long>> edges,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	for (Edge<Long, Long> edge : edges) {
		if (v.getValue() > 4) {
			if (v.getId().equals(edge.getTarget())) {
				out.collect(new Tuple2<>(v.getId(), edge.getSource()));
			} else {
				out.collect(new Tuple2<>(v.getId(), edge.getTarget()));
			}
		}
	}
}
 
Example 6
Source File: ReduceOnEdgesMethodsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateEdges(Vertex<Long, Long> v, Iterable<Edge<Long, Long>> edges,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	for (Edge<Long, Long> edge : edges) {
		if (v.getValue() > 4) {
			if (v.getId().equals(edge.getTarget())) {
				out.collect(new Tuple2<>(v.getId(), edge.getSource()));
			} else {
				out.collect(new Tuple2<>(v.getId(), edge.getTarget()));
			}
		}
	}
}
 
Example 7
Source File: ReduceOnEdgesMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateEdges(Vertex<Long, Long> v, Iterable<Edge<Long, Long>> edges,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	for (Edge<Long, Long> edge : edges) {
		if (v.getValue() > 2) {
			out.collect(new Tuple2<>(v.getId(), edge.getTarget()));
		}
	}
}
 
Example 8
Source File: ReduceOnEdgesWithExceptionITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateEdges(Vertex<Long, Long> v, Iterable<Edge<Long, Long>> edges,
		Collector<Tuple2<Long, Long>> out) throws Exception {
	for (Edge<Long, Long> edge : edges) {
		if (v.getValue() > 4) {
			if (v.getId().equals(edge.getTarget())) {
				out.collect(new Tuple2<>(v.getId(), edge.getSource()));
			} else {
				out.collect(new Tuple2<>(v.getId(), edge.getTarget()));
			}
		}
	}
}
 
Example 9
Source File: ConnectedComponents.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void updateVertex(Vertex<K, VV> vertex, MessageIterator<VV> messages) throws Exception {
	VV current = vertex.getValue();
	VV min = current;

	for (VV msg : messages) {
		if (msg.compareTo(min) < 0) {
			min = msg;
		}
	}

	if (!min.equals(current)) {
		setNewVertexValue(min);
	}
}
 
Example 10
Source File: SingleSourceShortestPaths.java    From flink with Apache License 2.0 5 votes vote down vote up
@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());
		}
	}
}
 
Example 11
Source File: SingleSourceShortestPaths.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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());
		}
	}
}
 
Example 12
Source File: ReduceOnEdgesMethodsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateEdges(Vertex<Long, Long> v, Iterable<Edge<Long, Long>> edges,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	for (Edge<Long, Long> edge : edges) {
		if (v.getValue() > 4) {
			if (v.getId().equals(edge.getTarget())) {
				out.collect(new Tuple2<>(v.getId(), edge.getSource()));
			} else {
				out.collect(new Tuple2<>(v.getId(), edge.getTarget()));
			}
		}
	}
}
 
Example 13
Source File: SingleSourceShortestPaths.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 14
Source File: PregelCompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void compute(Vertex<Long, Long> vertex, MessageIterator<Long> messages) throws Exception {
	long currentComponent = vertex.getValue();

	for (Long msg : messages) {
		currentComponent = Math.min(currentComponent, msg);
	}

	if ((getSuperstepNumber() == 1) || (currentComponent < vertex.getValue())) {
		setNewVertexValue(currentComponent);
		for (Edge<Long, NullValue> edge : getEdges()) {
			sendMessageTo(edge.getTarget(), currentComponent);
		}
	}
}
 
Example 15
Source File: Projection.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public Projection(
		Vertex<KC, VVC> connectingVertex,
		VV sourceVertexValue, VV targetVertexValue,
		EV sourceEdgeValue, EV targetEdgeValue) {
	this.f0 = connectingVertex.getId();
	this.f1 = connectingVertex.getValue();
	this.f2 = sourceVertexValue;
	this.f3 = targetVertexValue;
	this.f4 = sourceEdgeValue;
	this.f5 = targetEdgeValue;
}
 
Example 16
Source File: ReduceOnEdgesWithExceptionITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void iterateEdges(Vertex<Long, Long> v, Iterable<Edge<Long, Long>> edges,
		Collector<Tuple2<Long, Long>> out) throws Exception {
	for (Edge<Long, Long> edge : edges) {
		if (v.getValue() > 4) {
			if (v.getId().equals(edge.getTarget())) {
				out.collect(new Tuple2<>(v.getId(), edge.getSource()));
			} else {
				out.collect(new Tuple2<>(v.getId(), edge.getTarget()));
			}
		}
	}
}
 
Example 17
Source File: CommunityDetection.java    From flink with Apache License 2.0 4 votes vote down vote up
public Vertex<K, Tuple2<Long, Double>> map(Vertex<K, Long> vertex) {
	return new Vertex<>(vertex.getId(), new Tuple2<>(vertex.getValue(), 1.0));
}
 
Example 18
Source File: MapVerticesITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Long map(Vertex<Long, Long> value) throws Exception {
	return value.getValue() + 1;
}
 
Example 19
Source File: CommunityDetection.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Long map(Vertex<K, Tuple2<Long, Double>> vertex) throws Exception {
	return vertex.getValue().f0;
}
 
Example 20
Source File: MapVerticesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Long map(Vertex<Long, Long> value) throws Exception {
	return value.getValue() + 1;
}