org.apache.flink.graph.Vertex Java Examples

The following examples show how to use org.apache.flink.graph.Vertex. 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: GraphCreationITCase.java    From flink with 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 File: VertexDegreesTest.java    From Flink-CEPplus with 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 #3
Source File: SummarizationITCase.java    From flink with 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 #4
Source File: SummarizationITCase.java    From flink with 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 File: VertexInDegreeTest.java    From flink with 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 #6
Source File: GraphCreationITCase.java    From Flink-CEPplus with 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 #7
Source File: GraphCreationITCase.java    From flink with 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 #8
Source File: GraphCreationITCase.java    From flink with 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 #9
Source File: GraphOperationsITCase.java    From flink with 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 #10
Source File: VertexMetrics.java    From flink with 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 #11
Source File: GridGraph.java    From flink with 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 #12
Source File: FromCollectionITCase.java    From flink with 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 #13
Source File: EuclideanGraphWeighing.java    From Flink-CEPplus with 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 #14
Source File: VertexDegreesTest.java    From flink with 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 #15
Source File: ScatterGatherIteration.java    From flink with 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 #16
Source File: TranslateTest.java    From flink with 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 #17
Source File: MapVerticesITCase.java    From Flink-CEPplus with 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 #18
Source File: EdgeDegreesPair.java    From flink with 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 #19
Source File: LabelPropagationITCase.java    From Flink-CEPplus with 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 #20
Source File: VertexDegreeTest.java    From flink with 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 #21
Source File: CommunityDetectionITCase.java    From Flink-CEPplus with 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 #22
Source File: GraphGeneratorUtils.java    From Flink-CEPplus with 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 #23
Source File: SummarizationITCase.java    From Flink-CEPplus with 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 #24
Source File: TranslateGraphIds.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Graph<NEW, VV, EV> runInternal(Graph<OLD, VV, EV> input)
		throws Exception {
	// Vertices
	DataSet<Vertex<NEW, VV>> translatedVertices = translateVertexIds(input.getVertices(), translator, parallelism);

	// Edges
	DataSet<Edge<NEW, EV>> translatedEdges = translateEdgeIds(input.getEdges(), translator, parallelism);

	// Graph
	return Graph.fromDataSet(translatedVertices, translatedEdges, input.getContext());
}
 
Example #25
Source File: VertexOutDegree.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet<Vertex<K, LongValue>> runInternal(Graph<K, VV, EV> input)
		throws Exception {
	// s
	DataSet<Vertex<K, LongValue>> sourceIds = input
		.getEdges()
		.map(new MapEdgeToSourceId<>())
			.setParallelism(parallelism)
			.name("Edge to source ID");

	// s, d(s)
	DataSet<Vertex<K, LongValue>> sourceDegree = sourceIds
		.groupBy(0)
		.reduce(new DegreeCount<>())
		.setCombineHint(CombineHint.HASH)
			.setParallelism(parallelism)
			.name("Degree count");

	if (includeZeroDegreeVertices.get()) {
		sourceDegree = input.getVertices()
			.leftOuterJoin(sourceDegree)
			.where(0)
			.equalTo(0)
			.with(new JoinVertexWithVertexDegree<>())
				.setParallelism(parallelism)
				.name("Zero degree vertices");
	}

	return sourceDegree;
}
 
Example #26
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDifference2() throws Exception {
	/*
	 * Test difference() such that no common vertices are there
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

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

	DataSet<Vertex<Long, Long>> vertex = env.fromElements(new Vertex<>(6L, 6L));

	Graph<Long, Long, Long> graph2 = Graph.fromDataSet(vertex, TestGraphUtils.getLongLongEdgeDataDifference2(env), env);

	graph = graph.difference(graph2);

	List<Edge<Long, Long>> result = graph.getEdges().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);
}
 
Example #27
Source File: VertexDegreesTest.java    From flink with 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 #28
Source File: GraphMutationsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddVerticesBothExisting() throws Exception {
	/*
	 * Test addVertices() -- add two existing vertices
	 */

	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<>();
	vertices.add(new Vertex<>(1L, 1L));
	vertices.add(new Vertex<>(3L, 3L));

	graph = graph.addVertices(vertices);

	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 #29
Source File: Summarization.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Vertex<K, VertexValue<VV>> map(VertexGroupItem<K, VV> value) throws Exception {
	K vertexId = value.getVertexId();
	reuseSummarizedVertexValue.setVertexGroupValue(value.getVertexGroupValue());
	reuseSummarizedVertexValue.setVertexGroupCount(value.getVertexGroupCount());
	return new Vertex<>(vertexId, reuseSummarizedVertexValue);
}
 
Example #30
Source File: PageRank.java    From flink with Apache License 2.0 5 votes vote down vote up
@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());
	}
}