Author: aching
Date: Mon Aug 20 03:29:09 2012
New Revision: 1374906
URL: http://svn.apache.org/viewvc?rev=1374906&view=rev
Log:
GIRAPH-295: Additional Example Algorithm to compute Outdegree and
Indegree. (Sean Choi via aching)
Added:
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleInDegreeCountVertex.java
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleOutDegreeCountVertex.java
Modified:
giraph/trunk/CHANGELOG
Modified: giraph/trunk/CHANGELOG
URL:
http://svn.apache.org/viewvc/giraph/trunk/CHANGELOG?rev=1374906&r1=1374905&r2=1374906&view=diff
==============================================================================
--- giraph/trunk/CHANGELOG (original)
+++ giraph/trunk/CHANGELOG Mon Aug 20 03:29:09 2012
@@ -2,6 +2,9 @@ Giraph Change Log
Release 0.2.0 - unreleased
+ GIRAPH-295: Additional Example Algorithm to compute Outdegree and
+ Indegree. (Sean Choi via aching)
+
GIRAPH-305: Adding an argument to GiraphRunner for Master Compute
classes. (Sean Choi via aching)
Added:
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleInDegreeCountVertex.java
URL:
http://svn.apache.org/viewvc/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleInDegreeCountVertex.java?rev=1374906&view=auto
==============================================================================
---
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleInDegreeCountVertex.java
(added)
+++
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleInDegreeCountVertex.java
Mon Aug 20 03:29:09 2012
@@ -0,0 +1,55 @@
+/*
+ * 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.giraph.examples;
+
+import org.apache.giraph.graph.Edge;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.DoubleWritable;
+import org.apache.giraph.graph.EdgeListVertex;
+
+/**
+ * Simple function to return the out degree for each vertex.
+ */
+@Algorithm(
+ name = "Indegree Count"
+)
+public class SimpleInDegreeCountVertex extends EdgeListVertex<
+ LongWritable, LongWritable,
+ DoubleWritable, DoubleWritable> {
+
+ @Override
+ public void compute(Iterable<DoubleWritable> messages) {
+ if (getSuperstep() == 0) {
+ Iterable<Edge<LongWritable, DoubleWritable>> edges = getEdges();
+ for (Edge<LongWritable, DoubleWritable> edge : edges) {
+ sendMessage(edge.getTargetVertexId(), new DoubleWritable(1.0));
+ }
+ } else {
+ long sum = 0;
+ for (DoubleWritable message : messages) {
+ sum++;
+ }
+ LongWritable vertexValue = getValue();
+ vertexValue.set(sum);
+ setValue(vertexValue);
+ voteToHalt();
+ return;
+ }
+ }
+}
Added:
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleOutDegreeCountVertex.java
URL:
http://svn.apache.org/viewvc/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleOutDegreeCountVertex.java?rev=1374906&view=auto
==============================================================================
---
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleOutDegreeCountVertex.java
(added)
+++
giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleOutDegreeCountVertex.java
Mon Aug 20 03:29:09 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.giraph.examples;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.DoubleWritable;
+import org.apache.giraph.graph.EdgeListVertex;
+
+
+/**
+ * Simple function to return the out degree for each vertex.
+ */
+@Algorithm(
+ name = "Outdegree Count"
+)
+public class SimpleOutDegreeCountVertex extends EdgeListVertex<
+ LongWritable, LongWritable,
+ DoubleWritable, DoubleWritable> {
+
+ @Override
+ public void compute(Iterable<DoubleWritable> messages) {
+ LongWritable vertexValue = getValue();
+ vertexValue.set(getNumEdges());
+ setValue(vertexValue);
+ voteToHalt();
+ }
+}