You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2011/12/14 06:04:38 UTC
svn commit: r1214056 - in /incubator/hama/trunk:
examples/src/main/java/org/apache/hama/examples/
graph/src/main/java/org/apache/hama/graph/
Author: edwardyoon
Date: Wed Dec 14 05:04:37 2011
New Revision: 1214056
URL: http://svn.apache.org/viewvc?rev=1214056&view=rev
Log:
Rename Vertex to VertexWritable
Added:
incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexWritable.java
Modified:
incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java
incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/ShortestPathVertex.java
incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexArrayWritable.java
Modified: incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java?rev=1214056&r1=1214055&r2=1214056&view=diff
==============================================================================
--- incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java (original)
+++ incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/PageRank.java Wed Dec 14 05:04:37 2011
@@ -42,18 +42,18 @@ import org.apache.hama.bsp.HashPartition
import org.apache.hama.bsp.SequenceFileInputFormat;
import org.apache.hama.bsp.SequenceFileOutputFormat;
import org.apache.hama.bsp.sync.SyncException;
-import org.apache.hama.graph.Vertex;
+import org.apache.hama.graph.VertexWritable;
import org.apache.hama.util.KeyValuePair;
public class PageRank extends
- BSP<Vertex, ShortestPathVertexArrayWritable, Text, DoubleWritable> {
+ BSP<VertexWritable, ShortestPathVertexArrayWritable, Text, DoubleWritable> {
public static final Log LOG = LogFactory.getLog(PageRank.class);
- private final HashMap<Vertex, Vertex[]> adjacencyList = new HashMap<Vertex, Vertex[]>();
- private final HashMap<String, Vertex> vertexLookupMap = new HashMap<String, Vertex>();
- private final HashMap<Vertex, Double> tentativePagerank = new HashMap<Vertex, Double>();
+ private final HashMap<VertexWritable, VertexWritable[]> adjacencyList = new HashMap<VertexWritable, VertexWritable[]>();
+ private final HashMap<String, VertexWritable> vertexLookupMap = new HashMap<String, VertexWritable>();
+ private final HashMap<VertexWritable, Double> tentativePagerank = new HashMap<VertexWritable, Double>();
// backup of the last pagerank to determine the error
- private final HashMap<Vertex, Double> lastTentativePagerank = new HashMap<Vertex, Double>();
+ private final HashMap<VertexWritable, Double> lastTentativePagerank = new HashMap<VertexWritable, Double>();
protected static int MAX_ITERATIONS = 30;
protected static String masterTaskName;
@@ -64,11 +64,11 @@ public class PageRank extends
@Override
public void setup(
- BSPPeer<Vertex, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer)
+ BSPPeer<VertexWritable, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer)
throws IOException {
// map our stuff into ram
- KeyValuePair<Vertex, ShortestPathVertexArrayWritable> next = null;
+ KeyValuePair<VertexWritable, ShortestPathVertexArrayWritable> next = null;
while ((next = peer.readNext()) != null) {
adjacencyList.put(next.getKey(), (ShortestPathVertex[]) next.getValue()
.toArray());
@@ -86,7 +86,7 @@ public class PageRank extends
@Override
public void bsp(
- BSPPeer<Vertex, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer)
+ BSPPeer<VertexWritable, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer)
throws IOException, SyncException, InterruptedException {
// while the error not converges against epsilon do the pagerank stuff
@@ -102,10 +102,10 @@ public class PageRank extends
// copy the old pagerank to the backup
copyTentativePageRankToBackup();
// sum up all incoming messages for a vertex
- HashMap<Vertex, Double> sumMap = new HashMap<Vertex, Double>();
+ HashMap<VertexWritable, Double> sumMap = new HashMap<VertexWritable, Double>();
DoubleMessage msg = null;
while ((msg = (DoubleMessage) peer.getCurrentMessage()) != null) {
- Vertex k = vertexLookupMap.get(msg.getTag());
+ VertexWritable k = vertexLookupMap.get(msg.getTag());
if (k == null) {
LOG.fatal("If you see this, partitioning has totally failed.");
}
@@ -118,7 +118,7 @@ public class PageRank extends
// pregel formula:
// ALPHA = 0.15 / NumVertices()
// P(i) = ALPHA + 0.85 * sum
- for (Entry<Vertex, Double> entry : sumMap.entrySet()) {
+ for (Entry<VertexWritable, Double> entry : sumMap.entrySet()) {
tentativePagerank.put(entry.getKey(), ALPHA
+ (entry.getValue() * DAMPING_FACTOR));
}
@@ -129,7 +129,7 @@ public class PageRank extends
}
// in every step send the tentative pagerank of a vertex to its
// adjacent vertices
- for (Vertex vertex : adjacencyList.keySet()) {
+ for (VertexWritable vertex : adjacencyList.keySet()) {
sendMessageToNeighbors(peer, vertex);
}
@@ -142,9 +142,9 @@ public class PageRank extends
@Override
public void cleanup(
- BSPPeer<Vertex, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer) {
+ BSPPeer<VertexWritable, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer) {
try {
- for (Entry<Vertex, Double> row : tentativePagerank.entrySet()) {
+ for (Entry<VertexWritable, Double> row : tentativePagerank.entrySet()) {
peer.write(new Text(row.getKey().getName()), new DoubleWritable(row
.getValue()));
}
@@ -154,7 +154,7 @@ public class PageRank extends
}
private double broadcastError(
- BSPPeer<Vertex, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer,
+ BSPPeer<VertexWritable, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer,
double error) throws IOException, SyncException, InterruptedException {
peer.send(masterTaskName, new DoubleMessage("", error));
peer.sync();
@@ -180,7 +180,7 @@ public class PageRank extends
private double determineError() {
double error = 0.0;
- for (Entry<Vertex, Double> entry : tentativePagerank.entrySet()) {
+ for (Entry<VertexWritable, Double> entry : tentativePagerank.entrySet()) {
error += Math.abs(lastTentativePagerank.get(entry.getKey())
- entry.getValue());
}
@@ -188,16 +188,16 @@ public class PageRank extends
}
private void copyTentativePageRankToBackup() {
- for (Entry<Vertex, Double> entry : tentativePagerank.entrySet()) {
+ for (Entry<VertexWritable, Double> entry : tentativePagerank.entrySet()) {
lastTentativePagerank.put(entry.getKey(), entry.getValue());
}
}
private void sendMessageToNeighbors(
- BSPPeer<Vertex, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer,
- Vertex v) throws IOException {
- Vertex[] outgoingEdges = adjacencyList.get(v);
- for (Vertex adjacent : outgoingEdges) {
+ BSPPeer<VertexWritable, ShortestPathVertexArrayWritable, Text, DoubleWritable> peer,
+ VertexWritable v) throws IOException {
+ VertexWritable[] outgoingEdges = adjacencyList.get(v);
+ for (VertexWritable adjacent : outgoingEdges) {
int mod = Math.abs(adjacent.hashCode() % peer.getNumPeers());
// send a message of the tentative pagerank divided by the size of
// the outgoing edges to all adjacents
Modified: incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/ShortestPathVertex.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/ShortestPathVertex.java?rev=1214056&r1=1214055&r2=1214056&view=diff
==============================================================================
--- incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/ShortestPathVertex.java (original)
+++ incubator/hama/trunk/examples/src/main/java/org/apache/hama/examples/ShortestPathVertex.java Wed Dec 14 05:04:37 2011
@@ -22,9 +22,9 @@ import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableComparable;
-import org.apache.hama.graph.Vertex;
+import org.apache.hama.graph.VertexWritable;
-public final class ShortestPathVertex extends Vertex implements
+public final class ShortestPathVertex extends VertexWritable implements
WritableComparable<ShortestPathVertex> {
private int weight;
Modified: incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java?rev=1214056&r1=1214055&r2=1214056&view=diff
==============================================================================
--- incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java (original)
+++ incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java Wed Dec 14 05:04:37 2011
@@ -1,72 +0,0 @@
-/**
- * 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.hama.graph;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.hadoop.io.Writable;
-
-public class Vertex implements Writable {
-
- protected String name;
-
- public Vertex() {
- super();
- }
-
- public Vertex(String name) {
- super();
- this.name = name;
- }
-
- @Override
- public void readFields(DataInput in) throws IOException {
- this.name = in.readUTF();
- }
-
- @Override
- public void write(DataOutput out) throws IOException {
- out.writeUTF(name);
- }
-
- @Override
- public int hashCode() {
- return name.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Vertex other = (Vertex) obj;
- if (!name.equals(other.name))
- return false;
- return true;
- }
-
- public String getName() {
- return name;
- }
-
-}
Modified: incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexArrayWritable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexArrayWritable.java?rev=1214056&r1=1214055&r2=1214056&view=diff
==============================================================================
--- incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexArrayWritable.java (original)
+++ incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexArrayWritable.java Wed Dec 14 05:04:37 2011
@@ -22,7 +22,7 @@ import org.apache.hadoop.io.ArrayWritabl
public class VertexArrayWritable extends ArrayWritable {
public VertexArrayWritable() {
- super(Vertex.class);
+ super(VertexWritable.class);
}
}
Added: incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexWritable.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexWritable.java?rev=1214056&view=auto
==============================================================================
--- incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexWritable.java (added)
+++ incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexWritable.java Wed Dec 14 05:04:37 2011
@@ -0,0 +1,72 @@
+/**
+ * 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.hama.graph;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.hadoop.io.Writable;
+
+public class VertexWritable implements Writable {
+
+ protected String name;
+
+ public VertexWritable() {
+ super();
+ }
+
+ public VertexWritable(String name) {
+ super();
+ this.name = name;
+ }
+
+ @Override
+ public void readFields(DataInput in) throws IOException {
+ this.name = in.readUTF();
+ }
+
+ @Override
+ public void write(DataOutput out) throws IOException {
+ out.writeUTF(name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ VertexWritable other = (VertexWritable) obj;
+ if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}