int main () { struct digraph *G = new_digraph (5); struct digraph *tc_G; /* make a funny digraph */ insert_edge (G, 0, 1); insert_edge (G, 1, 2); //insert_edge (G, 2, 3); insert_edge (G, 3, 4); insert_edge (G, 4, 0); /* is the digraph connected? */ if (is_connected (G)) printf ("connected!\n"); else printf ("not connected!\n"); /* print the adjacency matrix */ printf ("adjacency matrix for G:\n"); print_adj_matrix (G); /* find the transitive closure */ tc_G = Warshall (G); /* print the adjacency matrix for the transitive closure */ printf ("adjacency matrix for transitive closure of G:\n"); print_adj_matrix (tc_G); //return 0; /* make a funny DAG */ struct digraph *H = new_digraph (7); insert_edge (H, 3, 4); insert_edge (H, 4, 2); insert_edge (H, 3, 5); insert_edge (H, 5, 2); insert_edge (H, 2, 6); insert_edge (H, 5, 3); insert_edge (H, 6, 1); insert_edge (H, 6, 0); printf ("adjacency matrix for H:\n"); print_adj_matrix (H); if (is_connected (H)) printf ("connected!\n"); else printf ("not connected!\n"); topological_sort (H, 3); //return 0; struct digraph *tc_H = Warshall (H); printf ("transitive closure of H is:\n"); print_adj_matrix (tc_H); return 0; }
int route_calculate(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) { if(flags == CCN_SCHEDULE_CANCEL) { return -1; } nlsr_lock(); if ( nlsr->debugging ) printf("route_calculate called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"route_calculate called\n"); if( ! nlsr->is_build_adj_lsa_sheduled ) { /* Calculate Route here */ print_routing_table(); print_npt(); //struct hashtb_param param_me = {0}; nlsr->map = hashtb_create(sizeof(struct map_entry), NULL); nlsr->rev_map = hashtb_create(sizeof(struct map_entry), NULL); make_map(); assign_mapping_number(); print_map(); print_rev_map(); do_old_routing_table_updates(); clear_old_routing_table(); print_routing_table(); print_npt(); int i; int **adj_matrix; int map_element=hashtb_n(nlsr->map); adj_matrix=malloc(map_element * sizeof(int *)); for(i = 0; i < map_element; i++) { adj_matrix[i] = malloc(map_element * sizeof(int)); } make_adj_matrix(adj_matrix,map_element); if ( nlsr->debugging ) print_adj_matrix(adj_matrix,map_element); long int source=get_mapping_no(nlsr->router_name); int num_link=get_no_link_from_adj_matrix(adj_matrix, map_element ,source); if ( nlsr->is_hyperbolic_calc == 1) { long int *links=(long int *)malloc(num_link*sizeof(long int)); long int *link_costs=(long int *)malloc(num_link*sizeof(long int)); get_links_from_adj_matrix(adj_matrix, map_element , links, link_costs, source); struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ for (hashtb_start(nlsr->rev_map, e); e->key != NULL; hashtb_next(e)) { struct map_entry *me=e->data; if ( me->mapping != source ) { long int *faces=(long int *)calloc(num_link,sizeof(long int)); double *nbr_dist=(double *)calloc(num_link,sizeof(double)); double *nbr_to_dest=(double *)calloc(num_link,sizeof(double)); for ( i=0 ; i < num_link; i++) { int face=get_next_hop_face_from_adl(get_router_from_rev_map(links[i])); double dist_to_nbr=get_hyperbolic_distance(source,links[i]); double dist_to_dest_from_nbr=get_hyperbolic_distance(links[i],me->mapping); faces[i]=face; nbr_dist[i]=dist_to_nbr; nbr_to_dest[i]= dist_to_dest_from_nbr; } sort_hyperbolic_route(nbr_to_dest,nbr_dist, faces,0,num_link); if (nlsr->max_faces_per_prefix == 0 ) { for ( i=0 ; i < num_link; i++) { update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); } } else if ( nlsr->max_faces_per_prefix > 0 ) { if ( num_link <= nlsr->max_faces_per_prefix ) { for ( i=0 ; i < num_link; i++) { update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); } } else if (num_link > nlsr->max_faces_per_prefix) { for ( i=0 ; i < nlsr->max_faces_per_prefix; i++) { update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); } } } free(faces); free(nbr_dist); free(nbr_to_dest); } } hashtb_end(e); free(links); free(link_costs); } else if (nlsr->is_hyperbolic_calc == 0 ) { long int *parent=(long int *)malloc(map_element * sizeof(long int)); long int *dist=(long int *)malloc(map_element * sizeof(long int)); if ( (num_link == 0) || (nlsr->max_faces_per_prefix == 1 ) ) { calculate_path(adj_matrix,parent,dist, map_element, source); print_all_path_from_source(parent,source); print_all_next_hop(parent,source); update_routing_table_with_new_route(parent, dist,source); } else if ( (num_link != 0) && (nlsr->max_faces_per_prefix == 0 || nlsr->max_faces_per_prefix > 1 ) ) { long int *links=(long int *)malloc(num_link*sizeof(long int)); long int *link_costs=(long int *)malloc(num_link*sizeof(long int)); get_links_from_adj_matrix(adj_matrix, map_element , links, link_costs, source); for ( i=0 ; i < num_link; i++) { adjust_adj_matrix(adj_matrix, map_element,source,links[i],link_costs[i]); calculate_path(adj_matrix,parent,dist, map_element, source); print_all_path_from_source(parent,source); print_all_next_hop(parent,source); update_routing_table_with_new_route(parent, dist,source); } free(links); free(link_costs); } free(parent); free(dist); } print_routing_table(); print_npt(); update_npt_with_new_route(); print_routing_table(); print_npt(); for(i = 0; i < map_element; i++) { free(adj_matrix[i]); } free(adj_matrix); destroy_map(); destroy_rev_map(); //hashtb_destroy(&nlsr->map); //hashtb_destroy(&nlsr->rev_map); } nlsr->is_route_calculation_scheduled=0; nlsr_unlock(); return 0; }