jobConf.setReducerClass(AllPairsShortestPathReduce.class);
jobConf.setCombinerClass(AllPairsShortestPathCombiner.class);
jobConf.setNumMapTasks(numberOfMapTasks);
jobConf.setNumReduceTasks(numberOfReduceTasks);
TwisterModel mrDriver = new TwisterDriver(jobConf);
mrDriver.configureMaps();
int loopCount = 0;
TwisterMonitor monitor = null;
for (loopCount = 0;; loopCount++) {
monitor = mrDriver.runMapReduce(getKeyValuesForMap(numberOfMapTasks));
monitor.monitorTillCompletion();
Hashtable<Integer, Node> newGraph = ((AllPairsShortestPathCombiner) mrDriver
.getCurrentCombiner()).getResults();
System.out.println(" Loop Count: " + loopCount);
if (true) {
int converged = 1;
for (int m : this.graph.getNodes().keySet())
for (int n : this.graph.getNodes().get(m).getEdges()
.keySet())
if (this.graph.getNodes().get(m).getEdgeWeight(n) != newGraph
.get(m).getEdgeWeight(n))
converged = 0;
if (converged == 1) {
System.out.println("Converged!");
break;
} else
System.out.println("Not yet Converged!");
}
// reset nodes of the graph
this.graph.setNodes(newGraph);
}
this.graph.storeToFile("graph-out");
double timeInSeconds = ((double) (System.currentTimeMillis() - beforeTime)) / 1000;
System.out.println("Total Time for All pairs shortest path : "
+ timeInSeconds);
System.out.println("Total loop count : " + (loopCount));
// This closes the broker connections
mrDriver.close();
}