Ejemplo n.º 1
0
def get_astar_rout(source, target):
    idx_rout = []
    map = load_map_from_csv()
    rout = astar_get_rout.get_rout(source, target, map)
    for node in rout:
        idx_rout.append(node.index)
    return idx_rout
Ejemplo n.º 2
0
def write_results_to_file(results_file, problems_file, algorithem, map):
    nodes = map.junctions()
    w = open(results_file, "w")
    r = open(problems_file, "r")
    read_lines = r.readlines()
    lines = [x.strip() for x in read_lines]
    for line in lines:
        split = line.split(",")
        source = int(split[0])
        target = int(split[1])
        if algorithem == "ucs":
            rout = ucs_get_rout.get_rout(source, target, map)
            time = calculate_time_of_rout(rout)
            w.write(str(time) + "\n")
        elif algorithem == "astar":
            rout = astar_get_rout.get_rout(source, target, map)
            time = calculate_time_of_rout(rout)
            h_time = H(nodes[source], nodes[target])
            w.write(str(h_time) + "," + str(time) + "\n")
        else:
            rout = idastar_get_rout.get_rout(source, target, map)
            time = calculate_time_of_rout(rout)
            h_time = H(nodes[source], nodes[target])
            w.write(str(h_time) + "," + str(time) + "\n")
    w.close()
    r.close()
Ejemplo n.º 3
0
def testpaths(map):
    juncs = map.junctions()
    #problems.create_problems("db/problems.csv")
    # problems.write_results_to_file("results/UCSRuns.txt", "db/problems.csv",
    #                                "ucs", map)
    # problems.write_results_to_file("results/AStarRuns.txt", "db/problems.csv",
    #                                "astar", map)
    # problems.write_results_to_file("results/IDAStarRuns.txt", "db/problems.csv",
    #                                "idstar", map)

    # ucs_time = problems.get_run_times(map, "db/problems.csv", "ucs")
    # print(ucs_time)
    # astar_time = problems.get_run_times(map, "db/problems.csv", "astar")
    # print(astar_time)
    # ida_time = problems.get_run_times(map, "db/problems.csv", "ida_time")
    # print(ida_time)
    #problems.draw_times_graph("results/AStarRuns.txt")

    with open("db/problems.csv") as f:
        content = f.readlines()
    content = [x.strip() for x in content]
    for c in content:
        c.split(",")
        v = c.split(',')
        start = int(v[0])
        end = int(v[1])
        print(" ")
        print(str(start) + "," + str(end))
        path = astar_get_rout.get_rout(start, end, map)
        cost = calculate_time_of_rout(path)
        h_cost = H(juncs[start], juncs[end])
        print(cost)
        print(h_cost)
        if (cost < h_cost):
            print("problem")

        # pp = []
        # for p in path:
        #     pp.append(p.index)
        # cost = find_time(map.junctions(),pp)

        # path = ucs_rout.get_rout_with_map_dict(start, end, map)
        if path_is_illegal(path, map, end):
            print("Bye")
            break
        index_path = []
        for node in path:
            index_path.append(node.index)

        plot_path(
            juncs,
            index_path,
        )

        print(' '.join(str(j) for j in index_path))
        print(len(path))
Ejemplo n.º 4
0
def get_run_times(map, problems_file, algorithem):
    total_time = 0
    r = open(problems_file, "r")
    read_lines = r.readlines()
    lines = [x.strip() for x in read_lines]
    for line in lines:
        split = line.split(",")
        source = int(split[0])
        target = int(split[1])
        time_start = time.time()
        if algorithem == "ucs":
            ucs_get_rout.get_rout(source, target, map)
        elif algorithem == "astar":
            astar_get_rout.get_rout(source, target, map)
        else:
            idastar_get_rout.get_rout(source, target, map)
        time_end = time.time()
        total_time += time_end - time_start
    return total_time / 100