Example #1
0
def clean_metro(metro):
    # Rename some attributes
    utility.rename_node_attribute(metro, old='Latitude', new='lat')
    utility.rename_node_attribute(metro, old='Longitude', new='lon')
    utility.rename_edge_attribute(metro, old='Time (s)', new='time_s')

    # delete extraneous attributes

    # utility.del_edge_attribute(metro, 'To')
    # utility.del_edge_attribute(metro, 'From')
    # utility.del_node_attribute(metro, 'Station')

    # compute time in minutes
    time_m = {(e[0], e[1]): metro.edge[e[0]][e[1]]['time_s'] / 60
              for e in metro.edges_iter()}

    # mark whether a given edge is a transfer edge to another metro line.
    transfer = {key: 'transfer' for key in time_m if time_m[key] == 5.0}
    nx.set_edge_attributes(metro, 'transfer', transfer)

    nx.set_edge_attributes(metro, 'free_flow_time_m', time_m)
    nx.set_edge_attributes(metro, 'uniform_time_m',
                           nx.get_edge_attributes(metro, 'free_flow_time_m'))

    # -----------------------------------------------------------
    # ZEYAD: please delete the below three lines when you update the metro data set. Replace them with whatever is necessary to appropriate set a distance attribute in kilometers.
    dists = {(e[0], e[1]): analysis.distance(
        (metro.node[e[0]]['lat'], metro.node[e[0]]['lon']),
        (metro.node[e[1]]['lat'], metro.node[e[1]]['lon']))
             for e in metro.edges_iter()}
    nx.set_edge_attributes(metro, 'dist_km', dists)
    # -----------------------------------------------------------

    # assume metro has unlimited capacity
    nx.set_edge_attributes(metro, 'capacity', 100000000000000000000000)

    # don't need time_s anymore
    utility.del_edge_attribute(metro, 'time_s')

    return metro
def clean_metro(metro):
	# Rename some attributes
	utility.rename_node_attribute(metro, old = 'Latitude', new = 'lat')
	utility.rename_node_attribute(metro, old = 'Longitude', new = 'lon')
	utility.rename_edge_attribute(metro, old = 'Time (s)', new = 'time_s')
	
	# delete extraneous attributes
	
	# utility.del_edge_attribute(metro, 'To')
	# utility.del_edge_attribute(metro, 'From')
	# utility.del_node_attribute(metro, 'Station')

	# compute time in minutes
	time_m = {(e[0], e[1]) : metro.edge[e[0]][e[1]]['time_s'] / 60 for e in metro.edges_iter()}

	# mark whether a given edge is a transfer edge to another metro line.  
	transfer = {key : 'transfer' for key in time_m if time_m[key] == 5.0}
	nx.set_edge_attributes(metro, 'transfer', transfer)

	nx.set_edge_attributes(metro, 'free_flow_time_m', time_m)
	nx.set_edge_attributes(metro, 'uniform_time_m', nx.get_edge_attributes(metro, 'free_flow_time_m'))

	# -----------------------------------------------------------
	# ZEYAD: please delete the below three lines when you update the metro data set. Replace them with whatever is necessary to appropriate set a distance attribute in kilometers. 
	dists = {(e[0], e[1]) : analysis.distance((metro.node[e[0]]['lat'],metro.node[e[0]]['lon']) , 
							  (metro.node[e[1]]['lat'],metro.node[e[1]]['lon'])) for e in metro.edges_iter()}
	nx.set_edge_attributes(metro, 'dist_km', dists)
	# -----------------------------------------------------------

	# assume metro has unlimited capacity
	nx.set_edge_attributes(metro, 'capacity', 100000000000000000000000)
	
	# don't need time_s anymore
	utility.del_edge_attribute(metro, 'time_s')
	
	return metro
Example #3
0
		def find_nearest(n, N1, N2):
			dists = {m: analysis.distance( (N1.node[n]['lon'], N1.node[n]['lat']), (N2.node[m]['lon'], N2.node[m]['lat']) ) for m in N2}
			nearest = min(dists, key=dists.get)
			nearest_dist = dists[nearest]
			return nearest, nearest_dist