Пример #1
0
 def __init__(self, methodName='runTest'):
     super(TestAstar, self).__init__(methodName)
     self.g1 = GridWithWeights(4, 4)
     self.g2 = EightDirectionGrid(4, 4)
     self.g3 = DynamicBoundGrid(4, 4)
     self.g4 = DynamicBoundGridWithShortcuts(4, 4)
     self.g5 = DenseGraph(self.g4)
     self.g6 = DualityGraph(4, 4)
Пример #2
0
class TestGridDB(unittest.TestCase):
    def __init__(self, methodName='runTest'):
        super(TestGridDB, self).__init__(methodName)
        self.g1 = DynamicBoundGrid(4, 4)
        self.g1.set_search((0, 0), (3, 3))
        self.g2 = DynamicBoundGridWithShortcuts(4, 4)
        self.g2.set_search((0, 0), (3, 3))

    def test_case1(self):
        self.assertSetEqual(set(self.g1.neighbors((0, 0))),
                            set([(1, 0), (0, 1), (1, 1)]))

    def test_case2(self):
        self.assertSetEqual(set(self.g2.neighbors((0, 0))),
                            set([(1, 0), (0, 1), (1, 1)]))
Пример #3
0
class TestAstar(unittest.TestCase):
    def __init__(self, methodName='runTest'):
        super(TestAstar, self).__init__(methodName)
        self.g1 = GridWithWeights(4, 4)
        self.g2 = EightDirectionGrid(4, 4)
        self.g3 = DynamicBoundGrid(4, 4)
        self.g4 = DynamicBoundGridWithShortcuts(4, 4)
        self.g5 = DenseGraph(self.g4)
        self.g6 = DualityGraph(4, 4)
        
    def test_case1(self):
        start = (0, 0)
        goal = (3, 3)
        came_from, cost_so_far = a_star_search(self.g1, start, goal)
        path  = reconstruct_path(came_from, start, goal)
        answer = [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 3), (3, 3)]
        self.assertEqual(path, answer)

    def test_case2(self):
        start = (0, 0)
        goal = (3, 3)
        came_from, cost_so_far = a_star_search(self.g2, start, goal)
        path  = reconstruct_path(came_from, start, goal)
        answer = [(0, 0), (1, 1), (2, 2), (3, 3)]
        self.assertEqual(path, answer)
    
    def test_case3(self):
        start = (0, 0)
        goal = (3, 3)
        self.g3.set_search(start, goal)
        came_from, cost_so_far = a_star_search(self.g3, start, goal)
        path  = reconstruct_path(came_from, start, goal)
        answer = [(0, 0), (1, 1), (2, 2), (3, 3)]
        self.assertEqual(path, answer)
    
    def test_case4(self):
        start = (0, 0)
        goal = (3, 3)
        self.g4.set_search(start, goal)
        came_from, cost_so_far = a_star_search(self.g4, start, goal)
        path  = reconstruct_path(came_from, start, goal)
        answer = [(0, 0), (1, 1), (2, 2), (3, 3)]
        self.assertEqual(path, answer)
    
    def test_case5(self):
        start = (0, 0)
        goal = (3, 3)
        self.g5.set_search(start, goal)
        came_from, cost_so_far = a_star_search(self.g5, start, goal)
        path  = reconstruct_path(came_from, start, goal)
        answer = [(0, 0), (1, 1), (2, 2), (3, 3)]
        self.assertEqual(path, answer)
    
    def test_case6(self):
        start = (0, 0)
        goal = (3, 3)
        self.g6.set_search(start, goal)
        came_from, cost_so_far = a_star_search(self.g6, start, goal)
        path  = reconstruct_path(came_from, start, goal)
        answer = [(0, 0), (3, 3)]
        self.assertEqual(path, answer)
Пример #4
0
import time
import matplotlib.pyplot as plt
root = os.path.join(os.path.dirname(__file__), '..')
sys.path.append(root)

from graph.grid8d import EightDirectionGrid
from graph.gridDB import DynamicBoundGridWithShortcuts
from graph.transform import DenseGraph
from pathfinder.astar import a_star_search
from pathfinder.util import reduce_path, reconstruct_path
from shape.Octagon import solid_octagon
from shape.OctagonLine import solid_octagon_line

if __name__ == '__main__':
    grid1 = EightDirectionGrid(10000, 10000)
    grid2 = DynamicBoundGridWithShortcuts(10000, 10000)
    p = 0.5

    for pos in solid_octagon(510, 1000, 20):
        grid1.walls.add(pos)
        grid2.walls.add(pos)

    # case 1
#    for y in range(500, 5500):
#        grid1.walls.add((550, y))
#        grid2.walls.add((550, y))

# case 2
    for pos in solid_octagon_line((550, 500), (550, 5500), 20):
        grid1.walls.add(pos)
        grid2.walls.add(pos)
Пример #5
0
 def __init__(self, methodName='runTest'):
     super(TestGridDB, self).__init__(methodName)
     self.g1 = DynamicBoundGrid(4, 4)
     self.g1.set_search((0, 0), (3, 3))
     self.g2 = DynamicBoundGridWithShortcuts(4, 4)
     self.g2.set_search((0, 0), (3, 3))
Пример #6
0
                    vertex[v1].remove(current)
                    vertex[v1].add(v2)
                    vertex[v2].remove(current)
                    vertex[v2].add(v1)
                    vertex.pop(current)
            elif len(vertex[current]) == 1:
                v = list(vertex[current])[0]
                vertex[v].remove(current)
                vertex.pop(current)

        return vertex

    def neighbors(self, pos):
        return self.vertex[pos]

    def cost(self, from_node, to_node):
        return self.edge[(from_node, to_node)]

    def set_search(self, start, end):
        self.graph.set_search(start, end)
        self.constract()


if __name__ == '__main__':

    grid = DynamicBoundGridWithShortcuts(500, 500)

    start, end = ((0, 0), (5, 12))
    graph = DenseGraph(grid)
    graph.set_search(start, end)
Пример #7
0
import os
import sys
import time
import matplotlib.pyplot as plt
root = os.path.join(os.path.dirname(__file__), '..')
sys.path.append(root)

from graph.gridDB import DynamicBoundGridWithShortcuts, DynamicBoundGrid
from graph.transform import DenseGraph
from pathfinder.astar import a_star_search
from pathfinder.util import reduce_path, reconstruct_path
from shape.Octagon import solid_octagon
from shape.OctagonLine import solid_octagon_line

if __name__ == '__main__':
    grid1 = DynamicBoundGridWithShortcuts(10000, 10000)
    grid2 = DynamicBoundGridWithShortcuts(10000, 10000)
    dg = DenseGraph(grid2)
    p = 0.5

    #    for pos in solid_octagon(510, 1000, 20):
    #        grid1.walls.add(pos)
    #        grid2.walls.add(pos)

    # case 1
    #    for y in range(500, 5500):
    #        grid1.walls.add((550, y))
    #        grid2.walls.add((550, y))

    # case 2
    for pos in solid_octagon_line((550, 500), (550, 5500), 20):