void librdist_geometric(gsl_rng *rng, int argc, void *argv, int bufc, float *buf){ t_atom *av = (t_atom *)argv; if(argc != librdist_getnargs(ps_geometric)){ return; } const double p = librdist_atom_getfloat(av); int i; for(i = 0; i < bufc; i++) buf[i] = (float)gsl_ran_geometric(rng, p); }
int gslalg_rng_geometric_VM ( Word* args, Word& result, int message, Word& local, Supplier s ) { result = qp->ResultStorage( s ); CcInt *res = ((CcInt*) result.addr); long resD = 0; CcReal *cA = (CcReal*) args[0].addr; if( cA->IsDefined() ) { double a = cA->GetRealval(); if( 0.0 <= a && a <= 1.0 ) { resD = gsl_ran_geometric(the_gsl_randomgenerator.GetGenerator(), a); res->Set(true, resD); } else { res->Set(false, 0); } } else res->Set(false, 0); return (0); }
int main (int argc, char *argv[]) { size_t i,j; size_t n = 0; double mu = 0, nu = 0, nu1 = 0, nu2 = 0, sigma = 0, a = 0, b = 0, c = 0; double zeta = 0, sigmax = 0, sigmay = 0, rho = 0; double p = 0; double x = 0, y =0, z=0 ; unsigned int N = 0, t = 0, n1 = 0, n2 = 0 ; unsigned long int seed = 0 ; const char * name ; gsl_rng * r ; if (argc < 4) { printf ( "Usage: gsl-randist seed n DIST param1 param2 ...\n" "Generates n samples from the distribution DIST with parameters param1,\n" "param2, etc. Valid distributions are,\n" "\n" " beta\n" " binomial\n" " bivariate-gaussian\n" " cauchy\n" " chisq\n" " dir-2d\n" " dir-3d\n" " dir-nd\n" " erlang\n" " exponential\n" " exppow\n" " fdist\n" " flat\n" " gamma\n" " gaussian-tail\n" " gaussian\n" " geometric\n" " gumbel1\n" " gumbel2\n" " hypergeometric\n" " laplace\n" " landau\n" " levy\n" " levy-skew\n" " logarithmic\n" " logistic\n" " lognormal\n" " negative-binomial\n" " pareto\n" " pascal\n" " poisson\n" " rayleigh-tail\n" " rayleigh\n" " tdist\n" " ugaussian-tail\n" " ugaussian\n" " weibull\n") ; exit (0); } argv++ ; seed = atol (argv[0]); argc-- ; argv++ ; n = atol (argv[0]); argc-- ; argv++ ; name = argv[0] ; argc-- ; argc-- ; gsl_rng_env_setup() ; if (gsl_rng_default_seed != 0) { fprintf(stderr, "overriding GSL_RNG_SEED with command line value, seed = %ld\n", seed) ; } gsl_rng_default_seed = seed ; r = gsl_rng_alloc(gsl_rng_default) ; #define NAME(x) !strcmp(name,(x)) #define OUTPUT(x) for (i = 0; i < n; i++) { printf("%g\n", (x)) ; } #define OUTPUT1(a,x) for(i = 0; i < n; i++) { a ; printf("%g\n", x) ; } #define OUTPUT2(a,x,y) for(i = 0; i < n; i++) { a ; printf("%g %g\n", x, y) ; } #define OUTPUT3(a,x,y,z) for(i = 0; i < n; i++) { a ; printf("%g %g %g\n", x, y, z) ; } #define INT_OUTPUT(x) for (i = 0; i < n; i++) { printf("%d\n", (x)) ; } #define ARGS(x,y) if (argc != x) error(y) ; #define DBL_ARG(x) if (argc) { x=atof((++argv)[0]);argc--;} else {error( #x);}; #define INT_ARG(x) if (argc) { x=atoi((++argv)[0]);argc--;} else {error( #x);}; if (NAME("bernoulli")) { ARGS(1, "p = probability of success"); DBL_ARG(p) INT_OUTPUT(gsl_ran_bernoulli (r, p)); } else if (NAME("beta")) { ARGS(2, "a,b = shape parameters"); DBL_ARG(a) DBL_ARG(b) OUTPUT(gsl_ran_beta (r, a, b)); } else if (NAME("binomial")) { ARGS(2, "p = probability, N = number of trials"); DBL_ARG(p) INT_ARG(N) INT_OUTPUT(gsl_ran_binomial (r, p, N)); } else if (NAME("cauchy")) { ARGS(1, "a = scale parameter"); DBL_ARG(a) OUTPUT(gsl_ran_cauchy (r, a)); } else if (NAME("chisq")) { ARGS(1, "nu = degrees of freedom"); DBL_ARG(nu) OUTPUT(gsl_ran_chisq (r, nu)); } else if (NAME("erlang")) { ARGS(2, "a = scale parameter, b = order"); DBL_ARG(a) DBL_ARG(b) OUTPUT(gsl_ran_erlang (r, a, b)); } else if (NAME("exponential")) { ARGS(1, "mu = mean value"); DBL_ARG(mu) ; OUTPUT(gsl_ran_exponential (r, mu)); } else if (NAME("exppow")) { ARGS(2, "a = scale parameter, b = power (1=exponential, 2=gaussian)"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_exppow (r, a, b)); } else if (NAME("fdist")) { ARGS(2, "nu1, nu2 = degrees of freedom parameters"); DBL_ARG(nu1) ; DBL_ARG(nu2) ; OUTPUT(gsl_ran_fdist (r, nu1, nu2)); } else if (NAME("flat")) { ARGS(2, "a = lower limit, b = upper limit"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_flat (r, a, b)); } else if (NAME("gamma")) { ARGS(2, "a = order, b = scale"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_gamma (r, a, b)); } else if (NAME("gaussian")) { ARGS(1, "sigma = standard deviation"); DBL_ARG(sigma) ; OUTPUT(gsl_ran_gaussian (r, sigma)); } else if (NAME("gaussian-tail")) { ARGS(2, "a = lower limit, sigma = standard deviation"); DBL_ARG(a) ; DBL_ARG(sigma) ; OUTPUT(gsl_ran_gaussian_tail (r, a, sigma)); } else if (NAME("ugaussian")) { ARGS(0, "unit gaussian, no parameters required"); OUTPUT(gsl_ran_ugaussian (r)); } else if (NAME("ugaussian-tail")) { ARGS(1, "a = lower limit"); DBL_ARG(a) ; OUTPUT(gsl_ran_ugaussian_tail (r, a)); } else if (NAME("bivariate-gaussian")) { ARGS(3, "sigmax = x std.dev., sigmay = y std.dev., rho = correlation"); DBL_ARG(sigmax) ; DBL_ARG(sigmay) ; DBL_ARG(rho) ; OUTPUT2(gsl_ran_bivariate_gaussian (r, sigmax, sigmay, rho, &x, &y), x, y); } else if (NAME("dir-2d")) { OUTPUT2(gsl_ran_dir_2d (r, &x, &y), x, y); } else if (NAME("dir-3d")) { OUTPUT3(gsl_ran_dir_3d (r, &x, &y, &z), x, y, z); } else if (NAME("dir-nd")) { double *xarr; ARGS(1, "n1 = number of dimensions of hypersphere"); INT_ARG(n1) ; xarr = (double *)malloc(n1*sizeof(double)); for(i = 0; i < n; i++) { gsl_ran_dir_nd (r, n1, xarr) ; for (j = 0; j < n1; j++) { if (j) putchar(' '); printf("%g", xarr[j]) ; } putchar('\n'); } ; free(xarr); } else if (NAME("geometric")) { ARGS(1, "p = bernoulli trial probability of success"); DBL_ARG(p) ; INT_OUTPUT(gsl_ran_geometric (r, p)); } else if (NAME("gumbel1")) { ARGS(2, "a = order, b = scale parameter"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_gumbel1 (r, a, b)); } else if (NAME("gumbel2")) { ARGS(2, "a = order, b = scale parameter"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_gumbel2 (r, a, b)); } else if (NAME("hypergeometric")) { ARGS(3, "n1 = tagged population, n2 = untagged population, t = number of trials"); INT_ARG(n1) ; INT_ARG(n2) ; INT_ARG(t) ; INT_OUTPUT(gsl_ran_hypergeometric (r, n1, n2, t)); } else if (NAME("laplace")) { ARGS(1, "a = scale parameter"); DBL_ARG(a) ; OUTPUT(gsl_ran_laplace (r, a)); } else if (NAME("landau")) { ARGS(0, "no arguments required"); OUTPUT(gsl_ran_landau (r)); } else if (NAME("levy")) { ARGS(2, "c = scale, a = power (1=cauchy, 2=gaussian)"); DBL_ARG(c) ; DBL_ARG(a) ; OUTPUT(gsl_ran_levy (r, c, a)); } else if (NAME("levy-skew")) { ARGS(3, "c = scale, a = power (1=cauchy, 2=gaussian), b = skew"); DBL_ARG(c) ; DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_levy_skew (r, c, a, b)); } else if (NAME("logarithmic")) { ARGS(1, "p = probability"); DBL_ARG(p) ; INT_OUTPUT(gsl_ran_logarithmic (r, p)); } else if (NAME("logistic")) { ARGS(1, "a = scale parameter"); DBL_ARG(a) ; OUTPUT(gsl_ran_logistic (r, a)); } else if (NAME("lognormal")) { ARGS(2, "zeta = location parameter, sigma = scale parameter"); DBL_ARG(zeta) ; DBL_ARG(sigma) ; OUTPUT(gsl_ran_lognormal (r, zeta, sigma)); } else if (NAME("negative-binomial")) { ARGS(2, "p = probability, a = order"); DBL_ARG(p) ; DBL_ARG(a) ; INT_OUTPUT(gsl_ran_negative_binomial (r, p, a)); } else if (NAME("pareto")) { ARGS(2, "a = power, b = scale parameter"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_pareto (r, a, b)); } else if (NAME("pascal")) { ARGS(2, "p = probability, n = order (integer)"); DBL_ARG(p) ; INT_ARG(N) ; INT_OUTPUT(gsl_ran_pascal (r, p, N)); } else if (NAME("poisson")) { ARGS(1, "mu = scale parameter"); DBL_ARG(mu) ; INT_OUTPUT(gsl_ran_poisson (r, mu)); } else if (NAME("rayleigh")) { ARGS(1, "sigma = scale parameter"); DBL_ARG(sigma) ; OUTPUT(gsl_ran_rayleigh (r, sigma)); } else if (NAME("rayleigh-tail")) { ARGS(2, "a = lower limit, sigma = scale parameter"); DBL_ARG(a) ; DBL_ARG(sigma) ; OUTPUT(gsl_ran_rayleigh_tail (r, a, sigma)); } else if (NAME("tdist")) { ARGS(1, "nu = degrees of freedom"); DBL_ARG(nu) ; OUTPUT(gsl_ran_tdist (r, nu)); } else if (NAME("weibull")) { ARGS(2, "a = scale parameter, b = exponent"); DBL_ARG(a) ; DBL_ARG(b) ; OUTPUT(gsl_ran_weibull (r, a, b)); } else { fprintf(stderr,"Error: unrecognized distribution: %s\n", name) ; } return 0 ; }
int GSLRNG_geometric(stEval *args, stEval *result, void *i) { gsl_rng *r = STPOINTER(&args[0]); double p = STDOUBLE(&args[1]); STINT(result) = gsl_ran_geometric(r,p); return EC_OK; }
void simulation(float mu, float koff){ /*set up variables for RNG, generate seed that's time-dependent, * seed RNG with that value - guarantees that MPI instances will * actually be different from each other*/ const gsl_rng_type * T; gsl_rng_env_setup(); T = gsl_rng_default; gsl_rng *r; r = gsl_rng_alloc (T); unsigned long int seed; seed=gen_seed(); gsl_rng_set(r,seed); /*old legacy stuff //memset(lanes,0,NLANES*L*sizeof(int)); //lanes[8][48]=22; //FILE *fp;*/ /*define total time of simulation (in units of polymerizing events)*/ int totaltime=500; /*define number of ends in the system, necessary for depol * calculation and rates. Also, define a toggle for the first pol * event to reset*/ int ends=0; int newends=0; int first=1; /*just declare a bunch of stuff that we will use*/ float domega,kon; int accepted=0; int filaments,noconsts; int int_i; int j,k,size,currfils,currlen,gap,l,m; float i,p,coverage; int type=0; /*declare two matrices for the filaments per lane, one for the * "permanent" stuff and one for temporary testing in the * Metropolis scheme*/ int lanes[NLANES][L]={{0}}; int newlanes[NLANES][L]={{0}}; /*two floats to store the time of the next polymerization and depol * events, that will be initialized later*/ float nexton=0; float nextoff=VERYBIG; /*declare three GMP arbitrary precision values: one for storing the * current number of microstates, one for the new number when testing * in the Metropolis scheme and one to store the difference*/ mpz_t states; mpz_t newstates; mpz_t deltastates; mpz_init(states); mpz_init(newstates); mpz_init(deltastates); /*sets up: the value of the chemical potential of a monomer, the * on-rate (we're always taking it to be one), the off-rate * (defined in relation to the on-rate) and the average size of * a new polymer*/ kon=1; //float kon=1.0; //float koff=0.1; //try based on ends //printf("%f %f\n",kon,koff); int avg_size=3; p=1.0/avg_size; float inv_sites=1.0/(NLANES*(L-1)); clock_t t1 = clock(); /*sets up the I/O to a file - filename is dependent on MPI * instance number to avoid conflicts*/ char* filename[40]; //int my_rank=0; int my_rank; MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); sprintf(filename,"outputs_%1.1f_%1.1f/run%d.txt",mu,koff,my_rank); FILE *fp = fopen(filename, "w"); //strcat(filename,threadnum); //strcat(filename,".txt"); /*sets up the time for the first on event (first off only calculated * after we have filaments!)*/ nexton=gsl_ran_exponential(r,1.0/kon); //nextoff=gsl_ran_exponential(r,1.0/koff); //printf("nexton=%f nexoff=%f, avg on=%f avg off=%f thread=%d\n",nexton,nextoff,1.0/kon,1.0/koff,omp_get_thread_num()); /*start of the main loop*/ for (i=0;i<totaltime;i=i+0.01){ clock_t t2 = clock(); //printf("thread=%d i=%f\n",omp_get_thread_num(),i); /*before anything else, make a copy of the current lanes into * the matrix newlanes*/ memcpy(newlanes,lanes,sizeof(lanes)); newends=ends; /*calculate the current coverage (sites occupied divided by the * total number of sites) and output to file the current "time" * and coverage*/ coverage=0; for (k=0;k<NLANES;k++){ for (j=1;j<lanes[k][0]+1;j++){ coverage=coverage+lanes[k][j]; } } //printf("total length=%f\n",coverage); coverage=coverage*inv_sites; //printf("coverage=%f\n",coverage); fprintf(fp, "%f %f %f\n", i,coverage,ends,(double)(t2-t1)/CLOCKS_PER_SEC); //printf("%f %f\n",i,coverage); //printf("i=%f nexton=%f nextoff=%f type=%d\n",i,nexton,nextoff,type); /*tests for events, with priority for polymerizing - if both * are due, it will polymerize first and only depol in the next * timestep*/ if (i>=nextoff){ type=2;} if (i>=nexton){ type=1; } /*we will now calculate the number of filaments and constraints * in the system, going over each lane - relatively * straightforward!*/ filaments=0; noconsts=0; for (k=0;k<NLANES;k++){ //printf("according to main, %d filaments in lane %d\n",newlanes[k][0],k); filaments=filaments+newlanes[k][0]; noconsts=noconsts+2*newlanes[k][0]; if (newlanes[k][0]>1){ noconsts=noconsts+newlanes[k][0]; } } /*polymerization event!*/ if (type==1){ /*big legacy stuff - leave it alone!*/ //printf("lanes at beginning: filaments=%d noconsts=%d\n",filaments,noconsts); //for (k=0;k<NLANES;k++){ //printf("lane %d: ",k); //for (j=1;j<lanes[k][0]+1;j++){ //printf("%d ",lanes[k][j]); //} //printf("\n"); //} //if (i>0) count(states,argc, argv, lanes, filaments, noconsts); //gmp_printf("%Zd\n",states); /*sample exponential to get the size of the filament to be * added (integer exponential is geometric!)*/ size=gsl_ran_geometric(r,p); /*pick a lane at random to add the new filament*/ /*parentheses: in the system without stickers, as long as * this step of random sampling doesn't change, we're fine - * order inside lane doesn't really matter!*/ j=gsl_rng_uniform_int(r,NLANES); /*calculate the current number of filaments and occupied * length in the chosen lane*/ currfils=lanes[j][0]; currlen=0; for (k=1;k<currfils+1;k++){ currlen=currlen+lanes[j][k]; } //printf("currlen %d currfils %d\n",currlen,currfils); /*test if there's enough space to insert the new filament*/ if (currlen+currfils+size+2>L) continue; /*if there is, pick a "gap" to insert the filament in * (i.e. the place in the order of filaments of that lane)*/ else{ gap=1+gsl_rng_uniform_int(r,currfils+1); /*if it's not at the end of the order, need to move the other * ones in the lanes matrix to open space for the new one*/ if (gap!=currfils+1){ for (k=currfils;k>gap-1;k--){ newlanes[j][k+1]=newlanes[j][k]; } } /*insert new filament...*/ newlanes[j][gap]=size; /*...and update the number of filaments in the lane*/ newlanes[j][0]++; } /*calculate number of filaments and constraints for the * newlanes matrix - seems like a waste of a for loop, eh?*/ filaments=0; noconsts=0; for (k=0;k<NLANES;k++){ //printf("according to lanes, %d filaments in lane %d\n",newlanes[k][0],k); filaments=filaments+newlanes[k][0]; noconsts=noconsts+2*newlanes[k][0]; if (newlanes[k][0]>1){ noconsts=noconsts+newlanes[k][0]; } } //printf("lanes after adding: filaments=%d noconsts=%d\n",filaments,noconsts); //printf("proposed change:\n"); //for (k=0;k<NLANES;k++){ //printf("lane %d: ",k); //for (j=1;j<newlanes[k][0]+1;j++){ //printf("%d ",newlanes[k][j]); //} //printf("\n"); //} /*count microstates after addition!*/ count_new(&newstates, newlanes, filaments, noconsts); //fprintf(fp,"count="); //value_print(fp, P_VALUE_FMT, newstates); //fprintf(fp,"\n"); //gmp_printf("states=%Zd\n",states); //gmp_printf("newstates=%Zd\n",newstates); /*calculate delta omega for the addition - chemical potential * plus entropy difference - this should always work since we * set states to 0 in the very first iteration*/ domega=-mu*size-mpzln(newstates)+mpzln(states); //printf("delta omega: %f log10newstates=%f log10states=%f\n",domega, mpzln(newstates),mpzln(states)); /*metropolis test - if delta omega is negative, we accept * the addition*/ if (domega<0){ memcpy(lanes,newlanes,sizeof(lanes)); mpz_set(states,newstates); if (size==1){ ends=ends+1; }else if (size>1){ ends=ends+2; } if (first==1){ first=0; nextoff=gsl_ran_exponential(r,1.0/(koff*ends)); }else{ nextoff=i+gsl_ran_exponential(r,1.0/(koff*ends)); } } /*if it's positive, we calculate the probability of acceptance * and test for it*/ else{ double prob=exp(-1.0*domega); double fromthehat=gsl_rng_uniform(r); //printf("metropolising: rng=%f, prob=%f\n",fromthehat,prob); if (fromthehat<prob){ memcpy(lanes,newlanes,sizeof(lanes)); mpz_set(states,newstates); if (size==1){ ends=ends+1; }else if (size>1){ ends=ends+2; } if (first==1){ first=0; nextoff=gsl_ran_exponential(r,1.0/(koff*ends)); }else{ nextoff=i+gsl_ran_exponential(r,1.0/(koff*ends)); } //printf("accepted anyway!\n"); } } //printf("final result:\n"); //for (k=0;k<NLANES;k++){ //printf("lane %d: ",k); //for (j=1;j<lanes[k][0]+1;j++){ //printf("%d ",lanes[k][j]); //} //printf("\n"); //} /*calculate time of next polymerization event and reset type*/ nexton=nexton+gsl_ran_exponential(r,1.0/kon); //printf("nexton: %f\n",nexton); type=0; } /*Depol event! We need to check for number of filaments here * (note that "filaments" here is the one calculated at the * beginning of the for loop) because if there are no filaments * we just need to recalculate nextoff and keep going*/ if (type==2 && filaments>0){ //printf("entered depol\n"); //printf("filaments: %d\n",filaments); /*this is one of those conditions that shouldn't be necessary, * but I needed to add this at some point and now I'm afraid * to take it out and break the whole thing, so there you go*/ if (i>0 && filaments>0 ) { //count(states,argc, argv, lanes, filaments, noconsts); //gmp_printf("%Zd\n",states); /*pick a filament to decrease size - this will be changed * soon!*/ //j=gsl_rng_uniform_int(r,filaments)+1; //printf("j=%d\n",j); j=gsl_rng_uniform_int(r,ends)+1; //fprintf(fp,"j=%d out of %d\n",j,ends); /*need to replicate the routine below, but with more * intelligence to track ends - maybe create small * test program to try it in isolation?*/ /*go through lanes until you find the filament to be * decreased in size. Then, decrease size by one, check * whether the filament disappeared (in which case following * filaments need to be shifted left and number of filaments * in lane decreased). Finally, break from the for loop*/ int end_counter=0; int doneit=0; for (k=0;k<NLANES;k++){ //fprintf(fp,"k=%d nd_counter=%d, lane has %d filaments\n",k,end_counter,lanes[k][0]); for (l=1;l<lanes[k][0]+1;l++){ if (lanes[k][l]==1){ end_counter=end_counter+1; }else{ end_counter=end_counter+2; } if (j<=end_counter){ //fprintf(fp,"filaments=%d k=%d end_counter=%d thing to change=%d\n",filaments,k,end_counter,newlanes[k][l]); newlanes[k][l]=newlanes[k][l]-1; if (newlanes[k][l]==1){ newends=newends-1; } if (newlanes[k][l]==0){ for (m=l;m<newlanes[k][0];m++){ newlanes[k][m]=newlanes[k][m+1]; } newlanes[k][0]--; newends=newends-1; } doneit=1; break; } } if (doneit==1){ break; } } } //printf("nextoff=%f\n",nextoff); type=0; filaments=0; noconsts=0; for (k=0;k<NLANES;k++){ //printf("according to lanes, %d filaments in lane %d\n",newlanes[k][0],k); filaments=filaments+newlanes[k][0]; noconsts=noconsts+2*newlanes[k][0]; if (newlanes[k][0]>1){ noconsts=noconsts+newlanes[k][0]; } } //printf("rank %d is dumping previous lanes:\n",my_rank); //dump_lanes(lanes); //printf("rank %d is dumping its %d filaments and noconsts %d\n",my_rank,filaments,noconsts); //dump_lanes(newlanes); /*metropolis test should go in here*/ count_new(&newstates, newlanes, filaments, noconsts); //<-segfault is here! //fprintf(fp,"count="); //value_print(fp, P_VALUE_FMT, newstates); //fprintf(fp,"\n"); //gmp_printf("states=%Zd\n",states); //gmp_printf("newstates=%Zd\n",newstates); /*calculate delta omega for the addition - chemical potential * plus entropy difference - this should always work since we * set states to 0 in the very first iteration*/ domega=mu-mpzln(newstates)+mpzln(states); //fprintf(fp,"depol domega=%f, diff in mpzln=%f\n",domega,domega-1); if (domega<0){ memcpy(lanes,newlanes,sizeof(lanes)); mpz_set(states,newstates); ends=newends; } /*if it's positive, we calculate the probability of acceptance * and test for it*/ else{ double prob=exp(-1.0*domega); double fromthehat=gsl_rng_uniform(r); //printf("metropolising: rng=%f, prob=%f\n",fromthehat,prob); if (fromthehat<prob){ memcpy(lanes,newlanes,sizeof(lanes)); mpz_set(states,newstates); } } if (ends>0){ /*recalculate nextoff and reset type*/ nextoff=nextoff+gsl_ran_exponential(r,1.0/(koff*ends)); }else{ nextoff=VERYBIG; //first=1; } /*recalculate the number of filaments and constraints (could * be done more efficiently, but whatever)*/ filaments=0; noconsts=0; for (k=0;k<NLANES;k++){ //printf("according to lanes, %d filaments in lane %d\n",newlanes[k][0],k); filaments=filaments+lanes[k][0]; noconsts=noconsts+2*lanes[k][0]; if (lanes[k][0]>1){ noconsts=noconsts+lanes[k][0]; } //printf("before counting: filaments=%d noconsts=%d\n",filaments,noconsts); } /*recalculate total number of states - this will probably be * part of the Metropolis test further up when this is done*/ count_new(&states, lanes, filaments, noconsts); //fprintf(fp,"count="); //value_print(fp, P_VALUE_FMT, states); //fprintf(fp,"\n"); } /*in case there's nothing to depolimerize, we set nextoff as a big * float and reset the first flag*/ if (type==2 && filaments==0){ nextoff=VERYBIG; //first=1; type=0; } /*also, in any situation where there's no filament in the system, * we set states to zero just to be on the safe side*/ if (filaments==0){ mpz_set_si(states,0);} //else{ ////printf("pass/ng to count: %d %d \n",filaments, noconsts); //count_new(&states,lanes, filaments, noconsts);} ////for (k=0;k<NLANES;k++){ //////printf("lane %d: ",k); ////for (j=1;j<lanes[k][0]+1;j++){ //////printf("%d ",lanes[k][j]); ////} ////printf("\n"); //} //printf("%d %d\n",size,j); //printf("%d %f\n",omp_get_thread_num(),coverage); } /*clearing up - deallocating the arbitrary precision stuff, closing * the I/O file and returning!*/ mpz_clear(states); mpz_clear(newstates); mpz_clear(deltastates); gsl_rng_free (r); fclose(fp); return coverage; }
double test_geometric1 (void) { return gsl_ran_geometric (r_global, 1.0); }
double test_geometric (void) { return gsl_ran_geometric (r_global, 0.5); }