def simple_scenario_ipynb(): place_name = 'Greece' cf = '["highway"~"motorway|motorway_link|trunk|secondary|primary"]' net_type = 'drive' graph = net_ops.get_network_graph(place_name, net_type, cf) nodes, edges = net_ops.get_nodes_edges(graph) scenario_two_paths(graph, edges, 3744263637, 300972555, 295512257, 1604968703, 'traffic', 'loaded_edges.csv')
def main(): # declare all variables (may be input vars later) POIs_fpath = 'data/attica-supermarket.geojson' graph_fpath = 'data/attica_graph.graphml' algorithm = '' # read points of interest (data) point_coords_list = create_pois_df(POIs_fpath) graph = net_ops.load_graph_from_disk(graph_fpath) assigned_nodes_list = assign_points_to_nodes(point_coords_list, graph) nodes, edges = net_ops.get_nodes_edges(graph) update_graph_nodes_with_POIs(nodes, assigned_nodes_list) pdb.set_trace()
def run_tavros_scenario(): super_graph = get_athens_local_networks_scenario( '../data/dimoi_athinas.csv', '../results/graphs/', 'Tavros', 3744263637, 8067989857) custom_dijkstra('../results/supergraph.graphml', '../results/', 3744263637, 8067989857) plot_route_in_graph(super_graph, 3744263637, 8067989857) #babis nodes, edges = net_ops.get_nodes_edges(super_graph) net_ops.write_nodes_edges_to_disk(nodes, edges, 'supergraph', '../results/')
def custom_dijkstra_all_vs_all(src_graph_fp, csv_src_fp, results_csv_fpath, node): # read the csv file and get the list of nodes df = pandas.read_csv(csv_src_fp, sep=';') nodes_list = df[node].to_list() combo_list = net_ops.get_all_list_combinations(nodes_list) graph = net_ops.load_graph_from_disk(src_graph_fp) nodes, edges = net_ops.get_nodes_edges(graph) # get edges of network in appropriate form for custom dijkstra dijkstra_edges = min_ops.create_dijkstra_edge_list(edges, nodes) #TODO here we are custom_dijkstra_all_nodes_vs_all(combo_list, graph, edges, 'traffic', dijkstra_edges, results_csv_fpath)
def flora(src_graph_fp, csv_src_fp, results_csv_fpath, new_col='traffic'): # get the graph from disk graph = net_ops.load_graph_from_disk(src_graph_fp) nodes, edges = net_ops.get_nodes_edges(graph) # read the points of interest to df pois_df = io_ops.convert_csv_to_nodes(csv_src_fp) poi_nodes = assign_POIs_to_graph(graph, pois_df) # assign new fields and values to nodes of the network enhance_network_nodes_with_field(nodes, poi_nodes, new_field='supermarkets', field_name='AB') # create distance matrix data, dist_matrix_nodes_dict = create_distance_matrix(graph, poi_nodes) return data
def custom_dijkstra(src_graph_fp, results_folder, origin_node, dest_node): graph = net_ops.load_graph_from_disk(src_graph_fp) nodes, edges = net_ops.get_nodes_edges(graph) dijkstra_edges = min_ops.create_dijkstra_edge_list(edges, nodes) dijkstra_path = dijkstra.dijkstra(dijkstra_edges, origin_node, dest_node) dist, dijkstra_node_list = min_ops.refine_dijkstra_results(dijkstra_path) dijkstra_nodes_df = min_ops.get_dijkstra_matching_df(nodes, dijkstra_node_list, id='osmid') # write results to files dijkstra_edges_df = min_ops.get_dijkstra_matching_df(edges, dijkstra_node_list, id='u') write_results_to_disk(results_folder, origin_node, dest_node, dijkstra_nodes_df, dijkstra_edges_df)
def supermarkets_vrp_google_scenario(athens_network_path, supermarkets_path, results_path): # load athens network path and get nodes and edges graph = net_ops.load_graph_from_disk(athens_network_path) # get and update athens nodes with supermarket field nodes, edges = net_ops.get_nodes_edges(graph) nodes['supermarket'] = 'None' # load supermarkets path supermarkets = gpd.read_file(supermarkets_path) # project supermarkets nodes in athens network ###### HERE works net_sm_nodes = net_ops.get_matched_node_ids(supermarkets, graph) net_nodes = net_ops.populate_net_nodes_with_sm_nodes( graph, nodes, supermarkets) sm_nodes = net_nodes[net_nodes['supermarket_id'] != 0] #sm_nodes = sm_nodes[1:60] dist_matrix = net_ops.create_adj_matrix_of_supermarkets(sm_nodes, graph) return dist_matrix
def k_best_scenario(src_graph_fp, results_csv_fpath, node, k_nodes=[]): """ Method to run a k-best scenario with mandatory "passing" through every one of the k_nodes. If no k_nodes list is given then a simple dijkstra is executed (k=1). :param: """ # load network graph = net_ops.load_graph_from_disk(src_graph_fp) nodes, edges = net_ops.get_nodes_edges(graph) dijkstra_edges = min_ops.create_dijkstra_edge_list(edges, nodes) # initialize the k_best parameters k_res = [] k_nodes = [3744263637, 300972555, 295512257, 1604968703] min_ops.k_best(dijkstra_edges, k_nodes, '', '', k_res) dist, k_best_list = min_ops.refine_k_best_results(k_res) pdb.set_trace()
def scenario_all_in_all(src_graph_fp, csv_src_fp, results_csv_fpath, node): # read the csv file and get the list of nodes df = pandas.read_csv(csv_src_fp, sep=';') nodes_list = df[node].to_list() combo_list = net_ops.get_all_list_combinations(nodes_list) # get the network graph #cf = '["highway"~"motorway|motorway_link|trunk|secondary|primary"]' #graph = net_ops.get_network_graph('Greece', 'drive', cf) graph = net_ops.load_graph_from_disk(src_graph_fp) nodes, edges = net_ops.get_nodes_edges(graph) scenario_all_nodes_with_all(combo_list, graph, edges, 'traffic', results_csv_fpath) write_traffic_edges_to_csv(edges, results_csv_fpath, new_col='traffic', threshold=0.1)
def od_viewer_to_map(csv_file, graph_file, lonlat_centres_file): """Method to view data of an OD-Matrix to a map. Args: csv_file ([type]): [description] graph_file ([type]): [description] """ # load graph and data with loads for cities from csv_file df = read_data_from_file(csv_file, ',') net_graph = net_ops.load_graph_from_disk(graph_file) nodes, edges = net_ops.get_nodes_edges(net_graph) # assign cities to graph nodes reg_units_df = read_data_from_file(lonlat_centres_file, ',') node_id_list = _assign_net_node_to_reg_unit(reg_units_df, net_graph) # replace names of regional units with node ids. df = _replace_od_columns_with_node_ids(df, reg_units_df) # compute min path between cities in the network #nodes_pairs_list = create_nodes_pairs(node_id_list) nodes_pairs_list = extract_node_pairs_from_od(df) # load edges of network with the corresponding loads _update_edges_with_loads(net_graph, edges, nodes_pairs_list) # return loaded edges edges.to_csv('~/Downloads/updated_edges.csv')
def tatiana_scenario(src_graph_fp, csv_src_fp, results_csv_fpath, new_col='traffic'): # get the graph from disk graph = net_ops.load_graph_from_disk(src_graph_fp) nodes, edges = net_ops.get_nodes_edges(graph) # read the csv file (form: n1, n2, n3, ...n) # create pairs from csv file pairs = io_ops.get_u_v_pairs_from_file(csv_src_fp) # compute minimum paths and update traffic net_ops.add_new_column_to_dataframe(edges, new_col) for pair in pairs: u, v, traffic = pair if u is not v: update_edges_list_with_min_path_traffic(graph, edges, u, v, new_col, traffic) pdb.set_trace() #net_ops.add_u_v_coords_to_edges(nodes, edges) write_traffic_edges_to_csv(edges, results_csv_fpath, new_col, threshold=0.1) pdb.set_trace()