Github user vasia commented on a diff in the pull request:
https://github.com/apache/flink/pull/596#discussion_r28645013
--- Diff:
flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/library/ConnectedComponents.java
---
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.graph.library;
+
+import org.apache.flink.graph.Graph;
+import org.apache.flink.graph.GraphAlgorithm;
+import org.apache.flink.graph.spargel.MessageIterator;
+import org.apache.flink.graph.spargel.MessagingFunction;
+import org.apache.flink.graph.spargel.VertexUpdateFunction;
+import org.apache.flink.types.NullValue;
+
+/**
+ * Connected components algorithm.
+ *
+ * Initially, each vertex will have its own ID as a value(is its own
component). The vertices propagate their
+ * current component ID in iterations, each time adopting a new value from
the received neighbor IDs,
+ * provided that the value is less than the current minimum.
+ *
+ * The algorithm converges when vertices no longer update their value or
when the maximum number of iterations
+ * is reached.
+ */
+@SuppressWarnings("serial")
+public class ConnectedComponents implements GraphAlgorithm<Long, Long,
NullValue>{
+
+ private Integer maxIterations;
+
+ public ConnectedComponents(Integer maxIterations) {
+ this.maxIterations = maxIterations;
+ }
+
+ @Override
+ public Graph<Long, Long, NullValue> run(Graph<Long, Long, NullValue>
graph) throws Exception {
+
+ Graph<Long, Long, NullValue> undirectedGraph =
graph.getUndirected();
+
+ // initialize vertex values and run the Vertex Centric Iteration
+ return undirectedGraph.runVertexCentricIteration(new
CCUpdater(),
+ new CCMessenger(), maxIterations);
+ }
+
+ /**
+ * Updates the value of a vertex by picking the minimum neighbor ID out
of all the incoming messages.
+ */
+ public static final class CCUpdater extends VertexUpdateFunction<Long,
Long, Long> {
+
+ @Override
--- End diff --
This essentially does the same as `CCUpdater` in the Spargel example, but
since you want to use this to show that the `VertexUpdateFunction` and the
`MessagingFunction` remain the same, maybe it's better not to change the code
here? i.e. have the exact same code as in the Spargel example.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---