Beispiel #1
0
def main():  
    # How much it expand before quitting, if -1 it will search until goal found
    depthLimit = 10000
    
    _map_ = pp.generateMap2d_obstacle([100,100])
    #_map_ = pp.generateMap2d([60,60])
    
    # Dummy so we can run both with and without obstacle without changing code
    if len(_map_) == 2:
        map = _map_
    else:
        map = [_map_]

    # X,Y: Wrong, someone the data is placed Y,X)
    start, goal = tuple(np.argwhere(map[0] == -2)[0]), tuple(np.argwhere(map[0] == -3)[0])
    print("Start value: ",start, " Goal value: ", goal)
    
    # Plot each algorithm
    for x in range(0,8):
        data = defineClass(_map_, start, goal, x, depthLimit)
        if len(data[0]) == 0: 
            print("Couldnt find path") 
            continue
        
        newMap = data[0][0]
        if data[0][1] == depthLimit: 
            print("Depth limit reached for", str(data[1]))
            continue

        pp.plotMap(mapFunc(map[0], newMap), pathFunc(newMap, goal),str(data[1]) + ", g: " + str(data[0][1]) +  " Expanded: " + str(data[0][2]))

        print(str(data[1]) + " g: " + str(data[0][1]), " Steps:", str(data[0][2]))
    plt.show()
    '''
Beispiel #2
0
                if theMap[next.pos[0]][next.pos[1]] >= 0:
                    theMap[next.pos[0]][next.pos[1]] = next.depth

                self.searchedNodes += 1
                self.queue.sort_add(next)

        return self.path


if __name__ == "__main__":

    # map_object, info = pp.generateMap2d([60,60])
    map_object, info = pp.generateMap2d_obstacle([60, 60])
    print(info)
    start = Node(
        [np.where(map_object == -2)[0][0],
         np.where(map_object == -2)[1][0]], None, 0, 0)
    goal = Node(
        [np.where(map_object == -3)[0][0],
         np.where(map_object == -3)[1][0]], None, 0, 0)

    print("Start node is: {}".format(start.pos))
    print("Goal node is at: {}".format(goal.pos))

    searcher = AstarC()
    searcher.search(map_object, start, goal, info)
    print("Number of visited nodes: {}".format(searcher.searchedNodes))
    print("Length of path: {}".format(
        len(searcher.path[0]) + len(searcher.path[1])))
    pp.plotMap(map_object, searcher.path)