示例#1
0
def route_direct(file_name,
                 source_id=None,
                 target_id=None,
                 out_file=None,
                 overpass_url=None,
                 disk_cache=False,
                 visualize=False):
    from limic.util import start, end, status, file_size, load_pickled, save_pickled, save_path, options, replace
    if disk_cache:
        start("Using disk cache", file_name)
        set_option('disk_cache', file_name)
    from limic.overpass import region, set_server
    if disk_cache:
        status("OK")
    from os.path import exists
    if not disk_cache and exists(file_name):
        start("Loading", file_name)
        region.backend._cache = load_pickled(file_name)
        end('')
        file_size(file_name)
    len_cache = len(region.backend._cache)
    start("Routing using direct algorithm")
    set_server(overpass_url)
    path = astar_direct(source_id, target_id)
    end()
    start("Saving path to", out_file)
    save_path(path, out_file, visualize)
    end()
    if not disk_cache and len_cache != len(region.backend._cache):
        file_name_tmp = file_name + ".tmp"
        start("Saving to", file_name, "via", file_name_tmp)
        save_pickled(file_name_tmp, region.backend._cache)
        replace(file_name_tmp, file_name)
        end('')
        file_size(file_name)
示例#2
0
def route_gt(file_name,
             source_id=None,
             target_id=None,
             out_file=None,
             indirect=False,
             penalize=20,
             visualize=False):
    from limic.util import start, end, status, load_gt, save_path
    from limic.convert import transform_gt_npz
    start("Loading graph from", file_name)
    g = load_gt(file_name)
    end()
    start("Checking whether GT graph is rescaled")
    if g.gp.rescaled:
        indirect = True
        status("YES (forcing routing through NPZ)")
    else:
        status("NO")
    if indirect:
        start("Transforming graph to NPZ format")
        h = transform_gt_npz(g, penalize)
        end()
        start("Routing using NPZ")
        path = astar_npz(h, source_id, target_id)
        end()
    else:
        start("Routing using GT")
        path = astar_gt(g, source_id, target_id)
        end()
    start("Saving path to", out_file)
    save_path(path, out_file, visualize)
    end()
示例#3
0
def route_cnx(file_name,
              source_id=None,
              target_id=None,
              out_file=None,
              visualize=False,
              benchmark=None):
    from limic.util import start, end, load_pickled, save_path, save_pickled
    start("Loading from", file_name)
    g = load_pickled(file_name)
    end()
    start("Routing using condensed NX")
    if benchmark and out_file:
        routes = []
        for i in range(int(benchmark)):
            path = astar_cnx(g, None, None, routes)
    elif benchmark:
        for source, target in load_pickled(benchmark):
            path = astar_cnx(g, (source, ), (target, ))
    else:
        path = astar_cnx(g, source_id, target_id)
    end()
    if benchmark and out_file:
        start("Saving routes to", out_file)
        save_pickled(out_file, routes)
        end()
    elif not benchmark:
        start("Saving path to", out_file)
        save_path(path, out_file, visualize)
        end()
示例#4
0
def route_npz(file_name,
              source_id=None,
              target_id=None,
              out_file=None,
              indirect=False,
              penalize=20,
              visualize=False):
    from limic.util import start, end, status, save_path, load_npz
    from limic.convert import transform_npz_nx
    from numpy import int32
    start("Loading from", file_name)
    g = load_npz(file_name)
    end()
    start("Checking whether GT graph is rescaled")
    if g['edges_weight'].dtype == int32:
        indirect = True
        status("YES (forcing routing through NX)")
    else:
        status("NO")
    if indirect:
        start("Transforming graph to NX format")
        h = transform_npz_nx(g, penalize)
        end()
        start("Routing using NX")
        path = astar_nx(h, source_id, target_id)
        end()
    else:
        start("Routing using NPZ")
        path = astar_npz(g, source_id, target_id)
        end()
    start("Saving path to", out_file)
    save_path(path, out_file, visualize)
    end()
示例#5
0
def route_nx(file_name,
             source_id=None,
             target_id=None,
             out_file=None,
             visualize=False,
             benchmark=None):
    from limic.util import start, end, load_pickled, save_path
    start("Loading from", file_name)
    g = load_pickled(file_name)
    end()
    start("Routing using NX")
    if benchmark:
        for source, target in load_pickled(benchmark):
            path = astar_nx(g, (source, ), (target, ))
    else:
        path = astar_nx(g, source_id, target_id)
    end()
    if not benchmark:
        start("Saving path to", out_file)
        save_path(path, out_file, visualize)
        end()