void WikiGraph::print_from_list(list<int> nodes_to_analyse, int start_node, int number_pages) const try { Graph g; g = sub_graph(nodes_to_analyse); g.set_num_walks(get_num_walks()); g.set_walk_length(get_walk_length()); map<int,int> old_ids; int i=1; int new_start_node = 1; for(const auto& a : nodes_to_analyse) { if(a == start_node) new_start_node = i; old_ids[i++] = a; } // get the counts for the random walk map<int,int> rw_counts = g.random_walks(new_start_node); // sort pages by the visit count, in descending order vector<pair<int,int>> counts_and_nodes; for(pair<int,int> a :rw_counts) { counts_and_nodes.push_back(make_pair(a.second, a.first)); } sort(counts_and_nodes.begin(), counts_and_nodes.end(), greater<pair<int,int> >()); // print pages in descending order of number of visits for(pair<int, int> a : counts_and_nodes) { cout << node_to_wiki[old_ids[a.second]].title << ": " << a.first << " visits" << endl; if(--number_pages <= 0) break; } } catch (my_exception& ex) { ex.addToStack("print_from_list"); throw; }
list<int> Graph::johnsons_maximal_clique(list<int> & clique) { vector<set<Incidence> > sub_graph(adjacency_lists.size()); list<int> sub = clique; int n_nodes = number_of_nodes(); vector<bool> rest(n_nodes,true); list<int> rest_list; for (list<int>::iterator it = sub.begin(); it != sub.end(); it++) { rest[*it] = false; }; for (int i=0;i<rest.size();i++) { if (rest[i]) { rest_list.push_back(i); }; }; for (list<int>::iterator it = clique.begin(); it != clique.end(); it++) { list<int> new_list; for (list<int>::iterator it2 =rest_list.begin();it2 != rest_list.end(); it2++) { if (has_edge(*it,*it2)) { new_list.push_back(*it2); }; }; rest_list = new_list; }; rest.clear(); rest.resize(n_nodes,false); for (list<int>::iterator it = rest_list.begin(); it != rest_list.end(); it++) { rest[*it] = true; }; for (list<int>::iterator it = rest_list.begin(); it != rest_list.end(); it++) { for (set<Incidence>::iterator it2 = adjacency_lists[*it].begin(); it2 != adjacency_lists[*it].end(); it2++) { if (rest[it2->get_incident_node()]) { sub_graph[*it].insert(Incidence(it2->get_incident_node(),1)); }; }; }; calc_johnsons(sub,sub_graph,rest_list); return sub; };