서울시립대 인공지능 AI 코딩 과제 BFS, DFS, A*, IDA* 8 PUZZLE SOLUTION
- 최초 등록일
- 2019.07.29
- 최종 저작일
- 2018.09
- 8페이지/ MS 워드
- 가격 2,500원
소개글
BFS, DFS, A*, IDA* 8 PUZZLE SOLUTION
목차
없음
본문내용
# Search Algorithms
def graphSearch(problem, strategy):
start = problem.getStartState()
explored = set([str(start[0])])
strategy.push(start)
while not strategy.empty():
node = strategy.pop()
if problem.isGoalState(node):
# return the solution path and no. of explored nodes
return (node[2], len(explored))
for move in problem.getSuccessors(node):
gridCopy = str(move[0])
if gridCopy not in explored:
explored.add(gridCopy)
strategy.push(move)
return None
def depthFirstSearch(problem):
return graphSearch(problem, Stack())
def breadthFirstSearch(problem):
return graphSearch(problem, Queue())
def uniformCostSearch(problem):
return graphSearch(problem, PriorityQueue(lambda state: len(state[2])))
def astarSearch(problem, heuristic):
# A* uses path cost from start state + heuristic estimate to a goal
totalCost = lambda state: len(state[2]) + heuristic(state)
참고 자료
없음