import numpy as np
import pandas as pd
import graph_tool.all as gt

''' Load Air-routes data in the dataframe "routes" '''
routes = pd.read_csv('routes.dat', names = ['Airline', 'Airline ID', 'Source airport', 'Source Airport ID', 'Destination airport', 'Destination airport ID', 'Codeshare', 'Stops', 'Equipment'])
routes.dropna(how = "all", inplace = True)

all_routes = routes[['Source airport', 'Destination airport']].copy()
edges = [tuple(x) for x in all_routes.values]

# Create a graph
G = gt.Graph(directed = False)
G.add_edge_list(edges, hashed = True, string_vals = True)
gt.remove_parallel_edges(G)
print(G)

# Extract the largest component as a graph
lc = gt.Graph(gt.GraphView(G, vfilt = gt.label_largest_component(G)), prune = True)
print(lc)

deg = lc.new_vertex_property("int")
for v in lc.vertices():
    deg[v] = v.out_degree()

gt.graph_draw(lc, vertex_size = deg)
