bool add_random_edge(Graph &g, std::set<Vertex> &lonely, std::set<Vertex> &connected, std::set<Vertex> &saturated, T &gen) { // The condition for the first edge. if (lonely.size() >= 2 && connected.empty() && saturated.empty()) { // Select two lone vertexes, which will be the end nodes of the // first edge created. Vertex src = get_random_element(lonely, gen); // Move the src node from lonely before we pick the dst node. move(src, g, lonely, connected, saturated); Vertex dst = get_random_element(lonely, gen); move(dst, g, lonely, connected, saturated); bool status = add_edge(src, dst, g).second; assert(status); return status; } // The condition for lonely vertexes and a connected component. else if (!lonely.empty() && !connected.empty()) { // Add a new edge where one vertex belongs to the connected // component, while the other is a lone one. Vertex src = get_random_element(lonely, gen); Vertex dst = get_random_element(connected, gen); bool status = add_edge(src, dst, g).second; assert(status); move(src, g, lonely, connected, saturated); move_if_needed(dst, g, connected, saturated); return status; } // The condition for a connected component only. else if (lonely.empty() && connected.size() >= 2) { // Now we have to create an edge where both vertexes of the edge // belong to the connected component. We have to be carefull // not to create a parallel edge. Vertex src = get_random_element(connected, gen); // These are the vertexes that can be destination nodes. set<Vertex> sifted = connected; sifted.erase(src); BGL_FORALL_OUTEDGES_T(src, e, g, Graph) sifted.erase(target(e, g)); // Now pick from the sifted set. Vertex dst = get_random_element(sifted, gen); bool status = add_edge(src, dst, g).second; assert(status); move_if_needed(src, g, connected, saturated); move_if_needed(dst, g, connected, saturated); return status; } return false; }
static void run_impl(const DistributedGraph& g, typename graph_traits<DistributedGraph>::vertex_descriptor s, PredecessorMap predecessor, DistanceMap distance, Lookahead lookahead, WeightMap weight, IndexMap index_map, ColorMap color_map, Compare compare, Combine combine, DistInf inf, DistZero zero, DijkstraVisitor vis) { BGL_FORALL_VERTICES_T(u, g, DistributedGraph) BGL_FORALL_OUTEDGES_T(u, e, g, DistributedGraph) local_put(color_map, target(e, g), white_color); graph::detail::parallel_dijkstra_impl2<Lookahead> ::run(g, s, predecessor, distance, lookahead, weight, index_map, color_map, compare, combine, inf, zero, vis); }
inline void ns_spider( Graph &g, WeightMap w, typename graph_traits<Graph>::vertex_descriptor v, typename harel_bfs_traits<Graph, WeightMap>::neighbor_similarity_map &ns, int cur_depth, int limit, typename property_traits<WeightMap>::value_type running_weight, bool use_threshold = false) { if (cur_depth > limit) return; // hit our depth limit. we're done! // get this node's neighbors typedef typename property_traits<WeightMap>::value_type weight; typedef typename graph_traits<Graph>::out_edge_iterator out_edge_iterator; typedef typename graph_traits<Graph>::vertex_descriptor vertex; weight total = 0; BGL_FORALL_OUTEDGES_T(v,e,g,Graph) total += get(w, e); out_edge_iterator ei, eend; for(tie(ei, eend) = out_edges(v, g); ei != eend; ++ei) { // add to the map this edge's weight - if it exists already -- use addition vertex target = boost::target(*ei, g); weight new_running_weight = running_weight * (get(w, *ei) / total); // if new_running_weight is below a certain threshold, let's just ignore it if (use_threshold && new_running_weight < 0.001) continue; if (ns.count(target)) { ns[target] = ns[target] + new_running_weight; } else { ns[target] = new_running_weight; } // and go ahead and start spidering it, too ns_spider(g, w, target, ns, cur_depth + 1, limit, new_running_weight, use_threshold); } }