def __main_(): ''' graph = {'A': ["C"], 'B': ['C','A'], 'C':[]} ''' #graph=graph_parse.read_ham_graph("instance_test_3nodes.lp") graph=graph_parse.read_ham_graph(sys.argv[1]) #print graph avedepth=dfs(graph,"1")
def __main__(): ''' graph = {'A': ["C"], 'B': ['C','A'], 'C':[]} ''' #graph=graph_parse.read_ham_graph("instance_test_3nodes.lp") graph = graph_parse.read_ham_graph(sys.argv[1]) #print graph dfs_1st_back_depth, sum_of_choices_along_path = dfs(graph, "1")
def __main__(): ''' graph = {'A': ["C"], 'B': ['C','A'], 'C':[]} ''' #graph=graph_parse.read_ham_graph("instance_test_3nodes.lp") graph = graph_parse.read_ham_graph(sys.argv[1]) #print graph print "result: one_path:" back_depth = dfs(graph, "1")
def __main__(): #graph=graph_parse.read_ham_graph("instance_test_3nodes.lp") graph = graph_parse.read_ham_graph(sys.argv[1]) #print graph print "get_num_of_nodes(graph),get_num_of_edges(graph),get_ratio_node_edge(graph)" print get_num_of_nodes(graph), get_num_of_edges( graph), get_ratio_node_edge(graph) #------------------------ reverse_graph = reverse(graph) #print reverse_graph print "get_num_of_nodes(reverse_graph),get_num_of_edges(reverse_graph),get_ratio_node_edge(reverse_graph)" print get_num_of_nodes(reverse_graph), get_num_of_edges( reverse_graph), get_ratio_node_edge(reverse_graph) print "bi_edge:", get_num_of_edges(get_bi_edge(graph)) print "min_out_degree:", get_min_out_degree( graph), "max_out_degree:", get_max_out_degree( graph), "avg_out_degree:", get_avg_out_degree(graph) print "min_in_degree:", get_min_out_degree( reverse_graph), "max_in_degree:", get_max_out_degree( reverse_graph), "avg_in_degree:", get_avg_out_degree(reverse_graph) print "number of odd out degree", get_odd_out_degree( graph), "number of even out degree", get_even_out_degree( graph ), "ratio of odd out degree", get_odd_out_degree(graph) / float( len(graph.keys()) ), "ratio of even out degree", get_even_out_degree(graph) / float( len(graph.keys())) print "number of odd in degree", get_odd_out_degree( reverse_graph), "number of even in degree", get_even_out_degree( reverse_graph), "ratio of odd out degree", get_odd_out_degree( reverse_graph) / float(len(reverse_graph.keys( ))), "ratio of even out degree", get_even_out_degree( reverse_graph) / float(len(reverse_graph.keys())) print "out_degree_less_than_3:", get_out_degree_less_than_3( graph), "ratio", get_out_degree_less_than_3(graph) / float( len(graph.keys())) print "in_degree_less_than_3:", get_out_degree_less_than_3( reverse_graph), "ratio", get_out_degree_less_than_3( reverse_graph) / float(len(reverse_graph.keys())) print "degree_less_than_3:", get_degree_less_than_3( graph), "ratio", get_degree_less_than_3(graph) / float( len(graph.keys()))
f.write(",") f.write(str(round(i, 4))) if m[1] == 1: f.write("\n") else: #new line with open("feature.csv", "a") as f: for i in m[2:-1]: f.write(str(round(i, 4))) f.write(",") f.write(str(round(m[-1], 4))) if m[1] == 1: f.write("\n") graph = graph_parse.read_ham_graph(sys.argv[1]) reverse_graph = node_edge.reverse(graph) #num_of_nodes,num_of_edges,ratio_node_edge,bi_edge,ratio_bi_edge,min_out_degree,max_out_degree,avg_out_degree,min_in_degree,max_in_degree,avg_in_degree,num_of_odd_out_degree,ratio_of_odd_out_degree,num_of_even_out_degree,ratio_of_even_out_degree,num_of_odd_in_degree,ratio_of_odd_in_degree,num_of_even_in_degree,ratio_of_even_in_degree,num_of_odd_degree,ratio_of_odd_degree,num_of_even_degree,ratio_of_even_degree,out_degree_less_than_3,ratio_out_degree_less_than_3,in_degree_less_than_3,ratio_in_degree_less_than_3,degree_less_than_3,ratio_degree_less_than_3 #features: #num_of_nodes,num_of_edges,ratio_node_edge num_of_nodes = node_edge.get_num_of_nodes(graph) num_of_edges = node_edge.get_num_of_edges(graph) ratio_node_edge = node_edge.get_ratio_node_edge(graph) write_to_file(0, 0, num_of_nodes, num_of_edges, ratio_node_edge) #bi_edge,ratio_bi_edge bi_edge = node_edge.get_num_of_edges(node_edge.get_bi_edge(graph)) ratio_bi_edge = bi_edge / float(num_of_edges)
def __main__(): #G={1:[2,4],2:[1,3],3:[1,2],4:[1]} graph=graph_parse.read_ham_graph(sys.argv[1]) #print graph min_depth,max_depth,avg_depth=bfs_edges(graph, "1")