Skip to content

Commit

Permalink
Corrected BenchmarkTest. Close #29
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian committed Apr 6, 2013
1 parent 0d817b3 commit 9c95c01
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,33 @@ public void benchmark() throws InterruptedException {
Maze2D maze = Maze2D.random(i, 0.9);
// Repeat 10 times
//Double mean1 = 0d, mean2 = 0d;
double min1 = Double.MAX_VALUE, min2 = Double.MAX_VALUE;
double min2 = Double.MAX_VALUE, min1 = Double.MAX_VALUE;
DirectedGraph<Point, JungEdge> graph = JungDirectedGraphFromMazeCreator.create(maze);
for (int j = 0; j < times; j++) {
//AStar<Point> it = AStarIteratorFromMazeCreator.create(maze, false);
AStar<Point> it = AlgorithmIteratorFromMazeCreator.astar(maze, false);
Stopwatch w = new Stopwatch().start();
MazeSearch.Result resultIterator = MazeSearch.executeIteratorSearch(it, maze);
long result1 = w.stop().elapsed(TimeUnit.MILLISECONDS);
Stopwatch w1 = new Stopwatch().start();
MazeSearch.Result resultJung = MazeSearch.executeJungSearch(graph, maze);
//In case there is no possible result in the random maze
if(resultJung.equals(MazeSearch.Result.NO_RESULT)){
maze = Maze2D.random(i, 0.9);
graph = JungDirectedGraphFromMazeCreator.create(maze);
j--;
continue;
}
long result1 = w1.stop().elapsed(TimeUnit.MILLISECONDS);
if (result1 < min1) {
min1 = result1;
}
Stopwatch w2 = new Stopwatch().start();
MazeSearch.Result resultJung = MazeSearch.executeJungSearch(graph, maze);
MazeSearch.Result resultIterator = MazeSearch.executeIteratorSearch(it, maze);
long result2 = w2.stop().elapsed(TimeUnit.MILLISECONDS);
if (result2 < min2) {
min2 = result2;
}
assertEquals(resultIterator.getCost(), resultJung.getCost(), 0.001);
}
System.out.println(String.format("%d \t %.5g \t %.5g", i, min1, min2));
System.out.println(String.format("%d \t %.5g \t %.5g", i, min2, min1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ private MazeSearch() {
}

public static final class Result {


public static final Result NO_RESULT = new Result(new ArrayList<Point>(), Double.POSITIVE_INFINITY);
private List<Point> path;
private Double cost;

Expand All @@ -131,6 +132,32 @@ public Double getCost() {
public List<Point> getPath() {
return path;
}

@Override
public int hashCode() {
int hash = 3;
hash = 83 * hash + (this.path != null ? this.path.hashCode() : 0);
hash = 83 * hash + (this.cost != null ? this.cost.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Result other = (Result) obj;
if (this.path != other.path && (this.path == null || !this.path.equals(other.path))) {
return false;
}
if (this.cost != other.cost && (this.cost == null || !this.cost.equals(other.cost))) {
return false;
}
return true;
}
}

//public static Result executePrintIteratorSearch(AStar<Point> it, StringMaze maze) throws InterruptedException {
Expand Down Expand Up @@ -186,6 +213,9 @@ public Double transform(JungEdge input) {
maze.getGoalLoc());
Double cost = 0.0;
List<Point> statePath = new ArrayList<Point>();
if(path.isEmpty()){
return Result.NO_RESULT;
}
for (Iterator<JungEdge> it = path.iterator(); it.hasNext();) {
JungEdge current = it.next();
statePath.add(current.getSource());
Expand Down

0 comments on commit 9c95c01

Please sign in to comment.