Java Code Examples for org.apache.flink.graph.Vertex

The following examples show how to use org.apache.flink.graph.Vertex. These examples are extracted from open source projects. 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 Project: flink   Source File: GraphCreationITCase.java    License: Apache License 2.0 7 votes vote down vote up
@Test
public void testCreateWithMapper() throws Exception {
	/*
	 * Test create() with edge dataset and a mapper that assigns the id as value
     */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongEdgeData(env),
		new AssignIdAsValueMapper(), env);

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,1\n" +
		"2,2\n" +
		"3,3\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 2
Source Project: flink   Source File: GraphCreationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFromTuple2WithMapper() throws Exception {
	/*
	 * Test graph creation with fromTuple2DataSet with vertex initializer
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple2<Long, Long>> edges = TestGraphUtils.getLongLongTuple2Data(env);

	Graph<Long, String, NullValue> graph = Graph.fromTuple2DataSet(edges,
		new BooMapper(), env);

	List<Vertex<Long, String>> result = graph.getVertices().collect();

	expectedResult = "1,boo\n" +
		"2,boo\n" +
		"3,boo\n" +
		"4,boo\n" +
		"6,boo\n" +
		"10,boo\n" +
		"20,boo\n" +
		"30,boo\n" +
		"40,boo\n" +
		"60,boo\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 3
Source Project: flink   Source File: VertexInDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithUndirectedSimpleGraph() throws Exception {
	DataSet<Vertex<IntValue, LongValue>> inDegree = undirectedSimpleGraph
		.run(new VertexInDegree<IntValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,2)\n" +
		"(1,3)\n" +
		"(2,3)\n" +
		"(3,4)\n" +
		"(4,1)\n" +
		"(5,1)";

	TestBaseUtils.compareResultAsText(inDegree.collect(), expectedResult);
}
 
Example 4
Source Project: flink   Source File: SummarizationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, String> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env);

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example 5
Source Project: flink   Source File: GraphOperationsITCase.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("serial")
@Test
public void testFilterVertices() throws Exception {
	/*
	 * Test filterOnVertices:
	 */
	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.filterOnVertices(new FilterFunction<Vertex<Long, Long>>() {
		public boolean filter(Vertex<Long, Long> vertex) throws Exception {
			return (vertex.getValue() > 2);
		}
	}).getEdges();

	List<Edge<Long, Long>> result = data.collect();

	expectedResult = "3,4,34\n" +
		"3,5,35\n" +
		"4,5,45\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 6
Source Project: Flink-CEPplus   Source File: EuclideanGraphWeighing.java    License: Apache License 2.0 6 votes vote down vote up
private static DataSet<Vertex<Long, Point>> getVerticesDataSet(ExecutionEnvironment env) {
	if (fileOutput) {
		return env.readCsvFile(verticesInputPath)
				.lineDelimiter("\n")
				.types(Long.class, Double.class, Double.class)
				.map(new MapFunction<Tuple3<Long, Double, Double>, Vertex<Long, Point>>() {

					@Override
					public Vertex<Long, Point> map(Tuple3<Long, Double, Double> value) throws Exception {
						return new Vertex<>(value.f0, new Point(value.f1, value.f2));
					}
				});
	} else {
		return EuclideanGraphData.getDefaultVertexDataSet(env);
	}
}
 
Example 7
Source Project: flink   Source File: TranslateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

	int count = 10;

	List<Vertex<LongValue, LongValue>> vertexList = new LinkedList<>();
	List<Edge<LongValue, LongValue>> edgeList = new LinkedList<>();

	for (long l = 0; l < count; l++) {
		LongValue lv0 = new LongValue(l);
		LongValue lv1 = new LongValue(l + 1);
		LongValue lv2 = new LongValue(l + 2);
		vertexList.add(new Vertex<>(lv0, lv1));
		edgeList.add(new Edge<>(lv0, lv1, lv2));
	}

	graph = Graph.fromCollection(vertexList, edgeList, env);
}
 
Example 8
Source Project: Flink-CEPplus   Source File: MapVerticesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithCustomParametrizedType() throws Exception {
	/*
	 * Test mapVertices() and change the value type to a parameterized custom type
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Vertex<Long, DummyCustomParameterizedType<Double>>> mappedVertices = graph.mapVertices(
		new ToCustomParametrizedTypeMapper()).getVertices();
	List<Vertex<Long, DummyCustomParameterizedType<Double>>> result = mappedVertices.collect();

	expectedResult = "1,(1.0,1)\n" +
		"2,(2.0,2)\n" +
		"3,(3.0,3)\n" +
		"4,(4.0,4)\n" +
		"5,(5.0,5)\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 9
Source Project: flink   Source File: EdgeDegreesPair.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DataSet<Edge<K, Tuple3<EV, Degrees, Degrees>>> runInternal(Graph<K, VV, EV> input)
		throws Exception {
	// s, t, d(s)
	DataSet<Edge<K, Tuple2<EV, Degrees>>> edgeSourceDegrees = input
		.run(new EdgeSourceDegrees<K, VV, EV>()
			.setParallelism(parallelism));

	// t, d(t)
	DataSet<Vertex<K, Degrees>> vertexDegrees = input
		.run(new VertexDegrees<K, VV, EV>()
			.setParallelism(parallelism));

	// s, t, (d(s), d(t))
	return edgeSourceDegrees
		.join(vertexDegrees, JoinHint.REPARTITION_HASH_SECOND)
		.where(1)
		.equalTo(0)
		.with(new JoinEdgeDegreeWithVertexDegree<>())
			.setParallelism(parallelism)
			.name("Edge target degree");
}
 
Example 10
Source Project: Flink-CEPplus   Source File: LabelPropagationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleIteration() throws Exception {
	/*
	 * Test one iteration of label propagation example with a simple graph
	 */
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, NullValue> inputGraph = Graph.fromDataSet(
		LabelPropagationData.getDefaultVertexSet(env),
		LabelPropagationData.getDefaultEdgeDataSet(env), env);

	List<Vertex<Long, Long>> result = inputGraph
		.run(new LabelPropagation<>(1))
		.collect();

	expectedResult = LabelPropagationData.LABELS_AFTER_1_ITERATION;
	compareResultAsTuples(result, expectedResult);
}
 
Example 11
Source Project: Flink-CEPplus   Source File: CommunityDetectionITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleIteration() throws Exception {
	/*
	 * Test one iteration of the Simple Community Detection Example
	 */

	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Double> inputGraph = Graph.fromDataSet(
		CommunityDetectionData.getSimpleEdgeDataSet(env), new InitLabels(), env);

	List<Vertex<Long, Long>> result = inputGraph.run(new CommunityDetection<>(1, CommunityDetectionData.DELTA))
		.getVertices().collect();

	expected = CommunityDetectionData.COMMUNITIES_SINGLE_ITERATION;
	compareResultAsTuples(result, expected);
}
 
Example 12
Source Project: Flink-CEPplus   Source File: SummarizationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeLongValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateVertexValues<>(new StringToLong()))
		.run(new TranslateEdgeValues<>(new StringToLong()));

	List<Vertex<Long, Summarization.VertexValue<Long>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<Long>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<Long>, EdgeValue<Long>> output =
		input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example 13
Source Project: Flink-CEPplus   Source File: VertexDegreesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	DataSet<Vertex<LongValue, Degrees>> degreesWithoutZeroDegreeVertices = emptyGraphWithVertices
		.run(new VertexDegrees<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degreesWithoutZeroDegreeVertices.collect().size());

	DataSet<Vertex<LongValue, Degrees>> degreesWithZeroDegreeVertices = emptyGraphWithVertices
		.run(new VertexDegrees<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,(0,0,0))\n" +
		"(1,(0,0,0))\n" +
		"(2,(0,0,0))";

	TestBaseUtils.compareResultAsText(degreesWithZeroDegreeVertices.collect(), expectedResult);
}
 
Example 14
Source Project: Flink-CEPplus   Source File: GraphGeneratorUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generates {@link Vertex Vertices} with sequential, numerical labels.
 *
 * @param env the Flink execution environment.
 * @param parallelism operator parallelism
 * @param vertexCount number of sequential vertex labels
 * @return {@link DataSet} of sequentially labeled {@link Vertex vertices}
 */
public static DataSet<Vertex<LongValue, NullValue>> vertexSequence(ExecutionEnvironment env, int parallelism, long vertexCount) {
	Preconditions.checkArgument(vertexCount >= 0, "Vertex count must be non-negative");

	if (vertexCount == 0) {
		return env
			.fromCollection(Collections.emptyList(), TypeInformation.of(new TypeHint<Vertex<LongValue, NullValue>>(){}))
				.setParallelism(parallelism)
				.name("Empty vertex set");
	} else {
		LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, vertexCount - 1);

		DataSource<LongValue> vertexLabels = env
			.fromParallelCollection(iterator, LongValue.class)
				.setParallelism(parallelism)
				.name("Vertex indices");

		return vertexLabels
			.map(new CreateVertex())
				.setParallelism(parallelism)
				.name("Vertex sequence");
	}
}
 
Example 15
Source Project: flink   Source File: VertexDegreeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	DataSet<Vertex<LongValue, LongValue>> degree;

	degree = emptyGraphWithVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degree.collect().size());

	degree = emptyGraphWithVertices
		.run(new VertexDegree<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,0)\n" +
		"(1,0)\n" +
		"(2,0)";

	TestBaseUtils.compareResultAsText(degree.collect(), expectedResult);
}
 
Example 16
Source Project: flink   Source File: ScatterGatherIteration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void coGroup(Iterable<Edge<K, EV>> edges, Iterable<Vertex<K, Tuple3<VV, LongValue, LongValue>>> state,
					Collector<Tuple2<K, Message>> out) throws Exception {

	final Iterator<Vertex<K, Tuple3<VV, LongValue, LongValue>>> stateIter = state.iterator();

	if (stateIter.hasNext()) {
		Vertex<K, Tuple3<VV, LongValue, LongValue>> vertexWithDegrees = stateIter.next();

		nextVertex.f0 = vertexWithDegrees.f0;
		nextVertex.f1 = vertexWithDegrees.f1.f0;

		scatterFunction.setInDegree(vertexWithDegrees.f1.f1.getValue());
		scatterFunction.setOutDegree(vertexWithDegrees.f1.f2.getValue());

		scatterFunction.set(edges.iterator(), out, vertexWithDegrees.getId());
		scatterFunction.sendMessages(nextVertex);
	}
}
 
Example 17
Source Project: flink   Source File: GridGraph.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Graph<LongValue, NullValue, NullValue> generate() {
	Preconditions.checkState(!dimensions.isEmpty(), "No dimensions added to GridGraph");

	// Vertices
	DataSet<Vertex<LongValue, NullValue>> vertices = GraphGeneratorUtils.vertexSequence(env, parallelism, vertexCount);

	// Edges
	LongValueSequenceIterator iterator = new LongValueSequenceIterator(0, this.vertexCount - 1);

	DataSet<Edge<LongValue, NullValue>> edges = env
		.fromParallelCollection(iterator, LongValue.class)
			.setParallelism(parallelism)
			.name("Edge iterators")
		.flatMap(new LinkVertexToNeighbors(vertexCount, dimensions))
			.setParallelism(parallelism)
			.name("Grid graph edges");

	// Graph
	return Graph.fromDataSet(vertices, edges, env);
}
 
Example 18
Source Project: flink   Source File: VertexDegreesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEmptyGraphWithVertices() throws Exception {
	DataSet<Vertex<LongValue, Degrees>> degreesWithoutZeroDegreeVertices = emptyGraphWithVertices
		.run(new VertexDegrees<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degreesWithoutZeroDegreeVertices.collect().size());

	DataSet<Vertex<LongValue, Degrees>> degreesWithZeroDegreeVertices = emptyGraphWithVertices
		.run(new VertexDegrees<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	String expectedResult =
		"(0,(0,0,0))\n" +
		"(1,(0,0,0))\n" +
		"(2,(0,0,0))";

	TestBaseUtils.compareResultAsText(degreesWithZeroDegreeVertices.collect(), expectedResult);
}
 
Example 19
Source Project: flink   Source File: FromCollectionITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFromCollectionEdgesWithInitialValue() throws Exception {
	/*
        * Test fromCollection(edges) with vertices initialised by a
        * function that takes the id and doubles it
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromCollection(TestGraphUtils.getLongLongEdges(),
		new InitVerticesMapper(), env);

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,8\n" +
		"5,10\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 20
Source Project: Flink-CEPplus   Source File: GraphCreationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWithMapper() throws Exception {
	/*
	 * Test create() with edge dataset and a mapper that assigns the id as value
     */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongEdgeData(env),
		new AssignIdAsValueMapper(), env);

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,1\n" +
		"2,2\n" +
		"3,3\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 21
Source Project: flink   Source File: GraphCreationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWithMapper() throws Exception {
	/*
	 * Test create() with edge dataset and a mapper that assigns the id as value
     */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongEdgeData(env),
		new AssignIdAsValueMapper(), env);

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,1\n" +
		"2,2\n" +
		"3,3\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 22
Source Project: flink   Source File: VertexMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public VertexMetrics<K, VV, EV> run(Graph<K, VV, EV> input)
		throws Exception {
	super.run(input);

	DataSet<Vertex<K, Degrees>> vertexDegree = input
		.run(new VertexDegrees<K, VV, EV>()
			.setIncludeZeroDegreeVertices(includeZeroDegreeVertices)
			.setParallelism(parallelism));

	vertexMetricsHelper = new VertexMetricsHelper<>();

	vertexDegree
		.output(vertexMetricsHelper)
			.name("Vertex metrics");

	return this;
}
 
Example 23
Source Project: flink   Source File: SummarizationITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, String> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env);

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example 24
Source Project: flink   Source File: VertexDegreesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithEmptyGraphWithoutVertices() throws Exception {
	DataSet<Vertex<LongValue, Degrees>> degreesWithoutZeroDegreeVertices = emptyGraphWithoutVertices
		.run(new VertexDegrees<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(false));

	assertEquals(0, degreesWithoutZeroDegreeVertices.collect().size());

	DataSet<Vertex<LongValue, Degrees>> degreesWithZeroDegreeVertices = emptyGraphWithoutVertices
		.run(new VertexDegrees<LongValue, NullValue, NullValue>()
			.setIncludeZeroDegreeVertices(true));

	assertEquals(0, degreesWithZeroDegreeVertices.collect().size());
}
 
Example 25
Source Project: flink   Source File: GatherSumApplyConfigurationITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIterationDirectionIN() throws Exception {
	/*
	 * Test that if the direction parameter IN is given, the iteration works as expected
	 * (i.e. it gathers information from the OUT edges and neighbors and the information is calculated for an IN edge
	 * When data is gathered from the OUT edges the Gather Sum and Apply functions
	 * set the set of vertices which have path from a vertex as the value of that vertex
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	GSAConfiguration parameters = new GSAConfiguration();

	parameters.setDirection(EdgeDirection.IN);

	List<Edge<Long, Long>> edges = TestGraphUtils.getLongLongEdges();

	edges.remove(0);

	Graph<Long, HashSet<Long>, Long> graph = Graph
		.fromCollection(TestGraphUtils.getLongLongVertices(), edges, env)
		.mapVertices(new GatherSumApplyConfigurationITCase.InitialiseHashSetMapper());

	DataSet<Vertex<Long, HashSet<Long>>> resultedVertices = graph.runGatherSumApplyIteration(
			new GetReachableVertices(), new FindAllReachableVertices(), new UpdateReachableVertices(), 4,
			parameters)
		.getVertices();
	List<Vertex<Long, HashSet<Long>>> result = resultedVertices.collect();

	expectedResult = "1,[1, 3, 4, 5]\n"
		+ "2,[1, 2, 3, 4, 5]\n"
		+ "3,[1, 3, 4, 5]\n"
		+ "4,[1, 3, 4, 5]\n"
		+ "5,[1, 3, 4, 5]\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 26
Source Project: Flink-CEPplus   Source File: LabelPropagationData.java    License: Apache License 2.0 5 votes vote down vote up
public static final DataSet<Vertex<Long, Long>> getDefaultVertexSet(ExecutionEnvironment env) {

		List<Vertex<Long, Long>> vertices = new ArrayList<>();
		vertices.add(new Vertex<>(1L, 10L));
		vertices.add(new Vertex<>(2L, 10L));
		vertices.add(new Vertex<>(3L, 30L));
		vertices.add(new Vertex<>(4L, 40L));
		vertices.add(new Vertex<>(5L, 40L));
		vertices.add(new Vertex<>(6L, 40L));
		vertices.add(new Vertex<>(7L, 40L));

		return env.fromCollection(vertices);
	}
 
Example 27
Source Project: Flink-CEPplus   Source File: GraphOperationsITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUnion() throws Exception {
	/*
	 * Test union()
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	List<Vertex<Long, Long>> vertices = new ArrayList<>();
	List<Edge<Long, Long>> edges = new ArrayList<>();

	vertices.add(new Vertex<>(6L, 6L));
	edges.add(new Edge<>(6L, 1L, 61L));

	graph = graph.union(Graph.fromCollection(vertices, edges, env));

	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" +
		"6,1,61\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example 28
Source Project: Flink-CEPplus   Source File: EuclideanGraphData.java    License: Apache License 2.0 5 votes vote down vote up
public static DataSet<Vertex<Long, EuclideanGraphWeighing.Point>> getDefaultVertexDataSet(ExecutionEnvironment env) {

		List<Vertex<Long, EuclideanGraphWeighing.Point>> vertices = new ArrayList<>();
		for (int i = 1; i <= NUM_VERTICES; i++) {
			vertices.add(new Vertex<>(new Long(i),
				new EuclideanGraphWeighing.Point(new Double(i), new Double(i))));
		}

		return env.fromCollection(vertices);
	}
 
Example 29
Source Project: flink   Source File: GSASingleSourceShortestPaths.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 30
@Override
public void iterateNeighbors(Iterable<Tuple3<Long, Edge<Long, Long>, Vertex<Long, Long>>> neighbors,
		Collector<Tuple2<Long, Long>> out) throws Exception {

	long sum = 0;
	Tuple3<Long, Edge<Long, Long>, Vertex<Long, Long>> next = null;
	for (Tuple3<Long, Edge<Long, Long>, Vertex<Long, Long>> neighbor : neighbors) {
		next = neighbor;
		sum += next.f2.getValue();
	}
	if (next.f0 > 2) {
		out.collect(new Tuple2<>(next.f0, sum));
		out.collect(new Tuple2<>(next.f0, sum * 2));
	}
}