日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

网络导通概率的研究

發(fā)布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 网络导通概率的研究 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

  最近老師給了一個題目,說是研究一個正常矩陣任意概率置點概率下,雙向導通(x,y)的概率(要求有自然邊界條件,也就是可以從0->length-1),用代碼敲了一下demo,結果發(fā)現(xiàn)有個好有趣的結果:不同大小的矩陣,導通概率從某一個概率上升,點越多,上升程度越快(斜率越大),但是都會在(0.592...,35%個點導通)左右相交,符合ziff論文的結果。

  其實這個結果是統(tǒng)計學的一個結果,不過我們還沒學概率論,這個神奇的結論我還不能證明(不過這個證明也之能證明二維的,對于三維以上只能通過模擬得出)。

  這個結果對于不同的圖都有不同的結果,我模擬的這個是最簡單的圖(自然邊界條件矩形圖)。

  下面是demo,沒有什么特別的算法,也就是DFS稍微優(yōu)化一下。

1 #include <iostream> 2 #include <functional> 3 #include <algorithm> 4 #include <time.h> 5 #define MARTIX_SIZE 256 6 #define NP 6 7 8 using namespace std; 9 10 typedef struct _tempset 11 { 12 bool flag;//是否被訪問過 13 bool dir_x;//規(guī)定x一個方向 14 bool dir_y;//規(guī)定x一個方向 15 bool is_dot;//是否是一個節(jié)點 16 }Set; 17 typedef struct _group 18 { 19 int particle_sum; 20 bool Link_px; 21 bool Link_py; 22 }Group; 23 typedef struct _temp_recur 24 { 25 int x, y, dir; 26 }T_Group; 27 typedef int Position; 28 29 void Inivilize(Set ***const, T_Group **const,Position **const,Position **const); 30 Set **ReFresh_Martix(Set **const, int *const, Position *const, Position *const, int); 31 void Draw_The_Gragh(Set **const); 32 void Destory(Set **const, T_Group *, Position *, Position *); 33 void If_Cls(void); 34 void Show(const int, const int, const int, const double,FILE *); 35 void DFS_Martix(Set **, const int, const int, T_Group *const, Group *, Position *const, Position *const); 36 37 static double poss[NP] = { 0.590, 0.5925, 0.5926, 0.5927, 0.5928, 0.5930}; 38 39 static pair<int,int>direction[4]; 40 41 void Inivilize(Set ***const martix_tmp, 42 T_Group **const G_Stack, Position **const Mark_x, Position **const Mark_y) 43 { 44 /*函數(shù)名: Inivilize 45 *調用者函數(shù): void main(void) 46 *函數(shù)形參: martix_tmp(矩陣指針) 47 G_Stack(偽遞歸棧堆指針) 48 Mark_x,Mark_y(GPA優(yōu)化的斷層標記數(shù)組指針) 49 *函數(shù)功能: 初始化 50 *返回值: 無 51 */ 52 *martix_tmp = (Set **)malloc(sizeof(Set *)*MARTIX_SIZE); 53 Set *Zone = (Set *)malloc(sizeof(Set)*MARTIX_SIZE*MARTIX_SIZE); 54 for (int i = 0; i < MARTIX_SIZE; i++) 55 (*martix_tmp)[i] = &Zone[i*MARTIX_SIZE]; 56 57 *G_Stack = (T_Group *)malloc(sizeof(T_Group)*MARTIX_SIZE*MARTIX_SIZE);//整形最大值 58 *Mark_x = (Position *)malloc(sizeof(Position)*MARTIX_SIZE); 59 *Mark_y = (Position *)malloc(sizeof(Position)*MARTIX_SIZE); 60 61 //............................................... 62 srand((unsigned)time(NULL)); 63 direction[0].first = -1; direction[0].second = 0; 64 direction[1].first = 1; direction[1].second = 0; 65 direction[2].first = 0; direction[2].second = -1; 66 direction[3].first = 0; direction[3].second = 1; 67 } 68 69 Set **ReFresh_Martix(Set **const Martix, int *const sum_particle, 70 Position *const Mark_x, Position *const Mark_y, int k) 71 { 72 /*函數(shù)名: ReFresh_Martix 73 *調用者函數(shù): void main(void) 74 *函數(shù)形參: Martix(矩陣指針) 75 sum_particle(新產生的粒子數(shù)) 76 Mark_x,Mark_y(GPA優(yōu)化的斷層標記數(shù)組指針) 77 k(以第k個概率產生點) 78 *函數(shù)功能: 給矩陣產生點,以及賦值 79 *返回值: Martix(矩陣指針) 80 */ 81 int tmp; 82 memset(Mark_x, 0, sizeof(Position)*MARTIX_SIZE); 83 memset(Mark_y, 0, sizeof(Position)*MARTIX_SIZE); 84 for (int i = 0; i < MARTIX_SIZE; i++) 85 { 86 for (int j = 0; j < MARTIX_SIZE; j++) 87 { 88 tmp = rand(); 89 Martix[i][j].flag = tmp < RAND_MAX * poss[k] ? 1 : 0; 90 Martix[i][j].dir_y = 0; Martix[i][j].dir_x = 0;//強行規(guī)定一個方向 91 Martix[i][j].is_dot = 0; 92 if (Martix[i][j].flag) 93 { 94 (*sum_particle)++; 95 Mark_x[j]++; Mark_y[i]++; 96 Martix[i][j].is_dot = 1; 97 } 98 } 99 } 100 return Martix; 101 } 102 103 void Destory(Set **const Martix, T_Group *G_Stack, Position *Mark_x, Position *Mark_y) 104 { 105 /*函數(shù)名: Destory 106 *調用者函數(shù): void main(void) 107 *函數(shù)形參: Martix(矩陣指針) 108 G_Stack(偽遞歸棧堆指針) 109 Mark_x,Mark_y(GPA優(yōu)化的斷層標記數(shù)組指針) 110 *函數(shù)功能: 銷毀 111 *返回值: 無 112 */ 113 free(Martix[0]);//去掉集體分配的首地址就可以了 114 free(Martix); 115 free(G_Stack);//銷毀遞歸棧堆 116 free(Mark_x); free(Mark_y);//銷毀點集 117 } 118 119 void If_Cls(void) 120 { 121 /*函數(shù)名: If_Cls 122 *調用者函數(shù): void main(void) 123 *函數(shù)形參: 無 124 *函數(shù)功能: 詢問是否清屏 125 *返回值: 無 126 */ 127 char choice; 128 printf("Do you want to clean the screen?(Y or N)"); 129 while (1) 130 { 131 choice = getchar(); 132 if (choice == 'Y') 133 { 134 system("cls"); 135 return; 136 } 137 else if (choice == 'N') 138 return; 139 else 140 { 141 puts("Error Input!Please enter again!\n"); 142 fflush(stdin); 143 } 144 } 145 } 146 147 void Show(const int k, const int link_group_sum, const int loop, const double max_poss, FILE *fp) 148 { 149 /*函數(shù)名: Show 150 *調用者函數(shù): void main(void) 151 *函數(shù)形參: k(以第k個概率產生點) 152 link_group_sum(聯(lián)通集團個數(shù)) 153 loop(循環(huán)次數(shù)) 154 max(聯(lián)通最大點個數(shù)) 155 p_sum(所有聯(lián)通集團的粒子總數(shù)) 156 fp(指向data.txt的文件指針) 157 *函數(shù)功能: 顯示當前概率集團信息,并且把數(shù)據(jù)寫入data.txt中 158 *返回值: 無 159 */ 160 puts("===============================================================================\n"); 161 printf("\a%cEcho %d:\nPossibility of %.4f\nThe linked graphs` sum is %d\nAccount for %.2f%% in %d graghs\n", 162 16, k + 1, poss[k], link_group_sum, 100 * (double)link_group_sum / (double)loop, loop); 163 printf("The possibility of(max linked points/sum points)accounts for %.2f%%\n", 100 * max_poss); 164 printf("\n"); 165 166 if (fp != NULL) 167 { 168 fprintf(fp, "===============================================================================\n"); 169 fprintf(fp, "%cEcho %d:\nPossibility of %.4f\nThe linked graphs` sum is %d\nAccount for %.2f%% in %d graghs\n", 170 7, k + 1, poss[k], link_group_sum, 100 * (double)link_group_sum / (double)loop, loop); 171 fprintf(fp, "The possibility of(max linked points/sum points)accounts for %.2f%%\n", 100 * max_poss); 172 fprintf(fp, "\n"); 173 } 174 } #include "plug.h"static bool x_full, y_full;int main(void)//森林火災項目的計算連通性的概率 {int loop, sum_particle, link_group_sum, max_particle_sum;double max_poss, poss_tmp; Set **martix = NULL; //矩陣 Group tmp; T_Group *G_Stack; //范圍太大,不用遞歸,手動直接開大棧提高效率Position *Mark_x = NULL, *Mark_y = NULL; //Gpa優(yōu)化標記數(shù)組FILE *fp = NULL; //文件指針//......................................................................................Inivilize(&martix, &G_Stack, &Mark_x, &Mark_y); //初始化while (1){printf("Please enter the times of the loops(The martix`s size is %d*%d)\n(The program will stop until you input zero)\n", MARTIX_SIZE, MARTIX_SIZE);while (1){scanf("%d", &loop);if (loop >= 0)break;puts("DO NOT try to input a negative loop");system("cls");puts("Please enter the time of the loop(break until you input 0)");}if (loop == 0) break;fflush(stdin);puts("The Date will be written in ""data.txt"" in the folder of this program\n");if ((fp = fopen("data.txt", "r")) == NULL)puts("""data.txt"" doesn`t exsit,the program will create a new one\n");fp = fopen("data.txt", "a+");time_t c1 = clock(); //這里先得到一個循環(huán)開始的時間for (int k = 0; k < NP; k++){link_group_sum = 0; max_poss = 0;/*DFS: 遞歸每一個概率,和每一張圖,然后每一個點深度優(yōu)先搜索看是否聯(lián)通*GPA優(yōu)化:如果Mark數(shù)組出現(xiàn)斷層,則此圖一定不連通(x_full和y_full)*/for (int i = 0; i < loop; i++){sum_particle = 0; x_full = 1; y_full = 1; martix = ReFresh_Martix(martix, &sum_particle, Mark_x, Mark_y, k);max_particle_sum = 0;for (int y = 0; y < MARTIX_SIZE && x_full && y_full; y++){for (int x = 0; x < MARTIX_SIZE && x_full && y_full; x++){if (martix[y][x].flag){DFS_Martix(martix, x, y, G_Stack, &tmp, Mark_x, Mark_y);if (tmp.Link_px && tmp.Link_py){link_group_sum++;if (tmp.particle_sum > max_particle_sum)max_particle_sum = tmp.particle_sum;}}}}poss_tmp = (double)max_particle_sum / (double)sum_particle;max_poss = poss_tmp > max_poss ? poss_tmp : max_poss;}Show(k, link_group_sum, loop, max_poss, fp); //聯(lián)通的概率(loop個圖),聯(lián)通的時候最大聯(lián)通集團粒子數(shù) }time_t c2 = clock(); //得到循環(huán)結束的時間(ms)printf("The program has run %lldms\n\n", c2 - c1); fclose(fp); //記得關閉文件流system("pause"); If_Cls(); } Destory(martix, G_Stack, Mark_x, Mark_y); //銷毀棧組 fflush(stdin);system("cls"); system("pause");return 0; }void DFS_Martix(Set **martix, const int st_x, const int st_y, T_Group *const G_Stack, Group *Part_Group, Position *const Mark_x, Position *const Mark_y) {/*函數(shù)名: DFS_Martix*調用者函數(shù): void main(void)*函數(shù)形參: martix(矩陣)st_x,st_y(開始坐標橫縱坐標)G_Stack(偽遞歸棧堆)Part_Group(集團參數(shù)指針)Mark_x,Mark_y(GPA優(yōu)化的斷層標記數(shù)組)*函數(shù)功能: DFS搜索聯(lián)通集團*返回值: 無*/bool If_Push, //出入棧標志if_link_y = 0, if_link_x = 0; //圖是否聯(lián)通標志bool round_dir_x = 0, round_dir_y = 0, //環(huán)圖指向標記:規(guī)定沿著某個軸沿一個方向突然發(fā)生反轉時,某個方向就會被標記1 tmp_dir_x, tmp_dir_y; int dir_tmp, particle_sum = 0, //粒子數(shù)top = 0; //棧頂位 Position dir_x, dir_y;T_Group tmp;//......................................................................................//初始化棧..........martix[st_y][st_x].flag = 0; martix[st_y][st_x].dir_x = 0; martix[st_y][st_x].dir_y = 0;Mark_x[st_x]--; Mark_y[st_y]--;tmp.x = st_x, tmp.y = st_y; tmp.dir = dir_tmp = 0;G_Stack[top++] = tmp; particle_sum++;//.................. Part_Group->Link_px = 0;Part_Group->Link_py = 0;while (top != 0){If_Push = 0;tmp = G_Stack[top - 1]; //讀取棧頂元素,以及棧頂元素環(huán)圖兩個指向標記round_dir_x = martix[tmp.y][tmp.x].dir_x;round_dir_y = martix[tmp.y][tmp.x].dir_y;//每彈出一個點,就把該節(jié)點的x和y做標記,直接從上一個搜索方向之后開始搜索for (int i = dir_tmp; i < 4; i++){dir_x = tmp.x + direction[i].first;tmp_dir_x = (dir_x < 0 || dir_x == MARTIX_SIZE) ? !round_dir_x : round_dir_x;dir_x = (dir_x + MARTIX_SIZE) % MARTIX_SIZE; //循環(huán)坐標 dir_y = tmp.y + direction[i].second;tmp_dir_y = (dir_y < 0 || dir_y == MARTIX_SIZE) ? !round_dir_y : round_dir_y;dir_y = (dir_y + MARTIX_SIZE) % MARTIX_SIZE; //循環(huán)坐標if (martix[dir_y][dir_x].is_dot && !martix[dir_y][dir_x].flag){//如果環(huán)圖指向標記出現(xiàn)相反,則圖已經聯(lián)通if (!if_link_x)if_link_x = martix[dir_y][dir_x].dir_x == tmp_dir_x ? 0 : 1;if (!if_link_y)if_link_y = martix[dir_y][dir_x].dir_y == tmp_dir_y ? 0 : 1;}if (martix[dir_y][dir_x].flag){If_Push = 1;Mark_x[dir_x]--; Mark_y[dir_y]--;round_dir_x = tmp_dir_x; round_dir_y = tmp_dir_y;martix[dir_y][dir_x].flag = 0;martix[dir_y][dir_x].dir_x = round_dir_x; martix[dir_y][dir_x].dir_y = round_dir_y;if (!Mark_x[dir_x]) x_full = 0;if (!Mark_y[dir_y]) y_full = 0;tmp.x = dir_x; tmp.y = dir_y; tmp.dir = i;G_Stack[top++] = tmp; particle_sum++;break;}}dir_tmp = 0; //這里一定要初始化為0,否則接下來的點就無法搜索其他方向if (!If_Push) //如果沒有可以入棧的,那說明開始遞歸了,pop棧頂 {top--;dir_tmp = tmp.dir; //定義為當前點上一次出去的點的方向 }}if (particle_sum >= MARTIX_SIZE){Part_Group->Link_px = if_link_x;Part_Group->Link_py = if_link_y;}Part_Group->particle_sum = particle_sum; }

?

轉載于:https://www.cnblogs.com/Philip-Tell-Truth/p/5060061.html

總結

以上是生活随笔為你收集整理的网络导通概率的研究的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 女人舌吻男人茎视频 | 国产亚洲自拍一区 | 看免费毛片 | 999国产精品视频 | 男人添女人囗交视频 | 亚洲成在线观看 | 亚洲精品av中文字幕在线在线 | 在线看的av网站 | 麻豆影视免费观看 | www久久精品 | 国产亚洲精品久久久久动 | 精品亚洲乱码一区二区 | av中文字幕免费 | 国产一区色 | 亚洲一区二区自拍 | 97福利影院 | 精品国产xxx | 成年人的毛片 | 中文字幕23 | 久久日本视频 | 午夜亚洲一区 | 国产一区二区三区四区三区四 | 精品人妻无码专区在线 | re久久| 寂寞人妻瑜伽被教练日 | 在线观看一区二区三区视频 | 乱岳| 国产成人无码一区二区在线播放 | 欧美激情电影一区二区 | 嫩草99| 爱情岛成人| 影音先锋久久久久av综合网成人 | 精品视频免费 | 免费网站观看www在线观看 | 91精品国产91久久久久久吃药 | 日本午夜免费福利视频 | 5个黑人躁我一个视频 | free性中国hd国语露脸 | 人妻精品一区二区在线 | 美女高潮黄又色高清视频免费 | 麻豆社 | 就操网| 777精品视频| 一炮成瘾1v1高h | 中文字幕综合 | 久久2019| 91久久久久国产一区二区 | 国产欧美激情 | 亚洲AV综合色区无码国产播放 | 久草免费资源 | 国产av剧情一区 | 免费毛片在线 | 免费不卡毛片 | 色在线视频观看 | 国产精品ⅴa有声小说 | 日韩av不卡一区 | 国产拍拍拍拍拍拍拍拍拍拍拍拍拍 | 制服.丝袜.亚洲.中文.综合 | 久久精品无码专区 | 久久久性色精品国产免费观看 | 在线观看无码精品 | 制服.丝袜.亚洲.另类.中文 | 四虎影视成人 | 免费看黄色三级三级 | 综合色爱| 国产精品无码久久久久成人app | 日韩人妻无码精品综合区 | 亚洲av无码专区在线电影 | 国产乱码精品一区二区三 | 亚洲欧美中文字幕 | ass亚洲尤物裸体pics | 已婚少妇美妙人妻系列 | 日韩欧美在线观看一区 | 国产专区一区二区 | 黄色骚视频 | 草草在线影院 | 2019日韩中文字幕mv | 2021中文字幕 | 亚洲六月丁香色婷婷综合久久 | 亚洲精品91天天久久人人 | 久久精品这里只有精品 | 天天曰夜夜操 | 好看的中文字幕电影 | 超碰在线9 | 亚洲AV无码精品色毛片浪潮 | 中文字幕视频免费观看 | 国产成人精品视频ⅴa片软件竹菊 | 91大神一区二区 | 国产成人精品视频在线 | 爽妇网国产精品 | 熟女熟妇伦久久影院毛片一区二区 | 久久久久久av无码免费看大片 | 69色堂 | 国产精品无码白浆高潮 | 在线观看黄av | 亚洲久草视频 | 一区二区三区四区国产精品 | 自偷自拍亚洲 | 欧美日韩一区二区在线 |