集合平均十多个独立实现

时间:2017-07-31 06:52:10

标签: c

   #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>
    //#include<igraph.h>
    #define NUM_VERTICES1 15000// No. of data  for Newman Watts to be used 15000:
    //#define strings 10 // No. of base strings to be used 160:
    //Function for generating infection rate randomly: 
    void unifRand(double *x, double *x1, double *x2)
    {
        int i; 
        const int n = 200; // 20
        srand(unsigned(time(NULL)));
        for(i = 0; i < n - 1; i++)
        {
             //x2[i] = rand()/double(RAND_MAX); //generate random number for choosing the infected neighbors(m):
             x[i] = (0.2)+(0.4-0.2)*rand()/double(RAND_MAX);
             x2[i] = 0.02; // fix the neighbor m and check:                      
             x1[i] = log(1-x[i]);// Infection rate lambda:
             printf("%lf\t%lf\t%lf\t%d\t%d\t\n", x[i], x1[i],x2[i],rand(), RAND_MAX);
         }
    }



    // Function 2:
    struct Edge {

        int vertex;
        struct Edge * next;
    };

    // Inserts Node to the Linked List by Head Insertion - O(1)
    // Returns address of head which is the newly created node.
    struct Edge * addEdge(struct Edge * currentHead, int newVertex)
    {
        struct Edge * newHead 
                     = (struct Edge *) malloc(sizeof(struct Edge));

        newHead->vertex = newVertex;
        newHead->next = currentHead;

        return newHead;
    }

    int main()
    {
        FILE *wg = NULL;
        FILE *ob = NULL;
        wg = fopen("ncwang1.txt","w");
        ob = fopen("obs.txt","w");
        if(wg == NULL)
        {
            printf("Error in opening file wg!\n");
        }
        if(ob == NULL)
        {
            printf("Error in opening file ob!\n");
        }

        int vertices = 200, edges = 400, i; // 20,50:(100,50)
        int strings = 160;
        int nobs = 10;
        int v1, v2;
        double j;
        int k;
        double t=0.0;
        double dt=0.1;
        double b;
        double x[vertices], x1[vertices];
        double x2[vertices];
        unifRand(x,x1,x2);

        // printf("Enter the Number of Vertices -\n");
        // scanf("%d", &vertices);

        //printf("\nEnter the Number of Edges -\n");
        // scanf("%d", &edges);

        struct Edge * adjacencyList[vertices + 1];
        // Size is made (vertices + 1) to use the
        // array as 1-indexed, for simplicity

        // initialize array:
        for (i = 0; i <= vertices; ++i) {
            adjacencyList[i] = NULL;
        }

        for (i = 0; i <= edges; ++i) {
            //scanf(%d%d", &v1, &v2);
            v1 = rand()%200;
            v2 = rand()%200; 

            // Adding edge v1 --> v2
            // Add edge from v1 --> v2
            if(v1 != v2)
                adjacencyList[v1] = addEdge(adjacencyList[v1], v2);

            // Adding edge v2 --> v1
            // Remove this if you want a Directed Graph
            adjacencyList[v2] = addEdge(adjacencyList[v2], v1);
        }

        // Printing Adjacency List
        printf("\nAdjacency List -\n\n");

        for(j = 0; j < strings; j++){
            for (i = 0; i <= vertices; ++i) {
                printf("adjacencyList[%d] -> ", i);
                struct Edge * traverse = adjacencyList[i];

                while (traverse != NULL)
                {
                    b = (double)j/vertices;
                    fprintf(wg,"%d \t%d \t\t%0.6lf\t\t%0.1lf\t\t%0.8lf\t\n", i, traverse->vertex,-(x1[i]*(traverse->vertex))/100,b,
                    x[i]);
                    //fprintf(ob,"%d\t%0.2lf\t%0.1lf\n",k,(-log(1-x[i])*(traverse->vertex)),b);
                    printf("%d -> ", traverse->vertex);
                    traverse = traverse->next;
                }
                printf("NULL\n");
            }
        }
        return 0;
        fclose(wg);
        fclose(ob);
        wg = NULL;
        ob = NULL;
    }

我已经从一篇研究论文中编写了上面的网络重建性能代码。我必须绘制&#39; b&#39;与输出中的(-log(1-x [i])*(遍历 - >顶点))。该论文的作者提到&#34;结果是通过整体平均超过10个独立实现获得的。我如何在我的代码中实现这一点。由于我是统计物理的新手,我不知道如何实施。任何建议都会有所帮助。电流输出在b = 0.1,0.2..1.0时只给出一条线,这不是预期的输出。

0 个答案:

没有答案