示例#1
0
def main():
    streets_in_grid = ["SACRAMENTO ST", "BAKER ST", "SUTTER ST", "STEINER ST", "PERINE PL", "WILMOT ST", "BRODERICK ST", "DIVISADERO ST", "SCOTT ST", "PIERCE ST", "CALIFORNIA ST", "PINE ST", "BUSH ST"]
    int_dic = loadIntersections(toPrint=False)
    ints_in_grid = {}
    #if both streets for intersection are in grid, add the intersection to ints_in_grid
    for key in int_dic.keys():
        if int_dic[key].get_streets()[0] in streets_in_grid and int_dic[key].get_streets()[1] in streets_in_grid:
            ints_in_grid[key] = int_dic[key]
            
#     for key in ints_in_grid.keys():
#         print(key, "\n", ints_in_grid[key])
    makeIntersectionJSAA(ints_in_grid)
示例#2
0
def main():
    intersection_dict = loadIntersections()
    street_dict = load_streets()
    
    #create a dict of SF_intersections from intersection_dict
    sf_intersections = {}

    for key in intersection_dict.keys():
        intersection = intersection_dict[key]
        sf_intersections[key] = (SF_intersection(intersection.get_cnn(), intersection.get_streets(), intersection.get_loc(), intersection.get_elev()))
        
    print(len(sf_intersections))
    #create a list of streets from street_dict   
    sf_streets = []
    for key in street_dict.keys():
        street = street_dict[key]
        if street.get_start() == street.get_end():
            #Ramsel Ct loops around on itself with no intersections and should be excluded from the graph
            #exclude this case and any like it
            continue
        sf_streets.append(SF_street(sf_intersections[street.get_start()], sf_intersections[street.get_end()], street.get_streetname()))
        
    print(len(sf_streets))

    graph = SF_graph()
    
    for key in sf_intersections.keys():
        graph.add_node(sf_intersections[key])
        
#     print(len(graph.nodes))
    
    for edge in sf_streets:
#         print(type(edge))
#         print(type(edge.get_source()))
#         print(edge.get_source() in graph.nodes)
#         print(graph.nodes)
        graph.add_edge(edge)
#         except(ValueError):
#             pass
        
    sf_graph_out = open("sf_graph.pickle", "wb")
    pickle.dump(graph, sf_graph_out)
示例#3
0
def makeStreetsCSV(intersection_file = "fixed_intersections.csv", street_segments_file = "street_segments.csv", streets_file = "new_streets.csv"):
    int_dict = loadIntersections(intersection_file)
    street_segments = open(street_segments_file, "r")
    streets = open(streets_file, "w")
    nodes = int_dict.keys()
    dic = {} #dict of cnn -> street
    repeatedStreets = 0
    streetMissingEnds = 0

    for line in street_segments:
        line = line.split(",")
        #skip first line
        if line[0] == "CNN": continue
        cnn = line[0]
        streetname = line[1]
        start = line[-2]
        end = line[-1][:-1]
        #dont repeat streets
        if cnn in dic.keys():
            repeatedStreets += 1
            continue
        #make sure both ends exist (a few or missing)
        if start in nodes and end in nodes:
            street = Street(cnn, streetname, start, end)
            dic[cnn] = street
        else:
            streetMissingEnds += 1
            
        
    print("# of repeated streets: {}\n# of streets missing ends: {}".format(repeatedStreets, streetMissingEnds))
    
    street_segments.close()
    
    for key in sorted(dic.keys()):
        streets.write("{}\n".format(dic[key].getCSVLine()))
        
    streets.close()
示例#4
0
def main():
    sys.setrecursionlimit(100000)
    #     print(sys.getrecursionlimit())
    gragh_pickle_in = open("sf_graph.pickle", "rb")
    graph = pickle.load(gragh_pickle_in)
    print(len(graph.nodes))
    twenty1_folsom = "24079000"
    twenty2_folsom = "24077000"
    int_list = loadIntersections()
    int1 = int_list[twenty1_folsom]
    int2 = int_list[twenty2_folsom]
    node1 = SF_intersection(int1.get_cnn(), int1.get_streets(), int1.get_loc(), int1.get_elev())
    node2 = SF_intersection(int2.get_cnn(), int2.get_streets(), int2.get_loc(), int2.get_elev())
    edge = graph.get_edge(node1, node2)
    print(edge.get_streetname())
    print(edge.get_length())
    print(edge.get_work())
    print(edge.get_source().get_streets())
    print(edge.get_destination().get_streets())
    for n in graph.children_of(node1):
        print(n)
    shortest_path = search(graph, node1, node2, toPrint=True)
    print(shortest_path)
    shortest_path = makePathFromDijk(graph, shortest_path)
    print(shortest_path)
    #     for node_str in shortest_path.get_node_list():
    #         print("{}  \n===\n||\n\\/\n".format(int_list[str(node_str)].get_streets()))
    #
    print(shortest_path.get_weight())
    print(shortest_path.get_length())
    print("------correct answer-------")
    ans = SF_street(node1, node2, "folsom")
    #     print(ans.get_elev_change())
    print(ans.get_work())
    print(ans.get_length())

    print("Arrived")
示例#5
0
    def get_edges(self):
        """
        returns the dict of edges
        """
        return self.edges
    
    def get_nodes(self):
        return self.nodes
    

            

if __name__ == '__main__':
    from intersection import loadIntersections
    from street import load_streets
    ints = loadIntersections()
    streets = load_streets()
    
    twenty1_folsom = "24079000"
    twenty2_folsom = "24077000"
    shotwell_21 = "24080000"
    shotwell_22 = "24078000"
    twenty1 = "1105000"
    twenty2 = "1187000"
    shotwell = "11839000"
    folsom = "5696000"
    intList = [twenty1_folsom, twenty2_folsom, shotwell_21, shotwell_22]
    streetList = [folsom, shotwell, twenty1, twenty2]
    graph = SF_graph()
    for node in intList:
        node = ints[node]
#!/usr/bin/python3.4
from intersection import loadIntersections

if __name__ == '__main__':
    dic = loadIntersections()
    fout = open("sorted_ints.csv", "w")
    for key in sorted(dic.keys()):
        fout.write(dic[key].getCSVLine())
    fout.close()
示例#7
0
def main(start = None, end = None):
    #list of strings containing every street with an
    #intersection in the grid 
    exp_node_num = 31
    exp_edge_num = 47
    streets_in_grid = ["SACRAMENTO ST", "BAKER ST", "SUTTER ST", "STEINER ST", "PERINE PL", "WILMOT ST", "BRODERICK ST", "DIVISADERO ST", "SCOTT ST", "PIERCE ST", "CALIFORNIA ST", "PINE ST", "BUSH ST"]
    int_dic = loadIntersections(toPrint=False)
    ints_in_grid = {}
    #if both streets for intersection are in grid, add the intersection to ints_in_grid
    for key in int_dic.keys():
        if int_dic[key].get_streets()[0] in streets_in_grid and int_dic[key].get_streets()[1] in streets_in_grid:
            ints_in_grid[key] = int_dic[key]
    
    # for key in ints_in_grid.keys():
    #     print(ints_in_grid[key].get_streets())
        
    # print(len(ints_in_grid))
    
    #get every street where start int and end int are in test Grid
    all_streets = load_streets(toPrint=False)
    streets_in_grid = {}
    for key in all_streets.keys():
        if all_streets[key].get_start() in ints_in_grid.keys() and all_streets[key].get_end() in ints_in_grid.keys():
            streets_in_grid[key] = all_streets[key]
    
#     for key in streets_in_grid.keys():
#         sne = streets_in_grid[key].get_start_name_end()
#         print("{}->{}->{}".format(ints_in_grid[sne[0]].get_streets(), sne[1], ints_in_grid[sne[2]].get_streets()))
#     print(len(streets_in_grid))
    digraph = build_graph(ints_in_grid, streets_in_grid)
#     print("Args: {}".format(sys.argv))
#     print("Arg length: {}".format(len(sys.argv)))
    if len(sys.argv) == 3:
        if sys.argv[1] in ints_in_grid.keys() and sys.argv[2] in ints_in_grid.keys():
            start = sys.argv[1]
            end = sys.argv[2]
        else:
            print("invalid start or end node")
            assert False
    else:
        start = random.choice(list(ints_in_grid.keys()))
        end = random.choice(list(ints_in_grid.keys()))
        while end == start:
            end = random.choice(list(ints_in_grid.keys()))
    start_int = ints_in_grid[start]
    end_int = ints_in_grid[end]
    start_node= SF_intersection(start_int.get_cnn(), start_int.get_streets(), start_int.get_loc(), start_int.get_elev())
    end_node= SF_intersection(end_int.get_cnn(), end_int.get_streets(), end_int.get_loc(), end_int.get_elev())
    bf_path = search(digraph, start_node, end_node)
    print("start:{} - {}".format(start_int.get_streets(), start_int.get_cnn()))
    print("end:{} - {}".format(end_int.get_streets(), end_int.get_cnn()))
    print("brute force: " + str(bf_path))
    print(bf_path.get_weight())
    print()
    dp_path = dsearch(digraph, start_node, end_node)
    print()
    print("dynamic p:   " + str(dp_path))
    print(dp_path.get_node_list())
    print(dp_path.get_weight())
    print("\nDystra:")
    dpath = dijkstra_search(digraph, start_node, end_node, toPrint=False)
    dyspath = makePathFromDijk(digraph, dpath)
    print(dyspath)
    print(dpath)
    print(dyspath.get_weight())