Skip to content

Commit

Permalink
Merge pull request #166 from PaulJackson123/contrib/165
Browse files Browse the repository at this point in the history
Contrib/165
  • Loading branch information
pablormier committed Jan 11, 2016
2 parents 3f90e4d + bbb9147 commit 5825945
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import es.usc.citius.hipster.algorithm.Hipster;
import es.usc.citius.hipster.model.Transition;
import es.usc.citius.hipster.model.function.CostFunction;
import es.usc.citius.hipster.model.function.HeuristicFunction;
import es.usc.citius.hipster.model.function.impl.StateTransitionFunction;
import es.usc.citius.hipster.model.problem.ProblemBuilder;
import es.usc.citius.hipster.model.problem.SearchProblem;
Expand Down Expand Up @@ -60,8 +61,8 @@ public static void main(String[] args) throws InterruptedException {
final Maze2D maze = example.getMaze();
// In order to search, we need at least the origin and the goal destination.
// We can take these two points from the default maze:
Point origin = maze.getInitialLoc();
Point goal = maze.getGoalLoc();
final Point origin = maze.getInitialLoc();
final Point goal = maze.getGoalLoc();
// The maze is a 2D map, where each tile defined by 2D coordinates x and y
// can be empty or occupied by an obstacle. We have to define de transition
// function that tells the algorithm which are the available movements from
Expand Down Expand Up @@ -99,6 +100,16 @@ public Double evaluate(Transition<Void, Point> transition) {
return source.distance(destination);
}
})
.useHeuristicFunction(new HeuristicFunction<Point, Double>() {
// Give A* an estimate for the remaining distance to goal. Estimate need not be exact as long as
// it doesn't overestimate the remaining distance.
@Override
public Double estimate(Point state) {
// Provide Euclidean distance as simple estimate.
// Manhattan distance is not applicable as it doesn't support diagonal transitions.
return state.distance(goal);
}
})
.build();

//MazeSearch.printSearch(Hipster.createAStar(p).iterator(), maze);
Expand Down

0 comments on commit 5825945

Please sign in to comment.