use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testRemoveInvalidVertex.
@Test
public void testRemoveInvalidVertex() throws Exception {
/*
* Test removeVertex() -- remove an invalid vertex
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
graph = graph.removeVertex(new Vertex<>(6L, 6L));
DataSet<Edge<Long, Long>> data = graph.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testRemoveOneValidOneInvalidEdge.
@Test
public void testRemoveOneValidOneInvalidEdge() throws Exception {
/*
* Test removeEdges() -- one edge is valid, the other is invalid
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
List<Edge<Long, Long>> edgesToBeRemoved = new ArrayList<>();
edgesToBeRemoved.add(new Edge<>(1L, 1L, 51L));
edgesToBeRemoved.add(new Edge<>(6L, 1L, 61L));
graph = graph.removeEdges(edgesToBeRemoved);
DataSet<Edge<Long, Long>> data = graph.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "3,4,34\n" + "3,5,35\n" + "4,5,45\n" + "5,1,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphMutationsITCase method testAddEdges.
@Test
public void testAddEdges() throws Exception {
/*
* Test addEdges() -- simple case
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
List<Edge<Long, Long>> edgesToBeAdded = new ArrayList<>();
edgesToBeAdded.add(new Edge<>(2L, 4L, 24L));
edgesToBeAdded.add(new Edge<>(4L, 1L, 41L));
graph = graph.addEdges(edgesToBeAdded);
DataSet<Edge<Long, Long>> data = graph.getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "1,3,13\n" + "2,3,23\n" + "2,4,24\n" + "3,4,34\n" + "3,5,35\n" + "4,1,41\n" + "4,5,45\n" + "5,1,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class GraphOperationsITCase method testUndirected.
@Test
public void testUndirected() throws Exception {
/*
* Test getUndirected()
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env);
DataSet<Edge<Long, Long>> data = graph.getUndirected().getEdges();
List<Edge<Long, Long>> result = data.collect();
expectedResult = "1,2,12\n" + "2,1,12\n" + "1,3,13\n" + "3,1,13\n" + "2,3,23\n" + "3,2,23\n" + "3,4,34\n" + "4,3,34\n" + "3,5,35\n" + "5,3,35\n" + "4,5,45\n" + "5,4,45\n" + "5,1,51\n" + "1,5,51\n";
compareResultAsTuples(result, expectedResult);
}
use of org.apache.flink.graph.Edge in project flink by apache.
the class EuclideanGraphWeighing method main.
public static void main(String[] args) throws Exception {
if (!parseParameters(args)) {
return;
}
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Vertex<Long, Point>> vertices = getVerticesDataSet(env);
DataSet<Edge<Long, Double>> edges = getEdgesDataSet(env);
Graph<Long, Point, Double> graph = Graph.fromDataSet(vertices, edges, env);
// the edge value will be the Euclidean distance between its src and trg vertex
DataSet<Tuple3<Long, Long, Double>> edgesWithEuclideanWeight = graph.getTriplets().map(new MapFunction<Triplet<Long, Point, Double>, Tuple3<Long, Long, Double>>() {
@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<Long, Long, Double>(srcVertex.getId(), trgVertex.getId(), srcVertex.getValue().euclideanDistance(trgVertex.getValue()));
}
});
Graph<Long, Point, Double> resultedGraph = graph.joinWithEdges(edgesWithEuclideanWeight, new EdgeJoinFunction<Double, Double>() {
public Double edgeJoin(Double edgeValue, Double inputValue) {
return inputValue;
}
});
// retrieve the edges from the final result
DataSet<Edge<Long, Double>> result = resultedGraph.getEdges();
// emit result
if (fileOutput) {
result.writeAsCsv(outputPath, "\n", ",");
// since file sinks are lazy, we trigger the execution explicitly
env.execute("Euclidean Graph Weighing Example");
} else {
result.print();
}
}
Aggregations