Index: examples/pom.xml
===================================================================
--- examples/pom.xml (revision 1671493)
+++ examples/pom.xml (working copy)
@@ -51,6 +51,11 @@
hama-ml
${project.version}
+
+ com.googlecode.json-simple
+ json-simple
+ 1.1
+
hama-examples-${project.version}
Index: examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java
===================================================================
--- examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java (revision 1671493)
+++ examples/src/main/java/org/apache/hama/examples/util/FastGraphGen.java (working copy)
@@ -21,6 +21,7 @@
import java.util.HashSet;
import java.util.Random;
+import org.apache.commons.cli.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -28,16 +29,12 @@
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hama.HamaConfiguration;
-import org.apache.hama.bsp.BSP;
-import org.apache.hama.bsp.BSPJob;
-import org.apache.hama.bsp.BSPPeer;
-import org.apache.hama.bsp.FileOutputFormat;
-import org.apache.hama.bsp.NullInputFormat;
-import org.apache.hama.bsp.SequenceFileOutputFormat;
+import org.apache.hama.bsp.*;
import org.apache.hama.bsp.sync.SyncException;
import org.apache.hama.commons.io.TextArrayWritable;
import com.google.common.collect.Sets;
+import org.json.simple.JSONArray;
public class FastGraphGen {
protected static Log LOG = LogFactory.getLog(FastGraphGen.class);
@@ -44,6 +41,8 @@
private static String SIZE_OF_MATRIX = "size.of.matrix";
private static String MAX_EDGES = "max.outlinks";
+ private static String OUTPUT_FORMAT = "graph.outputformat";
+ private static String WEIGHT = "graph.weight";
public static class FastGraphGenBSP extends
BSP {
@@ -51,6 +50,8 @@
private Configuration conf;
private int sizeN;
private int maxOutEdges;
+ private boolean isJson;
+ private int weight;
@Override
public void setup(
@@ -58,6 +59,8 @@
this.conf = peer.getConfiguration();
sizeN = conf.getInt(SIZE_OF_MATRIX, 10);
maxOutEdges = conf.getInt(MAX_EDGES, 1);
+ isJson = conf.getBoolean(OUTPUT_FORMAT, false);
+ weight = conf.getInt(WEIGHT, 0);
}
@Override
@@ -74,37 +77,96 @@
}
Random r = new Random();
- for (int i = startID; i < endID; i++) {
- HashSet set = Sets.newHashSet();
- for (int j = 0; j < maxOutEdges; j++) {
- set.add(r.nextInt(sizeN));
+ if (isJson) {
+ for (int i = startID; i < endID; i++) {
+
+ JSONArray vtxArray = new JSONArray();
+ vtxArray.add(i);
+ vtxArray.add(0);
+ JSONArray edgeArray = new JSONArray();
+ HashSet set = Sets.newHashSet();
+ for (int j = 0; j < maxOutEdges; j++) {
+ set.add(r.nextInt(sizeN));
+ }
+ for (int x : set) {
+ JSONArray edge = new JSONArray();
+ edge.add(x);
+ edge.add(r.nextInt(weight) + 1);
+ edgeArray.add(edge);
+ }
+ vtxArray.add(edgeArray);
+ peer.write(new Text(vtxArray.toString()), null);
}
- TextArrayWritable textArrayWritable = new TextArrayWritable();
- Text[] arr = new Text[set.size()];
- int index = 0;
- for (int x : set) {
- arr[index++] = new Text(String.valueOf(x));
+
+ } else {
+ for (int i = startID; i < endID; i++) {
+ HashSet set = Sets.newHashSet();
+ for (int j = 0; j < maxOutEdges; j++) {
+ set.add(r.nextInt(sizeN));
+ }
+
+ TextArrayWritable textArrayWritable = new TextArrayWritable();
+ Text[] arr = new Text[set.size()];
+ int index = 0;
+ for (int x : set) {
+ arr[index++] = new Text(String.valueOf(x));
+ }
+ textArrayWritable.set(arr);
+
+ peer.write(new Text(String.valueOf(i)), textArrayWritable);
}
- textArrayWritable.set(arr);
- peer.write(new Text(String.valueOf(i)), textArrayWritable);
}
-
}
}
- public static void main(String[] args) throws InterruptedException,
- IOException, ClassNotFoundException {
- if (args.length < 4) {
- System.out
- .println("Usage: