本文整理汇总了Python中State.State.isGoal方法的典型用法代码示例。如果您正苦于以下问题:Python State.isGoal方法的具体用法?Python State.isGoal怎么用?Python State.isGoal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State.State
的用法示例。
在下文中一共展示了State.isGoal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AStar
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import isGoal [as 别名]
def AStar(matrix):
# Set up inital condition.
# Ask for all requiered input.
global statesCount
"""
matrix = map(int,list("123456780"))
print matrix
test = map(int, list("704512836"))
matrixWithMoves = createMoves(matrix)
print test
"""
initialState = State(matrix)
initialState.f = manhathanDistance(matrix)
if initialState.isGoal():
return initialState
frontier = PriorityQueue()
explored = {}
frontier.enqueue(initialState)
statesCount = 1
while frontier:
state = frontier.dequeue()
# print state.to_string() + " " + str(state.f)
explored[state.to_string()] = 1
if state.isGoal():
return state
children = createStatesManhatan(state)
for child in children:
if child.to_string() in explored:
continue
if child not in frontier:
frontier.enqueue(child)
statesCount += 1
else:
ch = frontier.__getitem__(child)
if ch.f > child.f:
# print child.to_string() + " " + str(ch.f) + " " + str(child.f)
frontier.__delitem__(child)
frontier.enqueue(child)
ts = frontier.__getitem__(child)
return None
示例2: hc_Steepest
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import isGoal [as 别名]
def hc_Steepest(matrix):
# Set up inital condition.
currentState = State(matrix)
currentState.f = manhathanDistance(matrix)
nextState = State(matrix)
nextState.f = copy(currentState.f)
statesCount = 1
while True:
children = createStatesManhatan(currentState)
for child in children:
statesCount +=1
if child.f < nextState.f:
nextState = child
if nextState.f >= currentState.f:
if nextState.isGoal():
return "Goal", nextState, statesCount
else:
return 'Local Maxima', nextState, statesCount
currentState = copy(nextState)
return None
示例3: AStar
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import isGoal [as 别名]
def AStar(matrix):
# Set up inital condition.
# Ask for all requiered input.
global statesCount
statesCount = 1
"""
matrix = map(int,list("123456780"))
print matrix
matrixWithMoves = createMoves(matrix)
print matrixWithMoves
"""
initialState = State(matrix)
initialState.f = missplacedTitles(matrix)
if initialState.isGoal():
return initialState
frontier = PriorityQueue()
explored = {}
frontier.enqueue(initialState)
while frontier:
state = frontier.dequeue()
explored[state.to_string()] = 1
if state.isGoal():
return state
children = createStatesMissplaced(state)
for child in children:
if child.to_string() in explored:
continue
if child not in frontier:
frontier.enqueue(child)
statesCount += 1
else:
ch = frontier.__getitem__(child)
if ch.f > child.f:
frontier.__delitem__(child)
frontier.enqueue(child)
# ts = frontier.__getitem__(child)
return None
示例4: hc_RandomRestart
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import isGoal [as 别名]
def hc_RandomRestart(matrix, count):
# Set up inital condition.
# Ask for all requiered input.
currentState = State(copy(matrix))
currentState.f = manhathanDistance(copy(matrix))
nextState = State(copy(matrix))
nextState.f = copy(currentState.f)
statesCount = count
while True:
children = createStatesManhatan(currentState)
for child in children:
statesCount +=1
if child.f < nextState.f:
nextState = child
if nextState.f >= currentState.f:
if nextState.isGoal():
return "Goal", nextState, statesCount
else:
return hc_RandomRestart(createMovesRandomRestart(copy(matrix)), statesCount)
currentState = copy(nextState)
return None