double cm(int **adj,int count,int row,int edges) { int **best_community=init_2_matrix(count,row); fill(best_community,-1,count,row); int i; int clu_count[count]; for(i=0;i<count;i++) clu_count[i]=-1; for(i=0;i<row;i++){ int ran_des=rand()%count; best_community[ran_des][clu_count[ran_des]+1]=i; clu_count[ran_des]++; } int **community=init_2_matrix(count,row); copy_2_matrix(best_community,community,count,row); //print_2_matrix(community,count,row); double Q_max=Calculate_Q(adj,community,count,row,edges); int loop_count=row*1000; for(i=0;i<loop_count;i++){ int from=rand()%count; int dest=rand()%count; int fromindex=rand()%(clu_count[from]+1); if(from!=dest&&clu_count[dest]<row-1&&clu_count[from]>0){ community[dest][clu_count[dest]+1]=community[from][fromindex]; community[from][fromindex]=-1; int j; for(j=fromindex;j<=clu_count[from];j++) community[from][j]=community[from][j+1]; double Q_tmp=Calculate_Q(adj,community,count,row,edges); //printf("%f ",Q_tmp); if(Q_tmp>Q_max){ Q_max=Q_tmp; clu_count[from]--; clu_count[dest]++; copy_2_matrix(community,best_community,count,row); } else copy_2_matrix(best_community,community,count,row); } } print_2_matrix(best_community,count,row); free_2_matrix(community,count); free_2_matrix(best_community,count); return Q_max; }
double GN(int **adj,int **best_community,int count,int row2,int edge) { int vertices=row2; int edges=edge; double **deleted_edge=zeros_double(edges,3); int deleted_edge_number=0; int **community=init_2_matrix(count,vertices);//! int x,y; for(x=0;x<count;x++) for(y=0;y<vertices;y++) community[x][y]=-1; int **best_matrix=zeros(vertices,vertices); int *community_number=init_matrix(edges); int number_community=0; int k_max=0; double q_max=INT_MIN*1.0; int edges_copy=edges; int **edges_array=zeros(edges*2,2); int **tri_edges=zeros(edges,2); int *number_tri_row=init_matrix(vertices); int *number_row=init_matrix(vertices); int row=0,step=0,tri_step=0; int **matrix=init_2_matrix(row2,row2); copy_2_matrix(adj,matrix,row2,row2); while(row<vertices){ int col=0; while(col<vertices){ if(adj[row][col]==1){ edges_array[step][0]=row; edges_array[step][1]=col; step++; if(col>row){ number_tri_row[row]++; tri_edges[tri_step][0]=row; tri_edges[tri_step][1]=col; tri_step++; } number_row[row]++; } col++; } row++; } int num=0; while(edges>0&&num<count-1){//! /* [temp,pos1,pos2,pos] = G_N4(edges_array,tri_edges,number_row,number_tri_row,vertices, edges*2);*/ int pos,pos1,pos2; double *temp=G_N4(edges_array,tri_edges,number_row,number_tri_row,vertices, edges*2,&pos1,&pos2,&pos); int i; for(i=0;i<3;i++) deleted_edge[deleted_edge_number][i]=temp[i]; matrix[(int)temp[0]][(int)temp[1]]=0; matrix[(int)temp[1]][(int)temp[0]]=0; int **c1=init_2_matrix(edges*2,2); int **c2=init_2_matrix(edges,2); copy_2_matrix(edges_array,c1,edges*2,2); copy_2_matrix(tri_edges,c2,edges,2); edges_array=zeros((edges-1)*2,2); tri_edges=zeros(edges-1,2); int x,y,x2=0,y2=0; for(x=0;x<edges*2;x++){ if(x!=pos1&&x!=pos2){ for(y=0;y<2;y++){ edges_array[x2][y2]=c1[x][y]; y2++; } x2++; y2=0; } } x2=0;y2=0; for(x=0;x<edges;x++){ if(x!=pos){ for(y=0;y<2;y++){ tri_edges[x2][y2]=c2[x][y]; y2++; } x2++; y2=0; } } free_2_matrix(c1,edges*2); free_2_matrix(c2,edges); int min=(int)temp[0]; if(min>(int)temp[1]) min=(int)temp[1]; number_tri_row[min]--; number_row[(int)temp[0]]--; number_row[(int)temp[1]]--; Get_Connected_Number(matrix,vertices,&num,community); //print_2_matrix(community,count,vertices); community_number[deleted_edge_number]=num;//printf("%d\n",num); co++; if(num==count-1){ number_community=num; /*change the community */ P(community,count,vertices); double quantity=Calculate_Q(adj,community,count,vertices,edges_copy); if(quantity>q_max){ q_max=quantity; copy_2_matrix(matrix,best_matrix,vertices,vertices); k_max=num; copy_2_matrix(community,best_community,count,vertices); } print_2_matrix(best_community,count,vertices); } deleted_edge_number++; edges--; } free_2_matrix_double(deleted_edge,edges); free_2_matrix(community,count); free_2_matrix(best_matrix,vertices); free_matrix(community_number); free_2_matrix(edges_array,edges*2); free_2_matrix(tri_edges,edges); free_matrix(number_tri_row); free_matrix(number_row); free_2_matrix(matrix,row2); return q_max; }
int main() { R=287.0; gama=1.4; L=2.5; B=0.1; H=1.5; cfl=0.25; // cout<<"\nGive CFL number ...?"; // cin>>cfl; ReadFolder.append("./Data/"); WriteFolder.append("./Data/"); FILE *final = fopen( "./Data/change.dat","w" ); fclose(final); // cout<<"Give number of cells along x-directions ......?"; // cin>>x_cell; // cout<<"Give number of cells along y-directions ......?"; // cin>>y_cell; // cout<<"Give number of cells along z-directions ......?"; // cin>>z_cell; // x_cell=10; // y_cell=3; // z_cell=10; Read_grid_size(); // Read_grid_size_single(); x_cell+=2; y_cell+=2; z_cell+=2; xy_cell=x_cell*y_cell; xyz_cell=x_cell*y_cell*z_cell; // printf("%i\n",x_cell); // printf("%i\n",xy_cell); // printf("%i\n",xyz_cell); Allocate_Memory(); // Calculate_Nodes(); // Calculate_Nodes_Compression_Ramp(); // Calculate_Nodes_Compression_Expansion_Ramp(); // Calculate_Nodes_Convergent_Duct(); Calculate_Nodes_Circular_Arc(); // Calculate_Nodes_Compression_Ramp_exponential_y(); Calculate_cellcenter(); Calculate_facenormal(); Calculate_cellvolume(); cout<<"Enter number of iterations ...?"; cin>>Iteration; // Iteration=3; int k; // Initial_Condition(); Read_grid_double_output (); for (k=0;k<=Iteration;k++) { Iter=k; if((k%1000)==0) { Write_Timestep(); // Write_First_row (); } Boundary_Conditions_wall (); // Boundary_Conditions_subsonic_wall (); Calculate_Mach (); Calculate_Timestep (); Calculate_dt_min (); Calculate_Q (); Calculate_Fluxvectors (); // Calculate_Q_new (); Calculate_Q_new_avg (); Calculate_Primitive (); Calculate_Change (); // Calculate_error (); // Calculate_error_compression (); Extra_Iterations (); } Write_grid_double_output (); // Write_Timestep(); return 0; }