Esempio n. 1
0
//==============================================================//
void dc(graph_t& g, gBenchPerf_event & perf, int perf_group) 
{
    perf.open(perf_group);
    perf.start(perf_group);
#ifdef SIM
    SIM_BEGIN(true);
#endif
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        // out degree
        vit->property().outdegree = vit->edges_size();

        // in degree
        edge_iterator eit;
        for (eit=vit->edges_begin(); eit!=vit->edges_end(); eit++) 
        {
            vertex_iterator targ = g.find_vertex(eit->target());
            (targ->property().indegree)++;
        }
    }
#ifdef SIM
    SIM_END(true);
#endif
    perf.stop(perf_group);
}// end dc
Esempio n. 2
0
void randomgraph_construction(graph_t &g, size_t vertex_num, size_t edge_num, gBenchPerf_event & perf, int perf_group)
{
    vector<pair<size_t,size_t> > edges;
    for (size_t i=0;i<edge_num;i++) 
    {
        edges.push_back(make_pair(rand()%vertex_num, rand()%vertex_num));
    }
    perf.open(perf_group);
    perf.start(perf_group);
    for (size_t i=0;i<vertex_num;i++) 
    {
        vertex_iterator vit = g.add_vertex();
        vit->set_property(vertex_property(i));
    }
#ifdef SIM
    SIM_BEGIN(true);
#endif 
    for (size_t i=0;i<edge_num;i++) 
    {
        edge_iterator eit;
        g.add_edge(edges[i].first, edges[i].second, eit);
#ifndef SIM
        eit->set_property(edge_property(i));
#endif
    }
#ifdef SIM
    SIM_END(true);
#endif 
    perf.stop(perf_group);
}
Esempio n. 3
0
size_t kcore(graph_t& g, size_t k, gBenchPerf_event & perf, int perf_group) 
{
    size_t remove_cnt=0;

    queue<vertex_iterator> process_q;

    // initialize
    for (vertex_iterator vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        size_t degree = vit->edges_size();
        vit->property().degree = degree;

        if (degree < k) 
        {
            process_q.push(vit);
            vit->property().removed = true;
            remove_cnt++;
        }
    }
    
    perf.open(perf_group);
    perf.start(perf_group);

    // remove vertices iteratively 
    while (!process_q.empty()) 
    {

        vertex_iterator vit = process_q.front();
        process_q.pop();

        for (edge_iterator eit=vit->edges_begin(); eit!=vit->edges_end(); eit++) 
        {
            size_t targ = eit->target();
            vertex_iterator targ_vit = g.find_vertex(targ);
            if (targ_vit->property().removed==false)
            {
                targ_vit->property().degree--;
                if (targ_vit->property().degree < k) 
                {
                    targ_vit->property().removed = true;
                    process_q.push(targ_vit);
                    remove_cnt++;
                }
            }
        }

    }

    perf.stop(perf_group);
    return remove_cnt;
}  // end kcore
Esempio n. 4
0
void bc(graph_t& g, bool undirected,
        gBenchPerf_event & perf, int perf_group)
{
    typedef list<size_t> vertex_list_t;
    // initialization
    size_t vnum = g.num_vertices();

    vector<vertex_list_t> shortest_path_parents(vnum);
    vector<size_t> num_of_paths(vnum);
    vector<int8_t> depth_of_vertices(vnum); // 8 bits signed
    vector<double> centrality_update(vnum);

    double normalizer;
    normalizer = (undirected)? 2.0 : 1.0;

    perf.open(perf_group);
    perf.start(perf_group);


    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        size_t vertex_s = vit->id();
        stack<size_t> order_seen_stack;
        queue<size_t> BFS_queue;

        BFS_queue.push(vertex_s);

        for (size_t i=0;i<vnum;i++) 
        {
            shortest_path_parents[i].clear();

            num_of_paths[i] = (i==vertex_s) ? 1 : 0;
            depth_of_vertices[i] = (i==vertex_s) ? 0: -1;
            centrality_update[i] = 0;
        }

        // BFS traversal
        while (!BFS_queue.empty()) 
        {
            size_t v = BFS_queue.front();
            BFS_queue.pop();
            order_seen_stack.push(v);

            vertex_iterator vit = g.find_vertex(v);

            for (edge_iterator eit=vit->edges_begin(); eit!= vit->edges_end(); eit++) 
            {
                size_t w = eit->target();
                
                if (depth_of_vertices[w]<0) 
                {
                    BFS_queue.push(w);
                    depth_of_vertices[w] = depth_of_vertices[v] + 1;
                }

                if (depth_of_vertices[w] == (depth_of_vertices[v] + 1)) 
                {
                    num_of_paths[w] += num_of_paths[v];
                    shortest_path_parents[w].push_back(v);
                }
            }

        }

        // dependency accumulation
        while (!order_seen_stack.empty()) 
        {
            size_t w = order_seen_stack.top();
            order_seen_stack.pop();

            double coeff = (1+centrality_update[w])/(double)num_of_paths[w];
            vertex_list_t::iterator iter;
            for (iter=shortest_path_parents[w].begin(); 
                  iter!=shortest_path_parents[w].end(); iter++) 
            {
                size_t v=*iter;

                centrality_update[v] += (num_of_paths[v]*coeff);
            }

            if (w!=vertex_s) 
            {
                vertex_iterator vit = g.find_vertex(w);
                vit->property().BC += centrality_update[w]/normalizer;
            }
        }
    }

    perf.stop(perf_group);

    return;
}