def main():
    g.add_matrix(6, 6)
    print("Breadth First Search: ")
    b = bfs.bfs_path(2, 7, 29, [3, 4, 9, 16, 20, 21, 25])
    if b == "Not Found":
        print("Path not found")
    else:
        for x in b:
            print(x)

    print("Dijkstra Search: ")
    d = dijkstra.dijkstra_path(1, 7, 29, [3, 4, 9, 16, 20, 21, 25])
    if d == "Not Found":
        print("Path not found")
    else:
        for x in d:
            print(x)

    print("A* Search Algorithm: ")
    a = asearch.a_path([1, 1], 7, 29, [3, 4, 9, 16, 19, 20, 21, 25])
    if a == "Not Found":
        print("Path Not Found")
    else:
        for x in a:
            print(x)

    print("IDA* Search Algorithm: ")
    ida = idasearch.ida_path([2, 1], 7, 29, [3, 4, 9, 16, 19, 20, 21, 25])
    if ida == "Not Found":
        print("Path Not Found")
    else:
        idap = []
        for x in ida:
            idap.append(x[0])
        print(idap)
        print(ida[-1][1])

    print("Best first Search")
    bestfs = bestfirstsearch.bestfs_path([2, 1], 7, 29,
                                         [3, 4, 9, 16, 20, 21, 25])
    if bestfs == "Not Found":
        print("Path Not FOund")
    else:
        for x in bestfs:
            print(x)
Example #2
0
#             4: [],
#             3: [4]}
# grfWeight = {(1, 3): 4,
#              (1, 2): 1,
#              (2, 3): 2,
#              (2, 4): 6,
#              (3, 4): 3}
inputGrf = {}
grfWeight = {}
with open("dijkstraData.txt") as f:
    for line in f:
        str = line.split('\t')
        startNode = int(str[0])
        inputGrf[startNode] = []
        for el in str[1:-1]:
            edge = el.split(',')
            inputGrf[startNode].append(int(edge[0]))
            grfWeight[startNode, int(edge[0])] = int(edge[1])

dijkScore = dijkstra_path(inputGrf, grfWeight)
print(dijkScore[7])
print(dijkScore[37])
print(dijkScore[59])
print(dijkScore[82])
print(dijkScore[99])
print(dijkScore[115])
print(dijkScore[133])
print(dijkScore[165])
print(dijkScore[188])
print(dijkScore[197])
Example #3
0
 def get_path(self, start, end):
     """Find shortest path between stations."""
     return dijkstra_path(self.graph, start, end)
Example #4
0
directory = os.path.dirname(os.path.abspath(__file__))
directory = Path(directory).parent
DATA_PATH = f"{directory}/data/graph.graphml"

G = ox.io.load_graphml(DATA_PATH)
fig, ax = ox.plot_graph(G)

list(G.edges(data=True))

origin_point = (41.797791, -87.603978)
dest_point = (41.790958, -87.593226)

origin_node = ox.get_nearest_node(G, origin_point)
dest_node = ox.get_nearest_node(G, dest_point)

route = dijkstra_path(G, origin_node, dest_node)

long = []
lat = []
for i in route:
    point = G.nodes[i]
    long.append(point['x'])
    lat.append(point['y'])


def plot_path(lat, long, origin_point, destination_point):
    """
    Given a list of latitudes and longitudes, origin 
    and destination point, plots a path on a map
    
    Parameters
Example #5
0
from time import time
from pathtime import walktime

print "Please input your starting point"
start = raw_input()
print "Please provide your destination"
end = raw_input()
print "Please choose your algorithm: \ninput 'd' for Dijkstra's algorithm or 'b' for Bellman-Ford algorithm"
algorithm = raw_input()

source = graph.name_to_id(start.lower())
sink = graph.name_to_id(end.lower())

if algorithm == "d" or "D":
	t0 = time()
	path_id = dijkstra_path(source, sink)
	print "\n"
	for k in range(len(path_id)):
		print graph.id_to_name(path_id[k])
	print "\n"
	t1 = time()
elif algorithm == "b" or "B":
	t0 = time()
	path_id = shortest_path(source, sink)
	print "\n"
	for k in range(len(path_id)):
		print graph.id_to_name(path_id[k])
	print "\n"
	t1 = time()

print "Your algorithm ran in",t1-t0,"seconds.\nIf you were to walk, this trip would take ~",walktime(graph,path_id),"minutes.\n"