Hi,
I am an undergraduate student and am doing a project on Scientific Initiation, 
but I am totally inexperienced in programming, so I would kindly ask for your 
help.I want to build graph average degree ranging from 1 to 5 and know to have 
average degree it is necessary to first edges 150 connected to degree 2-300 
edges and so on. I tried to use the simplify () function inside the while loop, 
but got error, then think to use it must first setting the weight values; but 
in doing so the graphs generated do not have the correct number of edges that 
should possess to achieve the desired degree. I'll put below, part of the code. 
Please give me a suggestion how to fix it. 
void TNetData::MatrixSimilarity(float sigma, int initial_degree, int 
final_degree){    VectorXf v1, v2;    MatrixXf W(NOS,NOS); int i, j, g, from, 
to;  float value, degree_average, similarity, accuracy;      igraph_integer_t 
eid;   igraph_vector_t  weights, degree, edges;        char namefile[256];    
string namefilecomplete;    char ext[] = "xml";
    igraph_attribute_combination_t comb;
    FILE *file; file = fopen("Graph and Information.data", "w");
        igraph_vector_init(&weights, 0);        igraph_vector_init(&edges,0);   
igraph_vector_init(&degree,NOS);        igraph_vector_null(&degree);    W = 
ArrayXXf::Zero(NOS,NOS);
        SETGAN(&net,"weighted", 1);
    igraph_attribute_combination(&comb, "weight", 
IGRAPH_ATTRIBUTE_COMBINE_FIRST, IGRAPH_NO_MORE_ATTRIBUTES);
        nSigma = sigma; sigma = sigma*sigma*2.0;
        for (i = 0 ; i < NOS ; i++){            v1 = data.row(i);               
for (j = 0 ; j < NOS ; j++){                if(i == j)                {         
           W(i,j) = 0.0;                    W(j,i) = 0.0;                }      
          else{                v2 = data.row(j);                value = 
dist.GetDistance(v1,v2);                value = value / sigma;                
value = exp(-value);                W(i,j) = value;                W(j,i) = 
value;                        }               }       }
   eid = 0;    for(g = initial_degree; g <= final_degree; g++)             g => 
average degree   {        igraph_degree(&net, &degree, igraph_vss_all(), 
IGRAPH_ALL, IGRAPH_NO_LOOPS);        degree_average = 
(igraph_vector_sum(&degree)/(float)NOS);
        while(degree_average <= (float)g)        {            do            {   
             from = (rand()%(NOS-1));                to = (rand()%(NOS-1));     
       }while(from == to);
            igraph_vector_push_back(&edges,from);            
igraph_vector_push_back(&edges,to);            similarity = W(from,to) = 
W(to,from);            igraph_vector_push_back(&weights,similarity);            
igraph_add_edges(&net,&edges,0);            eid++;            
igraph_degree(&net, &degree, igraph_vss_all(), IGRAPH_ALL, IGRAPH_NO_LOOPS);    
        degree_average = (igraph_vector_sum(&degree)/(float)NOS);
        }  
        for (i = 0; i < eid; i++)        {            SETEAN(&net, "weight", i, 
VECTOR(weights)[i]);        }
        sprintf(namefile, "%s_network%d.%s", GAS(&net, "dataset"), g, ext);     
   namefilecomplete.assign(namefile);        
graphs.push_back(namefilecomplete);        SaveNetwork(g);        
fprintf(file,"Average Degree => %f  Edges => %d\n\n", degree_average, eid);     
   igraph_write_graph_edgelist(&net, file);   }     fclose(file);        
igraph_vector_destroy(&weights);        igraph_vector_destroy(&edges);  
igraph_vector_destroy(&degree); igraph_attribute_combination_destroy(&comb);}
Thank you                                         
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to