Last active
August 29, 2015 14:22
-
-
Save kartikkukreja/a676cea69bf76abaa861 to your computer and use it in GitHub Desktop.
Iterative Deepening DFS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def depthLimitedDFS(problem, state, depth): | |
if problem.isGoalState(state): | |
return state[1] | |
if depth <= 0: | |
return None | |
for move in problem.getSuccessors(state): | |
solution = depthLimitedDFS(problem, move, depth-1) | |
if solution is not None: | |
return solution | |
return None | |
def iterativeDeepeningDFS(problem): | |
depth = 1 | |
while True: | |
solution = depthLimitedDFS(problem, problem.getStartState(), depth) | |
if solution is not None: | |
return solution | |
depth += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment