//This simulates the TASEP with periodic BC using random sequential update //The generated output file contains profiles at equidistant times //written (in bad style) by Stefan Grosskinsky #include #include #include #include #include #include #define l 200 #define rhol 0.2 #define rhor 0.8 FILE *output_ptr; char *output_file; char dataname[80]; int e[l]; //# of cars, configuration array //int c; //current counter double t; //time counter void init(); void update(); void file(); void output(); int main(void) { int k, delta; int tmeas; time_t t1; (void) time(&t1); srand48((long) t1); //random seed with system time t1 printf("This is a very good traffic model for Q2.3\n OUTPUT FILE CONTAINS CONFIGURATIONS!\n\n"); file(); //creat output file // tequi=l; //set equilibration time tmeas=l; //set waiting time between outputs delta=200; //set number of outputs init(); //initialze system output(); //output initial config for(k=1; krhor ) e[l-1]=0; } } else //bulk event { j=(i+1); if( e[i]*(1-e[j])==1 ) { e[i]=0; //move particle with rate 1 e[j]=1; // c++; //update current counter } } } t+=1./(l+1.); } void file() //create the output file { sprintf(dataname,"traffic_config_l%i.dat",l); output_file = dataname; output_ptr = fopen(output_file,"w"); fclose(output_ptr); } void output() // Output the current configuration { output_ptr = fopen(output_file,"a"); int i; for(i = 0; i < l; i++ ) { fprintf(output_ptr,"%i ",e[i]); } fprintf(output_ptr,"\n"); fclose(output_ptr); }