Java Code Examples for org.apache.flink.graph.Edge#getTarget()

The following examples show how to use org.apache.flink.graph.Edge#getTarget() . 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-CEPplus with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: Summarization.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: Summarization.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: MusicProfiles.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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));
}
 
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 {

	long weight = Long.MAX_VALUE;
	long minNeighborId = 0;

	for (Edge<Long, Long> edge : edges) {
		if (edge.getValue() < weight) {
			weight = edge.getValue();
			minNeighborId = edge.getTarget();
		}
	}
	out.collect(new Tuple2<>(v.getId(), minNeighborId));
}
 
Example 6
Source File: MusicProfiles.java    From flink with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 7
Source File: MusicProfiles.java    From flink with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 8
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 {

	long weight = Long.MAX_VALUE;
	long minNeighborId = 0;

	for (Edge<Long, Long> edge : edges) {
		if (edge.getValue() < weight) {
			weight = edge.getValue();
			minNeighborId = edge.getTarget();
		}
	}
	out.collect(new Tuple2<>(v.getId(), minNeighborId));
}
 
Example 9
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 {

	long weight = Long.MAX_VALUE;
	long minNeighborId = 0;

	for (Edge<Long, Long> edge : edges) {
		if (edge.getValue() < weight) {
			weight = edge.getValue();
			minNeighborId = edge.getTarget();
		}
	}
	out.collect(new Tuple2<>(v.getId(), minNeighborId));
}
 
Example 10
Source File: JoinWithEdgesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Boolean> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple2<>(edge.getTarget(), true);
}
 
Example 11
Source File: JoinWithEdgesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Long> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple2<>(edge.getTarget(), edge.getValue());
}
 
Example 12
Source File: JoinWithEdgesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple3<Long, Long, Boolean> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple3<>(edge.getSource(), edge.getTarget(), true);
}
 
Example 13
Source File: SimpleEdgeStream.java    From gelly-streaming with Apache License 2.0 4 votes vote down vote up
public Edge<K, NV> map(Edge<K, EV> edge) throws Exception {
	return new Edge<>(edge.getSource(), edge.getTarget(), innerMapper.map(edge));
}
 
Example 14
Source File: BroadcastTriangleCount.java    From gelly-streaming with Apache License 2.0 4 votes vote down vote up
@Override
public void flatMap(Edge<Long, NullValue> edge, Collector<TriangleEstimate> out) throws Exception {
	// Update edge count
	edgeCount++;

	int localBetaSum = 0;

	// Process the edge for all instances
	for (SampleTriangleState state : states) {

		// Flip a coin and with probability 1/i sample a candidate
		if (Coin.flip(state)) {
			state.srcVertex = edge.getSource();
			state.trgVertex = edge.getTarget();

			// Randomly sample the third vertex from V \ {src, trg}
			while (true) {
				state.thirdVertex = (int) Math.floor(Math.random() * vertices);

				if (state.thirdVertex != state.srcVertex && state.thirdVertex != state.trgVertex) {
					break;
				}
			}

			state.srcEdgeFound = false;
			state.trgEdgeFound = false;
			state.beta = 0;
		}

		if (state.beta == 0) {
			// Check if any of the two remaining edges in the candidate has been found
			if ((edge.getSource() == state.srcVertex && edge.getTarget() == state.thirdVertex)
					|| (edge.getSource() == state.thirdVertex && edge.getTarget() == state.srcVertex)) {
				state.srcEdgeFound = true;
			}

			if ((edge.getSource() == state.trgVertex && edge.getTarget() == state.thirdVertex)
					|| (edge.getSource() == state.thirdVertex && edge.getTarget() == state.trgVertex)) {
				state.trgEdgeFound = true;
			}

			state.beta = (state.srcEdgeFound && state.trgEdgeFound) ? 1 : 0;
		}

		if (state.beta == 1) {
			localBetaSum++;
		}
	}

	if (localBetaSum != previousResult) {
		previousResult = localBetaSum;

		int source = getRuntimeContext().getIndexOfThisSubtask();
		out.collect(new TriangleEstimate(source, edgeCount, localBetaSum));
	}
}
 
Example 15
Source File: JoinWithEdgesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Boolean> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple2<>(edge.getTarget(), true);
}
 
Example 16
Source File: JoinWithEdgesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Long> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple2<>(edge.getTarget(), edge.getValue());
}
 
Example 17
Source File: JoinWithEdgesITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple3<Long, Long, Boolean> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple3<>(edge.getSource(), edge.getTarget(), true);
}
 
Example 18
Source File: JoinWithEdgesITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Boolean> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple2<>(edge.getTarget(), true);
}
 
Example 19
Source File: JoinWithEdgesITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Tuple2<Long, Long> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple2<>(edge.getTarget(), edge.getValue());
}
 
Example 20
Source File: JoinWithEdgesITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Tuple3<Long, Long, Boolean> map(Edge<Long, Long> edge) throws Exception {
	return new Tuple3<>(edge.getSource(), edge.getTarget(), true);
}