示例#1
0
def get_idastar_rout(source, target):
    idx_rout = []
    map = load_map_from_csv()
    rout = idastar_get_rout.get_rout(source, target, map)
    for node in rout:
        idx_rout.append(node.index)
    return idx_rout
示例#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()
示例#3
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