예제 #1
0
void CDLib::generate_chord_graph(graph& g, id_type num_nodes) {
    init_empty_graph(g, num_nodes);
    for (id_type i = 0; i < g.get_num_nodes(); i++) {
        g.add_edge(i, (i - 1) % g.get_num_nodes(), 1);
        for (id_type j = 1; j <= g.get_num_nodes() / 2; j *= 2)
            g.add_edge(i, (i + j) % g.get_num_nodes(), 1);
    }
    g.set_graph_name("chord_" + T2str<id_type > (num_nodes));
}
예제 #2
0
void CDLib::generate_de_bruijn_graph(graph& g, id_type num_symbols, id_type sequence_length) {
    if (num_symbols && sequence_length) {
        id_type size = (unsigned long) pow((double) num_symbols, (double) sequence_length);
        init_empty_graph(g, size);
        for (id_type i = 0; i < g.get_num_nodes(); i++) {
            id_type basis = (i * num_symbols) % g.get_num_nodes();
            for (id_type j = 0; j < num_symbols; j++) g.add_edge(i, basis + j, 1);
        }
        g.set_graph_name("db_" + T2str<id_type > (num_symbols) + "_" + T2str<id_type > (sequence_length));
    }
}
예제 #3
0
string CDLib::get_graph_details_components(const graph& g)
{
    ostringstream oss;
    vector<node_set> components;
    id_type num_comp = get_connected_components_undirected(g,components);
    oss << "Number of Components : " << num_comp << endl;
    oss << "Average Component Size : " << ((double)g.get_num_nodes()/num_comp) << endl;
    node_set members;
    id_type large_size = get_largest_connected_component(g,members);
    oss << "Size of Largest Connected Component : " << large_size << endl;
    oss << "Fraction of Nodes in LCC : " << ((double)large_size/g.get_num_nodes()) << endl;
    return oss.str();
}
예제 #4
0
void CDLib::generate_clique_graph(graph& g, id_type size) {
    init_empty_graph(g, size);
    for (id_type i = 0; i < g.get_num_nodes(); i++)
        for (id_type j = 0; j < i; j++)
            if (i != j) g.add_edge(i, j, 1);
    g.set_graph_name("clique_" + T2str<id_type > (size));
}
예제 #5
0
void CDLib::generate_spoke_graph(graph& g, id_type size) {
    generate_star_graph(g, size);
    id_type last_id = g.get_num_nodes() - 1;
    if (last_id > 1) {
        for (id_type i = 1; i < last_id; i++)
            g.add_edge(i, (i + 1), 1);
        g.add_edge(last_id, 1, 1);
    }
    g.set_graph_name("spoke_" + T2str<id_type > (size));
}
예제 #6
0
void CDLib::generate_planted_partition_graph(graph& g, id_type num_comms, id_type comm_size, double pin, double pout, vector< node_set>& communities) {
    if (pin >= 0 && pout >= 0 && pin <= 1 && pout <= 1) {
        id_type num_nodes = comm_size*num_comms;
        init_empty_graph(g, num_nodes);
        communities.assign(num_comms, node_set());
        Uniform01RandomGeneratorMT p_gen;
        for (id_type i = 0; i < num_nodes; i++)
            if (i % comm_size) communities[i / comm_size].insert(i);
        for (id_type i = 0; i < g.get_num_nodes(); i++) {
            id_type comm_id_i = i / comm_size;
            for (id_type j = 0; j < g.get_num_nodes(); j++) {
                id_type comm_id_j = j / comm_size;
                double p = p_gen.next();
                if (comm_id_i == comm_id_j && p > pin) g.add_edge(i, j, 1);
                else if (p > pout) g.add_edge(i, j, 1);
            }
        }
        g.set_graph_name("pp_" + T2str<id_type > (num_comms) + "_" + T2str<id_type > (comm_size) + "_" + T2str<double>(pin) + "_" + T2str<double>(pout));
    }
}
예제 #7
0
string CDLib::get_graph_details(const graph& g)
{
    ostringstream oss;
    oss << "Number of Nodes: " << g.get_num_nodes() << endl;
    oss << "Number of Edges: " << g.get_num_edges() << endl;
    oss << "Number of Self Edges: " << g.get_num_self_edges() << endl;
    oss << "Total Weight: " << g.get_total_weight() << endl;
    oss << "Weight of Self Edges: " << g.get_self_edges_weight() << endl;
    vector<id_type> in_degrees(g.get_num_nodes(),0),out_degrees(g.get_num_nodes(),0);
    vector<double> in_weights(g.get_num_nodes(),0.0),out_weights(g.get_num_nodes(),0.0);
    for(id_type i=0;i<g.get_num_nodes();i++)
    {
        in_degrees[i] = g.get_node_in_degree(i);
        out_degrees[i] = g.get_node_out_degree(i);
        in_weights[i] = g.get_node_in_weight(i);
        out_weights[i] = g.get_node_out_weight(i);
    }
    oss << "In Degrees" << endl;
    oss << "Min\tMedian\tMax\tMean\tVariance" << endl;
    oss << statistics_string(in_degrees,"\t") << endl;
    oss << "Out Degrees" << endl;
    oss << "Min\tMedian\tMax\tMean\tVariance" << endl;
    oss << statistics_string(out_degrees,"\t")  << endl;
    oss << "In Weights" << endl;
    oss << "Min\tMedian\tMax\tMean\tVariance" << endl;
    oss << statistics_string(in_weights,"\t") << endl;
    oss << "Out Weights" << endl;
    oss << "Min\tMedian\tMax\tMean\tVariance" << endl;
    oss << statistics_string(out_weights,"\t")  << endl;
    return oss.str();
}
예제 #8
0
파일: graph_test.cpp 프로젝트: Bashakov/agg
 //------------------------------------------------------------------------
 void draw_nodes_draft()
 {
     pixfmt pixf(rbuf_window());
     base_renderer rb(pixf);
     primitives_renderer prim(rb);
     int i;
     for(i = 0; i < m_graph.get_num_nodes(); i++)
     {
         graph::node n = m_graph.get_node(i, width(), height());
         prim.fill_color(m_gradient_colors[147]);
         prim.line_color(m_gradient_colors[255]);
         prim.outlined_ellipse(int(n.x), int(n.y), 10, 10);
         prim.fill_color(m_gradient_colors[50]);
         prim.solid_ellipse(int(n.x), int(n.y), 4, 4);
     }
 }
예제 #9
0
파일: graph_test.cpp 프로젝트: Bashakov/agg
    //------------------------------------------------------------------------
    void draw_nodes_fine(scanline_rasterizer& ras)
    {
        gradient_span_alloc sa;
        pixfmt pixf(rbuf_window());
        base_renderer rb(pixf);
        int i;
        for(i = 0; i < m_graph.get_num_nodes(); i++)
        {
            graph::node n = m_graph.get_node(i, width(), height());
            agg::ellipse ell(n.x, n.y, 5.0 * m_width.value(), 5.0 * m_width.value());

            double x, y;
            switch(m_draw)
            {
                case 0:
                    ell.rewind(0);
                    while(!agg::is_stop(ell.vertex(&x, &y)));
                    break;

                case 1:
                    ras.reset();
                    ras.add_path(ell);
                    break;

                case 2:
                    ras.reset();
                    ras.add_path(ell);
                    ras.sort();
                    break;

                case 3:
                {
                    gradient_function gf;
                    agg::trans_affine mtx;
                    mtx *= agg::trans_affine_scaling(m_width.value() / 2.0);
                    mtx *= agg::trans_affine_translation(n.x, n.y);
                    mtx.invert();
                    interpolator inter(mtx);
                    gradient_span_gen sg(inter, gf, m_gradient_colors, 0.0, 10.0);
                    gradient_renderer ren(rb, sa, sg);
                    ras.add_path(ell);
                    agg::render_scanlines(ras, m_sl, ren);
                }
                break;
            }
        }
    }
예제 #10
0
파일: graphio.cpp 프로젝트: BalkiLab/graffy
bool CDLib::read_matlab_sp(graph& g, const string& filepath) {
    g.clear();
    ifstream ifs;
    ifs.open(filepath.c_str());
    if (ifs.is_open()) {
        id_type from, to;
        double weight = 1;
        while (!ifs.eof()) {
            ifs >> from >> to >> weight;
            while (max(from, to) > g.get_num_nodes()) {
                g.add_node();
            }
            g.add_edge(from - 1, to - 1, weight);
        }
        g.set_graph_name(filename(filepath));
        return true;
    }
예제 #11
0
void CDLib::generate_star_graph(graph& g, id_type size) {
    init_empty_graph(g, size);
    for (id_type i = 1; i < g.get_num_nodes(); i++)
        g.add_edge(0, i, 1);
    g.set_graph_name("star_" + T2str<id_type > (size));
}
예제 #12
0
void CDLib::generate_ring_graph(graph& g, id_type size) {
    init_empty_graph(g, size);
    for (id_type i = 0; i < g.get_num_nodes(); i++)
        g.add_edge(i, (i + 1) % size, 1);
    g.set_graph_name("ring_" + T2str<id_type > (size));
}