Esempio n. 1
0
def test():
    nodes = []
    for x in range(0, 4):
        nodes.append([])
        for y in range(0, 4):
            nodes[x].append(PositionNode(x, y))
    nodes[0][0].connections = [nodes[0][1], nodes[1][0]]
    nodes[0][1].connections = [nodes[0][0], nodes[0][2]]
    nodes[0][2].connections = [nodes[0][1], nodes[0][3]]
    nodes[0][3].connections = [nodes[0][2], nodes[1][3]]
    nodes[1][0].connections = [nodes[0][0]]
    nodes[1][1].connections = [nodes[1][2], nodes[2][1]]
    nodes[1][2].connections = [nodes[1][1], nodes[2][2]]
    nodes[1][3].connections = [nodes[0][3], nodes[2][3]]
    nodes[2][0].connections = [nodes[3][0], nodes[2][1]]
    nodes[2][1].connections = [nodes[2][0], nodes[1][1], nodes[3][1]]
    nodes[2][2].connections = [nodes[1][2], nodes[2][3]]
    nodes[2][3].connections = [nodes[2][2], nodes[1][3]]
    nodes[3][0].connections = [nodes[2][0]]
    nodes[3][1].connections = [nodes[2][1], nodes[3][2]]
    nodes[3][2].connections = [nodes[3][1], nodes[3][3]]
    nodes[3][3].connections = [nodes[3][2]]
    result = solve(nodes[3][3], nodes[1][0])
    for step in result:
        print(step)
Esempio n. 2
0
def createsolver(kind, pq_impl=None):
    if kind == "leftturn":
        import leftturn
        return ["Left turn only", leftturn.solve]
    elif kind == "depthfirst":
        import depthfirst
        return ["Depth first search", depthfirst.solve]
    elif kind == "dijkstra":
        import dijkstra
        description = "Dijkstra's Algorithm"
        pq = None
        if pq_impl:
            pq = priority_queue(pq_impl)
            description += " (using %s)" % pq_impl
        else:
            pq = priority_queue(DefaultPriorityQueue)
            description += " (using default %s)" % DefaultPriorityQueue
        return [description, lambda maze: dijkstra.solve(maze, pq)]
    elif kind == "astar":
        import astar
        description = "A-star Search"
        pq = None
        if pq_impl:
            pq = priority_queue(pq_impl)
            description += " (using %s)" % pq_impl
        else:
            pq = priority_queue(DefaultPriorityQueue)
            description += " (using default %s)" % DefaultPriorityQueue
        return [description, lambda maze: astar.solve(maze, pq)]
    else:
        import breadthfirst
        return ["Breadth first search", breadthfirst.solve]
Esempio n. 3
0
def main():
    problem = utils.Problem(n_puzzle.get_difficult_puzzle(3, 20),
                            n_puzzle.is_goal, n_puzzle.get_successors,
                            n_puzzle.get_cost, n_puzzle.get_heuristic)

    print('Solving using A*...')
    solutions = astar.solve(problem)
    print(solutions)
    print('')

    print('Solving using Anytime A*...')
    anytime_astar.solve(problem, 1.5)
Esempio n. 4
0
    def __init__(self):
        rospy.init_node('robot')

        self.bootstrap()
        rospy.sleep(1)

        astar_result = astar.solve()

        for result in astar_result:
            self.astar_pub.publish(result)

        mdp_result   = mdp.solve()
        self.mdp_pub.publish(mdp_result)

        self.sim_complete.publish(True)
        rospy.sleep(1)
        rospy.signal_shutdown("Great Success.")
Esempio n. 5
0
    def getPath(self, start, end):
        if not self.passable(end[0], end[1]):
            return None

        def neighbours(v):
            ret = list()
            for i, j in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]:
                nx = v[0] + i
                ny = v[1] + j
                if nx < 0 or ny < 0 or nx >= self.w or ny >= self.h:
                    continue
                if self.passable(nx, ny):
                    ret.append((nx, ny))
            return ret

        def costfunc(n1, n2):
            return self.movementCost(n2[0], n2[1])

        path = astar.solve(neighbours, costfunc, astar.euclidHeuristics(end),
                astar.makeGoalFunc(end), start)
        return path
Esempio n. 6
0
File: robot.py Progetto: s4byun/ROS
 def perform_astar(self):
     astar_result = astar.solve()
     for result in astar_result:
         self.astar_pub.publish(result)
Esempio n. 7
0
#! /usr/bin/python
import numpy as np
import astar
l = ((-1,1,1,1,1.),
     (-1,1,4,4,4),
     (-1,1,1,-1,-1),
     (-1,-1,-1,-1, -1))
mat = np.array(l)

mh = astar.MatrixHolder(mat)
astar = astar.AstarMatrix(mh)

mh.setMat(mat)
astar.reset()

start = (2,2)
goal = (0,4)

path= astar.solve(start,goal)
print "path: ", path


        goal_locations.append(locate_points(stoa(goal, 3), str(point)))
    locations.append(locate_points(stoa(current, 3), " "))
    goal_locations.append(locate_points(stoa(goal, 3), " "))
    for point in range(len(locations)):
        state_priority+=(abs(goal_locations[point][0]-locations[point][0])+abs(goal_locations[point][1]-locations[point][1]))
    return state_priority                  



    
raw1=input("Row 1: ")
raw2=input("Row 2: ")
raw3=input("Row 3: ")
board=[]
endset=[["1", "2", "3"], ["4", "5", "6"], ["7", "8", " "]]
if(len(raw1)==3):
    board.append([thing[:] for thing in raw1])
if(len(raw2)==3):
    board.append([thing[:] for thing in raw2])
if(len(raw3)==3):
    board.append([thing[:] for thing in raw3])

solution, explored=astar.solve(atos(board), atos(endset), generate_offspring, find_priority)
for state in solution:
    nstate=stoa(state, 3)
    for a in range(len(nstate)):
        print("".join(nstate[a]))
    print("\n")
print("Moves Required: ", len(solution)-1)
print("States Checked: ", explored)
Esempio n. 9
0
 def perform_astar(self):
     astar_result = astar.solve()
     for result in astar_result:
         self.astar_pub.publish(result)
Esempio n. 10
0
#! /usr/bin/python
import numpy as np
import astar

l = ((-1, 1, 1, 1, 1.), (-1, 1, 4, 4, 4), (-1, 1, 1, -1, -1), (-1, -1, -1, -1,
                                                               -1))
mat = np.array(l)

mh = astar.MatrixHolder(mat)
astar = astar.AstarMatrix(mh)

mh.setMat(mat)
astar.reset()

start = (2, 2)
goal = (0, 4)

path = astar.solve(start, goal)
print "path: ", path