コード例 #1
0
def tmp(agent_host, tree, dataMap, depthMap, expansionFactor):
    start = dataMap.indexFromPoint(startPos)
    tmp = dataMap.indexFromPoint(
        (startPos[0] + 50, startPos[1], startPos[2] + 50))
    end = (tmp[0], depthMap[tmp[0]][tmp[2]], tmp[2]
           )  # search goal (per for loops)
    waypoints = A_star_graph.search(start, end, tree, expansionFactor)

    cur = (waypoints[0][0], waypoints[0][1], waypoints[0][2])
    curIndex = 0

    t = time.time()  # store timestamp
    while (True):
        for i in range(curIndex + 1, len(waypoints)):
            print "{}/{}, {}".format(i, len(waypoints) - 1, curIndex)
            tmp = (waypoints[i][0], waypoints[i][1], waypoints[i][2]
                   )  # my A* requires tuples, not arrays
            path = A_star.search(cur, tmp, dataMap.data, 2)  # 2 second timeout
            if path:
                walkPath(agent_host, path)
                cur = tmp
                curIndex = i
                break

        if curIndex == len(waypoints) - 2:
            print "done!"
            break
    # print time.time() - t

    return waypoints
コード例 #2
0
def searchTesting(dataMap, depthMap):
    results = []

    #load saved map
    start = dataMap.indexFromPoint(startPos)

    # run A* 40^2 times, each time to a different point
    t0 = time.time()
    count = 1
    for i in range(-200, 200, 10):
        for j in range(-200, 200, 10):
            tmp = dataMap.indexFromPoint(
                (startPos[0] + i, startPos[1], startPos[2] + j))
            end = (tmp[0], depthMap[tmp[0]][tmp[2]], tmp[2]
                   )  #search goal (per for loops)

            t = time.time()  #store timestamp
            path = A_star.search(start, end, dataMap.data,
                                 15)  #15 second timeout

            # print results thus far
            # if(path):
            #     s = "{},{}:  |  Ellapsed: {:f}  |  Current:  {:f}  |  Percentage:  {:f}%  |"
            #     print s.format(i, j, time.time() - t0, time.time() - t, count/16.)
            # else:
            #     s = "{},{}:  |  Ellapsed: {:f}  |  TIMEOUT  |  Percentage:  {:f}%  |"
            #     print s.format(i, j, time.time() - t0, count/16.)
            # count = count + 1

            print("{},{}".format(i, j))
            if (path):
                results.append((i, j, time.time() - t, len(path)))
            else:
                results.append((i, j, time.time() - t, 0))
            pickle.dump(results, open("A_star_test_results.p", "wb"))
コード例 #3
0
# Create Spots
for i in range(cols):
    for j in range(row):
        x = node(i, j)
        grid[i][j] = x
        x.draw()
        graph[i][j] = 0

run = True
findPath = False
while run:
    # pygame.time.delay(1)

    if findPath:
        path = A_star.search(graph, start, end)
        if path == None:
            print("no path")
            run = False
        else:
            for i in range(0, len(path)):
                for j in range(0, len(path[i])):
                    if path[i][j] != -1:
                        node(i, j).changeColorToRed()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

        if pygame.mouse.get_pressed()[0] & (not findPath):
            try: