Made function to test speed of A*.
Changed heuristic2.
This commit is contained in:
parent
c0fe5766b0
commit
d150e9c21d
28
AStar.py
28
AStar.py
@ -173,7 +173,7 @@ def succ3A(state):
|
||||
|
||||
def heuristic2(state, goal):
|
||||
# Oblicz odległość Manhattanowską między aktualnym stanem a celem
|
||||
manhattan_distance = (abs(state['x'] - goal[0]) + abs(state['y'] - goal[1])) * 5.5
|
||||
manhattan_distance = (abs(state['x'] - goal[0]) + abs(state['y'] - goal[1])) * 2.5
|
||||
return manhattan_distance
|
||||
|
||||
|
||||
@ -256,3 +256,29 @@ def A_star2(istate, pole, goalTreasure):
|
||||
quit()
|
||||
|
||||
return False
|
||||
|
||||
"""
|
||||
TO TEST SPEED OF ASTAR
|
||||
|
||||
test_speed = False
|
||||
|
||||
if test_speed:
|
||||
time1 = 0
|
||||
time2 = 0
|
||||
cost1 = 0
|
||||
cost2 = 0
|
||||
for i in range(500):
|
||||
print(i)
|
||||
start = time.time()
|
||||
aStarRoot, cost_list, total_cost = AStar.A_star({'x': 0, 'y': 0, 'direction': "E"}, pole, goalTreasure)
|
||||
end = time.time()
|
||||
time1 += end - start
|
||||
cost1 += total_cost
|
||||
start = time.time()
|
||||
aStarRoot2, cost_list, total_cost = AStar.A_star2({'x': 0, 'y': 0, 'direction': "E"}, pole, goalTreasure)
|
||||
end = time.time()
|
||||
time2 += end - start
|
||||
cost2 += total_cost
|
||||
print(time1, time2)
|
||||
print(float(cost1 / 1000), float(cost2 / 1000))
|
||||
"""
|
Loading…
Reference in New Issue
Block a user