Beispiel #1
0
def test_get_neighbors_one_row_neighbor():
    node_a = astar.Node()
    node_b = astar.Node()

    neighbor_list = astar.get_neighbors([[node_a, node_b]], 0, 0)
    eq_(neighbor_list, [node_b])

    neighbor_list = astar.get_neighbors([[node_a, node_b]], 0, 1)
    eq_(neighbor_list, [node_a])
Beispiel #2
0
def test_get_neighbors_one_column_neighbor():
    node_a = astar.Node()
    node_b = astar.Node()

    neighbor_list = astar.get_neighbors([[node_a], [node_b]], 0, 0)
    eq_(neighbor_list, [node_b])

    neighbor_list = astar.get_neighbors([[node_a], [node_b]], 1, 0)
    eq_(neighbor_list, [node_a])
Beispiel #3
0
def test_get_neighbors_none_neighbor():
    node_a = astar.Node()

    neighbor_list = astar.get_neighbors([[node_a], [None]], 0, 0)
    eq_(neighbor_list, [])
Beispiel #4
0
def next():
    if len(astar.open) > 0:
        current = None
        for node in astar.open:
            if not current or astar.f[node] < astar.f[current]:
                current = node
        
        astar.current = current
        
        if astar.h[current] < astar.h[lowest] and astar.g[current] > astar.g[lowest]:
            astar.lowest = current
        
        if astar.h[current] < astar.h[cursor] or astar.g[current] > astar.g[cursor]:
            astar.cursor = current
        
        #Updates the path
        astar.test_path = []
        node = cursor
        while node:
            astar.test_path.append(node)
            node = astar.parent[node]
        
        if lowest == end:
            _stop()
            return False
        
        astar.open.remove(current)
                
        astar.closed.append(current)
        
        astar.checked_nodes = [current]
        
        for neighbor in astar.get_neighbors(current):
            update = False
            
            if neighbor not in closed:
                
                astar.checked_nodes.append(neighbor)
                
                g = astar.g[current] + g_function(current, neighbor)
                
                if neighbor in open:
                    if g < astar.g[neighbor]:
                        update = True
                else:
                    astar.open.append(neighbor)
                    update = True
            
                if update:                        
                    astar.parent[neighbor] = current
                    
                    astar.g[neighbor] = g
                    h = astar.h[neighbor] = h_function(neighbor, astar.end)
                    astar.f[neighbor] = g + h
                    
                    astar.maxg = max(astar.maxg, float(g))
                    astar.maxh = max(astar.maxh , float(h))

        #astar.open.sort(nodeCmp,reverse = True)
        
        return True
    else:
        _stop()
        return False