Ejemplo n.º 1
0
def search_route(from_id, to_id):
    c = client.graph(host, port)

    pq = types.preset_query([], [])
    spreq = types.shortest_path_req(from_id, to_id, 100, pq)
    stations = c.shortest_path(instance_name, spreq)

    print "Pseudo-Shortest Path (hops) from %s to %s:" % (from_id, to_id)
    for station in stations:
        node = c.get_node(instance_name, station)
        station_name = ''
        if 'name' in node.p:
            station_name = node.p['name']
        print "  %s\t%s" % (station, station_name)
Ejemplo n.º 2
0
def search_route(from_id, to_id):
    c = client.graph(host, port)

    pq = types.preset_query([], [])
    spreq = types.shortest_path_req(from_id, to_id, 100, pq)
    stations = c.shortest_path(instance_name, spreq)

    print "Pseudo-Shortest Path (hops) from %s to %s:" % (from_id, to_id)
    for station in stations:
        node = c.get_node(instance_name, station)
        station_name = ""
        if "name" in node.p:
            station_name = node.p["name"]
        print "  %s\t%s" % (station, station_name)
Ejemplo n.º 3
0
    if name in stations:
        node_id = stations[name]
    else:
        node_id = c.create_node(instance_name)
        c.update_node(instance_name, node_id, {'name': name})
        stations[name] = node_id
    return node_id


def print_stations():
    for station in sorted(stations.keys(), key=lambda k: int(stations[k])):
        print "%s\t%s" % (stations[station], station)


if __name__ == '__main__':
    # Create jubagraph client.
    c = client.graph(host, port)

    # Prepare query.
    pq = types.preset_query([], [])
    c.add_shortest_path_query(instance_name, pq)

    # Register stations in each line.
    # Do not add too much lines to prevent causing heavy load to the API server.
    create_graph(c, get_station_join(11302))  # 山手線
    create_graph(c, get_station_join(11312))  # 中央線

    # Print station IDs; you need the ID to search route.
    print "=== Station IDs ==="
    print_stations()
Ejemplo n.º 4
0
def add_station(c, name):
    if name in stations:
        node_id = stations[name]
    else:
        node_id = c.create_node(instance_name)
        c.update_node(instance_name, node_id, {'name': name})
        stations[name] = node_id
    return node_id

def print_stations():
    for station in sorted(stations.keys(), key=lambda k: int(stations[k])):
        print "%s\t%s" % (stations[station], station)

if __name__ == '__main__':
    # Create jubagraph client.
    c = client.graph(host, port)

    # Prepare query.
    pq = types.preset_query([], [])
    c.add_shortest_path_query(instance_name, pq)

    # Register stations in each line.
    # Do not add too much lines to prevent causing heavy load to the API server.
    create_graph(c, get_station_join(11302)) # 山手線
    create_graph(c, get_station_join(11312)) # 中央線

    # Print station IDs; you need the ID to search route.
    print "=== Station IDs ==="
    print_stations()