void arrangement::compute_neighbours() { neighbours.resize(nonCriticalRegions.number_of_faces() - 1); // minus unbounded face for (Arrangement_2::Face_iterator face = nonCriticalRegions.faces_begin(); face != nonCriticalRegions.faces_end(); ++face) { if (!face->is_unbounded() && face->data() != -1) { Arrangement_2::Ccb_halfedge_circulator first_outer_ccb = face->outer_ccb(); Arrangement_2::Ccb_halfedge_circulator outer_ccb = face->outer_ccb(); int id_face = face->data(); std::vector<int> voisins; do { Arrangement_2::Face_handle adjacent_face = outer_ccb->twin()->face(); if (!adjacent_face->is_unbounded()) voisins.push_back(adjacent_face->data()); ++outer_ccb; } while (outer_ccb != first_outer_ccb); neighbours[id_face] = voisins; } } // clean neighbours for (int i = 0; i < (int) neighbours.size(); ++i) for (int j = 0; j < (int) neighbours[i].size(); ++j) for (int k = 0; k < j; ++k) if (neighbours[i][j] == neighbours[i][k]) { neighbours[i].erase(neighbours[i].begin() + j); --j; break; } // print results print_neighbours(); }
void graph_interface(){ char input, string[MAX_LINE_LENGTH]; list_node * ln; int end=0, i, min_weight = 1, bfs_depth, min_nodes = 0; clusters * clst; clst = NULL; while(!end){ if(PPRINT){ printf("\n \033[1;31mGraph commands:\033[0m \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n \n: ", "\033[1;32ma\033[0m", "print an author and its articles", "\033[1;32mA\033[0m", "print an article and its authors", "\033[1;32mn\033[0m", "print an article and its neighbors in the article graph", "\033[1;32mc\033[0m", "print the article count (number of nodes in graph)", "\033[1;32mt\033[0m", "print the graph total edges", "\033[1;32mm\033[0m", "print the graph nodes' medium edges", "\033[1;32mM\033[0m", "print the graph nodes' max_edges", "\033[1;32mw\033[0m", "print the edge mean weight", "\033[1;32mC\033[0m", "calculate clusters", "\033[1;32mr\033[0m", "print representatives from last calculated clusters", "\033[1;32mq\033[0m", "return to main menu"); } else{ printf("\n Graph commands: \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n %3s \t %s \n \n: ", "a", "print an author and its articles", "A", "print an article and its authors", "n", "print an article and its neighbors in the article graph", "c", "print the article count (number of nodes in graph)", "t", "print the graph total edges", "m", "print the graph nodes' medium edges", "M", "print the graph nodes' max_edges", "w", "print the edge mean weight", "C", "calculate clusters", "r", "print representatives from last calculated clusters", "q", "return to main menu"); } scanf(" %c", &input); switch(input) { case 'a': printf("\n Author Name: "); flush_input_buffer(); fgets(string, MAX_LINE_LENGTH, stdin); remove_ending_newline(string); ln = search_in_hash(string, authors_dict); if(ln == NULL) printf("\n sorry, author not present \n"); else author_print((author *) ln->key); break; case 'A': printf("\n Article Id: "); flush_input_buffer(); scanf("%d", &i); print_article_node(artcl_graph->nodes[i]); break; case 'n': printf("\n Article Id: "); flush_input_buffer(); scanf("%d", &i); printf("\n Minimum edge weight: "); flush_input_buffer(); scanf("%d", &min_weight); printf("\n Depth of search: "); flush_input_buffer(); scanf("%d", &bfs_depth); print_neighbours(artcl_graph->nodes[i], bfs_depth, min_weight); break; case 'c': printf("\n %d Articles", artcl_graph->n_nodes); break; case 't': printf("\n %d edges in the article graph", total_edges(artcl_graph)); break; case 'm': printf("\n Articles in the graph have %f edges in mean", mean_edges(artcl_graph)); break; case 'M': printf("\n The article with the biggest number of edges is:"); print_article_node(max_edges(artcl_graph)); break; case 'w': printf("\n The mean edge weight is: %f", mean_edge_weight(artcl_graph)); break; case 'C': printf("\n Minimum edge weight: "); flush_input_buffer(); scanf("%d", &min_weight); if(clst != NULL){ free(clst->representatives); free(clst->nodes_in_cluster); free(clst); } clst = find_clusters(artcl_graph, min_weight); printf("\n %d clusters found", clst->n_rpr); break; case 'r': printf("\n Minimum nodes in cluster: "); flush_input_buffer(); scanf("%d", &min_nodes); if(clst != NULL){ for(i=0;i<clst->n_rpr;++i){ if(clst->nodes_in_cluster[i]>= min_nodes){ if(PPRINT) printf("\n \033[1;32mCluster %d has %d nodes. Representative:\033[0m", i, clst->nodes_in_cluster[i]); else printf("\n Cluster %d has %d nodes. Representative:", i, clst->nodes_in_cluster[i]); print_article_node(clst->representatives[i]); } } } break; case 'q': end=1; break; } } }