// ---------------------------------------------------------------- // Randomly populates lattice bonds and determines if there exists a path from // the center site to the site diagonally below and to the right. One may then // visually verify the path-detection computation. static void test_A1_oo_A2(int argc, char** argv) { int M = 18; int N = 18; double p = 0.6; int argi; int** vbonds; int** hbonds; int** site_marks; int A1[d]; int A2[d]; int ctd; for (argi = 2; argi < argc; argi++) { if (sscanf(argv[argi], "M=%d", &M) == 1) ; else if (sscanf(argv[argi], "N=%d", &N) == 1) ; else if (sscanf(argv[argi], "MN=%d", &M) == 1) N = M; else if (sscanf(argv[argi], "p=%lf", &p) == 1) ; else usage(argv[0], argv[1], 0); } if ((M < 3) || (N < 3)) usage(argv[0], argv[1], 1); vbonds = allocate_matrix(M, N, 0); hbonds = allocate_matrix(M, N, 0); site_marks = allocate_matrix(M, N, SITECHAR); set_A1_A2(A1, A2, M, N); populate_bonds(vbonds, hbonds, M, N, p); print_lattice(site_marks, vbonds, hbonds, M, N, A1, A2); printf("\n"); ctd = A1_oo_A2(site_marks, vbonds, hbonds, M, N, A1, A2); print_lattice(site_marks, vbonds, hbonds, M, N, A1, A2); if (ctd) printf("Yes\n"); else printf("No\n"); free_matrix(vbonds, M, N); free_matrix(hbonds, M, N); free_matrix(site_marks, M, N); }
// ---------------------------------------------------------------- // Randomly populates lattice bonds, prints the lattice, and lists the bonded // neighbors of the center site. One may then visually verify the // identification of neighbors. static void test_get_bonded_neighbors(int argc, char** argv) { int M = 18; int N = 18; double p = 0.6; int argi; int** vbonds; int** hbonds; int** site_marks; int A1[d]; int A2[d]; int neighbors[MAXNEI][d]; int numnei; int k; for (argi = 2; argi < argc; argi++) { if (sscanf(argv[argi], "M=%d", &M) == 1) ; else if (sscanf(argv[argi], "N=%d", &N) == 1) ; else if (sscanf(argv[argi], "MN=%d", &M) == 1) N = M; else if (sscanf(argv[argi], "p=%lf", &p) == 1) ; else usage(argv[0], argv[1], 0); } if ((M < 3) || (N < 3)) usage(argv[0], argv[1], 1); vbonds = allocate_matrix(M, N, 0); hbonds = allocate_matrix(M, N, 0); site_marks = allocate_matrix(M, N, SITECHAR); set_A1_A2(A1, A2, M, N); populate_bonds(vbonds, hbonds, M, N, p); print_lattice(site_marks, vbonds, hbonds, M, N, A1, A2); printf("\n"); get_bonded_neighbors(vbonds, hbonds, M, N, A1, neighbors, &numnei); printf("Bonded neighbors of A1 at (%d, %d):\n", A1[0], A1[1]); if (numnei == 0) printf("(none)\n"); for (k = 0; k < numnei; k++) { printf(" ( %3d, %3d )\n", neighbors[k][0], neighbors[k][1]); } free_matrix(vbonds, M, N); free_matrix(hbonds, M, N); free_matrix(site_marks, M, N); }
// ---------------------------------------------------------------- // Randomly populates lattice bonds and plots it to the screen using ASCII art. static void test_print_lattice(int argc, char** argv) { int M = 18; int N = 18; double p = 0.6; int argi; int** vbonds; int** hbonds; int** site_marks; int A1[d]; int A2[d]; // Parse the command line. for (argi = 2; argi < argc; argi++) { if (sscanf(argv[argi], "M=%d", &M) == 1) ; else if (sscanf(argv[argi], "N=%d", &N) == 1) ; else if (sscanf(argv[argi], "MN=%d", &M) == 1) N = M; else if (sscanf(argv[argi], "p=%lf", &p) == 1) ; else usage(argv[0], argv[1], 0); } // Validate parameters. if ((M < 3) || (N < 3)) usage(argv[0], argv[1], 1); // Allocate storage for the lattice. vbonds = allocate_matrix(M, N, 0); hbonds = allocate_matrix(M, N, 0); site_marks = allocate_matrix(M, N, SITECHAR); // Pick center points of the lattice. set_A1_A2(A1, A2, M, N); // Populate the bonds with probability p. populate_bonds(vbonds, hbonds, M, N, p); // Print the lattice. print_lattice(site_marks, vbonds, hbonds, M, N, A1, A2); // Free the lattice storage. free_matrix(vbonds, M, N); free_matrix(hbonds, M, N); free_matrix(site_marks, M, N); }
// ---------------------------------------------------------------- // Randomly populates lattice bonds and marks all clusters, plotting the // results to the screen. One may then visually verify the path-detection // computation. static void test_cluster_numbers(int argc, char** argv) { int M = 18; int N = 18; double p = 0.6; int argi; int** vbonds; int** hbonds; int** site_marks; int A1[d] = {-1, -1}; // Not used here int A2[d] = {-1, -1}; // Not used here for (argi = 2; argi < argc; argi++) { if (sscanf(argv[argi], "M=%d", &M) == 1) ; else if (sscanf(argv[argi], "N=%d", &N) == 1) ; else if (sscanf(argv[argi], "MN=%d", &M) == 1) N = M; else if (sscanf(argv[argi], "p=%lf", &p) == 1) ; else usage(argv[0], argv[1], 0); } if ((M < 3) || (N < 3)) usage(argv[0], argv[1], 1); vbonds = allocate_matrix(M, N, 0); hbonds = allocate_matrix(M, N, 0); site_marks = allocate_matrix(M, N, SITECHAR); populate_bonds(vbonds, hbonds, M, N, p); print_lattice(site_marks, vbonds, hbonds, M, N, A1, A2); printf("\n"); mark_cluster_numbers(site_marks, vbonds, hbonds, M, N, 0); print_lattice_and_cluster_numbers(site_marks, vbonds, hbonds, M, N); sanity_check_cluster_numbers(site_marks, vbonds, hbonds, M, N); free_matrix(vbonds, M, N); free_matrix(hbonds, M, N); free_matrix(site_marks, M, N); }
int main(int argc, const char * argv[]) { double **interaction; int *expression; double *basal; int i, size; /* Get arguments */ if (argc != 2) { fprintf(stderr, "Usage: %s networksize\n", argv[0]); exit(EXIT_FAILURE); } size = atoi(argv[1]); /* Allocate memory */ interaction = emalloc(size * sizeof interaction[0]); expression = emalloc(size * sizeof expression[0]); basal = emalloc(size * sizeof basal[0]); for (i = 0; i < size; i++) { interaction[i] = emalloc(size * sizeof interaction[0][0]); } initialise_rand_network(size, interaction); initialise_rand_genes(size, expression, basal); print_genes(size, expression, basal); printf("Network: \n"); print_lattice(size, interaction); /* Deallocate memory */ for (i = 0; i < size; i++) { free(interaction[i]); } free(interaction); free(expression); free(basal); return EXIT_SUCCESS; }
main () { unsigned long long int i; int timestart; char name[50]; // init_genrand(1); //seed MT random number timestart=time(NULL); init_genrand(timestart); //seed with current time in seconds since 1970 Unix Epoch empty_lattice (); //clears lattice fprintf(stderr,"Empty Lattice E: %f\n",lattice_energy()); fill_snakes (DENSITY); // print_lattice(); // sleep(1); //print_snakes(); //print_a_snake(0); fprintf (stderr, "Snakes filled\nNum Snakes: %d Lattice Points: %d\n", num_snakes, X * Y * Z); // fprintf(stderr,"Initial Snake Filled Lattice Energy: %f\n",lattice_energy()); // printf("#X,Y,Z: %d %d %d\n#Density: %f\n#Beta: %f\n#l_0: %d\n#sigma: %f\n#iE[1,1]: %f\n#Snakes: %d\n#Slithers: %d\n", // X,Y,Z,DENSITY,beta,l_0,sigma, iE[1][1], num_snakes,TOTAL_SLITHERS); for (i = 0; i < (long long) TOTAL_SLITHERS; i++) { wriggle (); //this function is the heart of the simulation - executed millions of times per second //might be worth unrolling this directly into this loop rather than have it as a subroutine... if (i%SLITHER_PRINT==0) //display information for monitoring the progression of the simulation { fprintf(stderr,"Slithers: %lld Snakes: %d Lattice Points: %d \n",i,num_snakes,X*Y*Z); // lattice_energy(); percolate(); // generate_df3(i/SLITHER_PRINT); // print_lattice(); // print_povray (); // fprintf(stderr,"Lattice Energy: %f\n",lattice_energy()); // usleep(1000000); // print_lattice_pnm_file((int)(beta*1000.00)); } } percolate(); //tests for percolation - and sets electric snakes as 'live' if part of percolating cluster //its a recursive algorithm though - so will crash if too many lattice sites! // print_lattice(); // print_xmakemol(); print_povray("snakes.pov"); // print_lattice_pnm_file((int)(beta*1000.00)); print_lattice_pnm_file(1); fprintf (stderr, "Num Snakes: %d Lattice Points: %d\n", num_snakes, X * Y * Z); // fprintf(stderr,"\nStats:\n\tRandom Numbers used: %lld\n\t Steps: %lld\n\tRand per Step: %f\n", // rand_count,i,((double)rand_count/(double)i) ); // scanf("%s",&name); // save_lattice_file(name); // gorgophone(); // printf("#Time Taken: %d seconds\n",time(NULL)-timestart); }