#include #include #include #include const int N = 20; const int L = 2*N; struct Edge { int i; int j; }; void initE(Edge E[L]); void prE(Edge E[L], char* fname); int newp(int p[N+L], int n); int set(int m[N], int e[L], int pa, Edge E[L], int R[N][N]); void init(int p[N+L], int m[N], int e[L], int R[N][N]); void prR(int m[N], Edge E[L], int e[L], char* fname); int ck(int m[N], int R[N][N]); void explore(int i, int m[N], int R[N][N]); int recv(int p[N+L], int m[N], int e[L], int R[N][N], Edge E[L]); double rate(Edge E[L], int suc[N+L], int T); void torus3x3(Edge E[L]); void K_ring_6de(Edge E[L]); void K_ring_4de(Edge E[L]); main() { int ti=time(0); printf("srand=%d\r\n",ti); srand(ti); Edge E[L]; int suc[N+L+1]; int T=50000; char fname[1000]; sprintf(fname,"out-N=%d-L=%d.csv",N,L); FILE *f=fopen(fname,"w"); fprintf(f,",P\r\n"); double maxS=0; double minS=1e10; for(int t=0;t<10000;t++) { if(t==0) K_ring_4de(E); else initE(E); double S=rate(E,suc,T); printf("%2d, %f\r\n",t,S); if(SmaxS) { for(int i=N;i<=N+L;i++) fprintf(f,"%2d, %f\r\n",i,(double)suc[i]/T); fprintf(f,",\r\n"); } if(SmaxS && t>0) { maxS=S; printf("saving the max graph\r\n"); prE(E,"out-maxS.eps"); } } fclose(f); } void K_ring_4de(Edge E[L]) { if(L!=2*N) { initE(E); return; } int G[N][N]; for(int i=0;i=0;i--) { j++; for(;p[j];j++) ; } p[j]=1; return j; } void initE(Edge E[L]) { const int K = N*(N-1)/2; int g[K]; for(int i=0;i=0;i--) { j++; for(;g[j];j++) ; } g[j]=1; } int l=0; for(int k=0;k-1;i++) for(int j=i+1;j-1;j++,n--) { if(n==0) { E[l].i=i; E[l].j=j; l++; } } } } void prE(Edge E[L], char* fname) { const double R = 70; const double r = 7; const double margin = 1; double x[N]; double y[N]; for(int i=0;i