예제 #1
0
int main(int argc, char **argv) {

    char *input_graph_filename;
    char *vertex_ids_filename;
    graph_t g;

    /* parse input args */
    if (argc != 3) {
        fprintf(stderr, "%s <edge list file> "
                "<vertex ids file>\n",
                argv[0]);
        exit(1);
    }

    input_graph_filename = argv[1];
    vertex_ids_filename  = argv[2];

    read_graph_file(input_graph_filename, &g);

    /* printing harmonic centrality scores of top 10 vertices 
       ordered by degree */ 
    find_highcentrality_vertices(vertex_ids_filename, 10, &g);

    return 0;
}
int main(int argc, char const *argv[]) {

  graph *g = malloc(sizeof(graph));
  read_graph_file(g, "10-d-u.txt", false);

  for (size_t i = 1; i <= g->nvertices; i++)
    discovered[i] = false;

  int num_cc = num_connected_comp(g);     // call to num connected components
  printf("\n\ng consists of %d connected comp\n", num_cc);

  return 0;
}
예제 #3
0
void load_graph(const char *filename, graph *graph) {
  // open the file
  std::ifstream graph_file;
  graph_file.open(filename);
  get_meta_data(graph_file, graph);

  int* scratch = (int*) malloc(sizeof(int) * (graph->num_nodes + graph->num_edges));
  read_graph_file(graph_file, scratch);

  build_start(graph, scratch);
  build_edges(graph, scratch);

  free(scratch);

}
예제 #4
0
int main(int argc, char **argv) {

    char *input_graph_filename;
    char *vertex_ids_filename;
    graph_t g;

    /* parse input args */
    if (argc != 3) {
            fprintf(stderr, "%s <edge list file> "
                "<vertex ids file>\n",
                    argv[0]);
        exit(1);
    }

    input_graph_filename = argv[1];
    vertex_ids_filename  = argv[2];

    read_graph_file(input_graph_filename, &g);

    /******* DEGREE DISTRIBUTION **************/
    int maxDegree = getMaxDegree(&g);
    int* histogram = (int*) malloc((maxDegree+1)*sizeof(int));
    int i = 0;
    for(i = 0; i <= maxDegree; i++)
        histogram[i] = 0;

    calculateDegreeDistribution(&g, histogram);

    // write out the degree distribution file
    char* degree_out = "degree_distrib.txt";
    FILE* fh = fopen(degree_out, "w");

    printf("Writing to %s..... ", degree_out);
    for(i = 0; i <= maxDegree; i++)
    {
        if(histogram[i])
            fprintf(fh, "%d %d\n", i, histogram[i]);
    }

    fclose(fh);
    printf("done\n");
    /*********************************************/
    /*********************************************/


    /******* CLUSTERING COEFFICIENT **************/
    // we can't calculate triangles on nodes which only have degree 1
    // so use the histogram array to calculate the relevant size of clusteringCoeff array
    //int relevantSize = g.n - histogram[1];
    float* clusteringCoeff = (float*) malloc(g.n * sizeof(float));

    int relevantSize = 0;
    for(i = 0; i < g.n; i++)
    {
        // if the degree is 1, then we can't calculate triangles on it
        if((g.num_edges[i+1] - g.num_edges[i]) > 1)
        {
            relevantSize++;
            clusteringCoeff[i] = calculateClusteringCoefficient(&g, i);
        }
    }

    printf("Sorting the clustering coefficients, so we can obtain a line plot\n");
    // need to sort the clustering coeff so that we have a sensible cumulative plot
    qsort(clusteringCoeff, relevantSize, sizeof(clusteringCoeff[0]), compare);
    printf("done.\n");

    // write out the clustering coeff values
    char* cluster_coeffs = "clustering_coeffs.txt";
    FILE* ccoeff = fopen(cluster_coeffs, "w");
    float tempSum = 0., sum = 0.;
    for(i = 0; i < relevantSize; i++)
        tempSum += clusteringCoeff[i];

    // cache the inverse for computing easier
    tempSum = 1./tempSum;

    printf("Writing to %s..... ", cluster_coeffs);
    for(i = 0; i < relevantSize; i++)
    {
        sum += (clusteringCoeff[i] * tempSum);
        fprintf(ccoeff, "%f %f\n", clusteringCoeff[i], sum);
    }

    fclose(ccoeff);
    printf("done\n");

    // free those are not needed anymore
    free(histogram);
    free(clusteringCoeff);

    /*********************************************/
    /*********************************************/

    /******* ASSORTATIVITY ***********************/
    float* assortativity = malloc(2*g.n * sizeof(float));
    for(i = 0; i < g.n; i++)
    {
        assortativity[2*i] = g.num_edges[i+1] - g.num_edges[i];
        float val = calcAssortativity(&g, i);
        assortativity[2*i+1] = val;
    }

    char* assortativityFile = "assortativity_values.txt";
    FILE* assort_fh = fopen(assortativityFile, "w");
    printf("Writing to %s..... ", assortativityFile);
    for(i = 0; i < g.n; i++)
    {
        fprintf(assort_fh, "%d %f\n", (int)assortativity[2*i], assortativity[2*i+1]);
    }

    fclose(assort_fh);
    free(assortativity);
    printf("done\n");
    /*********************************************/
    /*********************************************/



    /* printing harmonic centrality scores of top 10 vertices 
       ordered by degree */ 
    //find_highcentrality_vertices(vertex_ids_filename, 10, &g);

    return 0;
}
예제 #5
0
int main(int argc, char **argv) {

    char *input_graph_filename;
    char *vertex_ids_filename;
    graph_t g;

    /* parse input args */
    if (argc != 2) {
        fprintf(stderr, "%s <edge list file>\n", argv[0]);
        exit(1);
    }

    input_graph_filename = argv[1];
    vertex_ids_filename  = argv[2];

    read_graph_file(input_graph_filename, &g);

    int iterToRun = 1326;
    int edgesPerIter = 8;
    int randomIterLocn = 100;

    // now calculate the new sizes
    int newNumVertices = g.n + iterToRun;
    int newNumEdges = g.m + edgesPerIter*iterToRun;     // probably overestimate, but OK for now

    // realloc the adj and num_edges arrays
    g.num_edges = (int*) realloc(g.num_edges, (newNumVertices+1)*sizeof(int));
    g.adj = (int*) realloc(g.adj, 2*newNumEdges * sizeof(int));

    // initialize the random counter
    srand(time(NULL));

    // sort based on top K vertices
    int* topVertices = malloc(edgesPerIter * sizeof(int));
    pick_top_k_vertices(&g, edgesPerIter, topVertices);

    int i, j;
    for(i = 1; i <= iterToRun; i++)
    {
        int topK = edgesPerIter;
        if (topK > g.n)
            topK = g.n;

        int vertexId;

        if(i % randomIterLocn)
        {
            preferential_attachment(&g, topVertices, topK);

        }
        else
        {
            for(j = 0; j < topK; j++)
            {
                topVertices[j] = rand() % (g.n);
            }

            preferential_attachment(&g, topVertices, topK);

            pick_top_k_vertices(&g, topK, topVertices);
        }
    }

    free(topVertices);

    FILE* fp;
    fp = fopen("output.txt", "w");
    print_graph(&g, fp);
    fclose(fp);

    return 0;
}