Permalink
Browse files

Fixed Boggle Rolls for >5. Made Boggle version a parameter.

  • Loading branch information...
eljefe6a committed Dec 28, 2012
1 parent f3d683f commit 699640cacd6744663c2aecdf20f2f59935b1baa9
Showing with 31 additions and 6 deletions.
  1. +8 −3 src/BoggleDriver.java
  2. +6 −1 src/BoggleMapper.java
  3. +17 −2 src/BoggleRoll.java
View
@@ -34,6 +34,9 @@
/** The parameter name for the roll to be serialized */
public static final String ROLL_PARAM = "roll";
+ /** The parameter name for the roll version */
+ public static final String ROLL_VERSION = "rollversion";
+
@Override
public int run(String[] args) throws Exception {
if (args.length != 4) {
@@ -50,7 +53,7 @@ public int run(String[] args) throws Exception {
// To change how the mappers are created to process the roll,
// pass in -D mapreduce.input.lineinputformat.linespermap=0
// or in code uncomment:
- configuration.set("mapreduce.input.lineinputformat.linespermap", "32");
+ configuration.set("mapreduce.input.lineinputformat.linespermap", "64");
FileSystem fileSystem = FileSystem.get(configuration);
@@ -69,7 +72,7 @@ public int run(String[] args) throws Exception {
configuration.set(BLOOM_PARAM, bloomPath);
configuration.set(DICTIONARY_PARAM, dictionary);
- BoggleRoll roll = BoggleRoll.createRoll(BoggleRoll.bigBoggleVersion);
+ BoggleRoll roll = BoggleRoll.createRoll(configuration.getInt(ROLL_VERSION, BoggleRoll.bigBoggleVersion));
configuration.set(ROLL_PARAM, roll.serialize());
int iteration = traverseGraph(input, configuration, fileSystem, roll);
@@ -102,6 +105,7 @@ private int traverseGraph(String input, Configuration configuration, FileSystem
writeRollFile(input, fileSystem, roll, iteration);
long previousWordCount = 0;
+ long bloomSavings = 0;
// Traverse the graph until it is completely traversed
do {
@@ -134,10 +138,11 @@ private int traverseGraph(String input, Configuration configuration, FileSystem
// Check to see if the entire graph has been traversed
long currentWordCount = job.getCounters().findCounter("boggle", "words").getValue();
+ bloomSavings += job.getCounters().findCounter("boggle", "bloom").getValue();
if (currentWordCount == previousWordCount) {
logger.info("Finished traversing graph after " + iteration + " iterations. Found " + currentWordCount
- + " potential words.");
+ + " potential words. Bloom saved " + bloomSavings + " so far.");
break;
}
View
@@ -108,7 +108,12 @@ private void processNonFinalNode(Context context, String charsSoFar, RollGraphWr
context.write(new Text(newWord), nextGraphWritable);
} else {
- logger.info("Throwing out " + newWord + " because it didn't pass membership test");
+ // Use counters to keep track of how many words were thrown out by the Bloom Filter
+ context.getCounter("boggle", "bloom").increment(1);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Throwing out " + newWord + " because it didn't pass membership test");
+ }
}
}
}
View
@@ -9,13 +9,16 @@
*
*/
public class BoggleRoll {
- // Each dice in Boggle only certain characters. Each character represents a side of the dice
+ /** Constant for new version of Boggle */
public static final int newVersion = 0;
+ /** Constant for old version of Boggle */
public static final int oldVersion = 1;
+ /** Constant for Big Boggle version */
public static final int bigBoggleVersion = 2;
+ // Each dice in Boggle only certain characters. Each character represents a side of the dice
/** Dice for the new version of Boggle */
public static final String[] newVersionDice = { "aaeegn", "elrtty", "aoottw", "abbjoo", "ehrtvw", "cimotv",
"distty", "eiosst", "delrvy", "achops", "humnqu", "eeinsu", "eeghnw", "affkps", "hlnnrz", "deilrx" };
@@ -72,7 +75,19 @@ private BoggleRoll(int version) {
}
private void createRandomVersion(int size) {
-
+ versionDice = new String[size*size];
+
+ Random random = new Random();
+
+ // Big Note!
+ // Only the BoggleRoll created by the driver will have the correct version
+ // of the dice. You could serialize the object out and read it in, but
+ // isn't necessary for this program. We only need to make sure that
+ // the dice sides are serialized correctly (they are).
+
+ for (int i = 0; i < versionDice.length; i++) {
+ versionDice[i] = bigBoggleVersionDice[random.nextInt(bigBoggleVersionDice.length)];
+ }
}
/**

0 comments on commit 699640c

Please sign in to comment.