コード例 #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 TestDualityGraph(unittest.TestCase):
    def __init__(self, methodName='runTest'):
        super(TestDualityGraph, self).__init__(methodName)
        self.g1 = DualityGraph(4, 4)
        self.g1.set_search((0, 0), (3, 3))

    def test_case1(self):
        self.assertSetEqual(set(self.g1.neighbors((0, 0))),
                            set([(3, 0), (0, 3), (3, 3)]))
コード例 #3
0
import sys
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.duality_graph import DualityGraph
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 = DualityGraph(10000, 10000)
    p = 0.0

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

    #    start1, goal1 = (0, 500), (600, 5100)
    #    start2, goal2 = (10, 500), (600, 5200)
    #    start3, goal3 = (20, 500), (600, 5300)

    for pos in solid_octagon_line((550, 500), (550, 5500), 20):
        grid1.walls.add(pos)
        grid2.walls.add(pos)

    start1, goal1 = (500, 500), (600, 5100)
コード例 #4
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)
コード例 #5
0
import sys
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.duality_graph import DualityGraph
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__':
    grid = DualityGraph(10000, 10000)
    p = 0.0

    grid.walls.add((0, 1))
    grid.walls.add((0, 2))
    grid.walls.add((0, 3))
    grid.walls.add((0, 4))

    start, goal = (0, 0), (0, 5)

    plt.figure()
    plt.scatter([pos[0] for pos in grid.walls], [pos[1] for pos in grid.walls],
                color='black')

    t0 = time.time()
    grid.set_search(start, goal)
コード例 #6
0
 def __init__(self, methodName='runTest'):
     super(TestDualityGraph, self).__init__(methodName)
     self.g1 = DualityGraph(4, 4)
     self.g1.set_search((0, 0), (3, 3))