亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? permanent.c

?? Computes the permanent of a nonnegative integer matrix. Notes: Compile in C++, "g++ -o permanent per
?? C
字號:
// **********************************************************************// author   : Alexander Yong// email    : ayong@umich.edu// version  : May 1, 2003// Approximates the permanent of a nonnegative integer matrix based on// "Random weighting, asymptotic counting and inverse isoperimetry" by:// Alexander Barvinok and Alex Samorodnitsky//// The LAP code by R. Jonker and A. Volgenant// email: roy_jonker@majiclogic.com// with some minor modifications to handle floating point data, nonedges.// **********************************************************************#include <stdio.h>#include <fstream.h>#include <iomanip.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <string>#include <time.h>#include <climits>const int MAXDIM = 300;            // maximal number of vertices of Gconst int MAXIMAL_RAND = RAND_MAX;const float SOLVER_ACCURACY = 0.000001;     const float PI = 3.14159254;float nonedge_weight;              int used_nonedge = 0;              // flag for using a nonedge//----------------------------------------------------------------------// LAP FUNCTIONSfloat LAP(int dim, float assigncost[MAXDIM][MAXDIM], int rowsol[MAXDIM], 	int colsol[MAXDIM], float u[MAXDIM], float v[MAXDIM]){bool unassignedfound;int i, imin, numfree=0, prvnumfree, f, i0, k, freerow;int pred[MAXDIM], free[MAXDIM];int j, j1, j2, endofpath, last, low, up;int collist[MAXDIM], matches[MAXDIM];float min, umin, h, usubmin, v2;float  d[MAXDIM]; for(i=0; i<dim; i++)  matches[i] = 0;//column reductionfor(j=dim-1; j>=0; j--)//reverse order gives better results  {    min = assigncost[0][j];    imin = 0;    for(i=1; i<dim; i++)      if(assigncost[i][j]<min)	{	  min = assigncost[i][j];	  imin = i;	}    v[j] = min;    if(++matches[imin]==1)      {	rowsol[imin] = j;	colsol[j] = imin;      }    else      colsol[j] = -1;  }//REDUCTION TRANSFERfor(i=0; i<dim; i++)  if(matches[i]==0)    free[numfree++] = i;  else     if(matches[i]==1)      {	j1 = rowsol[i];	min = INT_MAX;	for(j=0; j<dim; j++)	  if(j!=j1)	    if(assigncost[i][j]-v[j] < min)	      min = assigncost[i][j] - v[j];	v[j1] = v[j1] - min;      }  //AUGMENGING ROW REDUCTIONint loopcnt = 0;do  {    loopcnt++;    k=0;    prvnumfree = numfree;    numfree = 0;    while(k<prvnumfree)      {	i = free[k];	k++;		//find min and second min reduced cost over cols	umin = assigncost[i][0] - v[0];	j1 = 0;	usubmin = INT_MAX;	for(j=1; j<dim; j++)	  {	    h = assigncost[i][j] - v[j];	    if(h<usubmin)	      if(h>=umin)		{		  usubmin = h;		  j2 = j;		}	      else		{		  usubmin = umin;		  umin = h;		  j2 = j1;		  j1 = j;		}	  }		i0 = colsol[j1];	if(umin < usubmin)	  //change the reduction of the min col to increase the min	  //reduced cost in the row to the subminimum	  v[j1] = v[j1] - (usubmin - umin);	else	  if(i0>=0)	    {	      j1 = j2;	      i0 = colsol[j2];	    }		//(re)assign i to j1, possibly un-assigning an i0	rowsol[i] = j1;	colsol[j1] = i;		if(i0 >= 0)	  if(umin < usubmin)	    //put in current k, and go back to that k	    //continue augmenting path i - j1 with i0	    free[--k] = i0;	  else	    //no further augmenting reduction possible	    //store i0 in list of free rows for next phase	    free[numfree++] = i0;      }  } while(loopcnt < 2);//AUGMENT SOLUTION for each free rowfor(f=0; f<numfree; f++)  {    freerow = free[f];    //Dijkstra shortest path algorithm    //runs until unassigned column added to shortest path tree    for(j=0; j<dim; j++)      {	d[j] = assigncost[freerow][j] - v[j];	pred[j] = freerow;	collist[j] = j;      }        low = 0;    up = 0;        unassignedfound = false;        do      {	if(up==low)	  {	    last = low - 1;	    	    //scan cols for up...dim-1 to find indices for which new min occurs	    //store these indices between low...up-1 (increasing)	    min = d[collist[up++]];	    for(k=up; k<dim; k++)	      {		j = collist[k];		h = d[j];		if(h<=min)		  {		    if(h<min)//new min		      {			up = low;//restart list at index low			min = h;		      }		    //new index with same min, put on index up, and extend list		    collist[k] = collist[up];		    collist[up++] = j;		  }	      }	    //check if any of the min cols happen to be unassigned	    //if so, we have augmenting path	    for(k=low; k<up; k++)	      if(colsol[collist[k]] < 0)		{		  endofpath = collist[k];		  unassignedfound = true;		  break;		}	  }		if(!unassignedfound)	  {	    //update 'distances' between freerow and all unscanned cols	    j1 = collist[low];	    low++;	    i = colsol[j1];	    h = assigncost[i][j1] - v[j1] - min;	    	    for(k=up; k<dim; k++)	      {		j = collist[k];		v2 = assigncost[i][j] - v[j] -h;		if(v2<d[j])		  {		    pred[j] = i;		    if(v2==min)		      if(colsol[j]<0)			{			  endofpath = j;			  unassignedfound = true;			  break;			}		      else			{			  collist[k] = collist[up];			  collist[up++] = j;			}		    d[j] = v2;		  }	      }	  }      }    while(!unassignedfound);    //update column prices    for(k=0; k<=last; k++)      {	j1 = collist[k];	v[j1] = v[j1] + d[j1] - min;      }        //reset row and col assignments along alternating path    do      {	i = pred[endofpath];	colsol[endofpath] = i;	j1 = endofpath;	endofpath = rowsol[i];	rowsol[i] = j1;      }    while(i!=freerow);  } //calculate optimal cost and check if nonedge usedfloat lapcost = 0;for(i=0; i<dim; i++)  {    j = rowsol[i];    u[i] = assigncost[i][j] - v[j];    if(assigncost[i][j]==nonedge_weight){      used_nonedge=1;    }    lapcost = lapcost + assigncost[i][j];  } return lapcost;}    // ---------------------------------------------------------------------// LOGISTIC DISTRIBUTION FUNCTIONS// Modified rand(), since returning 0 or MAXIMAL_RAND can cause problemsint modified_rand(){  int temp;  temp=rand();  if(temp==0){    temp=temp+1;  }  else if(temp==MAXIMAL_RAND){    temp=MAXIMAL_RAND-1;  }  return(temp);}// Redistributes a point from the uniform distribution to // the logistic distributionfloat random_weight_logistic(float data_point, int aij){   float log_rand,temp_var,temp_var2;  temp_var2=-log(data_point)/aij;  if(temp_var2>0.1){        temp_var=exp(-log(data_point)/aij);        temp_var=temp_var-1;	log_rand=log(temp_var);	log_rand=-log_rand;  }  else{	log_rand=log(aij)-log(log(1/data_point)) - temp_var2/2-(temp_var2)*(temp_var2)/24;  }  if(aij==0){	return(nonedge_weight);  }  else{   return(-log_rand);  }}// h(t) for the logistic distributionfloat H_fn_logistic(float t){  float Hoft;  float interval_range;  float left_point;  float right_point;  float mid_point;  float d1, value1, d2, value2, max_value;  left_point=0;  right_point=1-SOLVER_ACCURACY;  interval_range=2;        while(interval_range>SOLVER_ACCURACY){      mid_point=(left_point+right_point)/2;      d1=(left_point+mid_point)/2;      d2=(right_point+mid_point)/2;      value1=t*d1-log(PI*d1/(sin(PI*d1)));      value2=t*d2-log(PI*d2/(sin(PI*d2)));      		    if(value1>value2){		      right_point=mid_point;		      max_value=value1;		    }		    else{		      left_point=mid_point;		      max_value=value2;		    }		    interval_range=right_point-left_point;  }  Hoft= max_value;  return(Hoft);}float upper_logistic(float avg_GAMMA, int k){  float upper_ans;    upper_ans=avg_GAMMA;  return(upper_ans);}float lower_logistic(float avg_GAMMA, int k){  float lower_ans;   lower_ans=(k-1)*H_fn_logistic((float)avg_GAMMA/(k-1));  return(lower_ans);} // ----------------------------------------------------------------------int main(){using std::string;    long int seed = time(0);             // random seed    int ii,jj,kk;    int num_vertices;    string fileName;    ifstream inFile;    int matrix[MAXDIM][MAXDIM];                     // [a_ij]    float weights[MAXDIM][MAXDIM];                  // weight array matrix    float GAMMA,avg_GAMMA;                             float max_weight_matching;    float upper_bound,lower_bound;    int m;                                          // num. times to sample    float max_weight;    int rowsol[MAXDIM];                          //col matched to row    int colsol[MAXDIM];                          //row matched to col    float u[MAXDIM];                               //dual variable    float v[MAXDIM];                               //dual varuable        cout << "\n\n\n\n";    cout << "--------------------------------------------------------------\n";    cout << "This program takes a given bipartite graph G and embedsit\n";     cout << "into the\n";    cout << "hypersimplex. It then estimates the permanent corresponding \n";    cout << "to G by assigning random weights to each edge of G, and\n";    cout << "applying the Hungarian algorithm to find a maximal weight perfect\n";    cout << "matching. This is done m times and the resulting average estimates\n";    cout << "the function GAMMA. Then upper and lower bounds for the number\n";    cout << "of the permanent  are calculated.\n";    cout << "--------------------------------------------------------------\n\n\n";    cout << "Enter the number of times m to sample:\n";    cin >> m;    cout << "\n";    while(m<=0){       cout << "This number must be greater than zero.\n";       cout << "Enter the number of times m to sample: \n";       cin >> m;       cout << "\n";    }    cout << "Enter the number of vertices in the graph G\n";    cin >> num_vertices;    cout << "\n";    cout << "Enter the name of the file to open:\n";    cin >> fileName;    inFile.open(fileName.c_str(), ios::in);    while(!inFile){       cout << "File open error: '" << fileName << "' ";       cout <<"Try again.\n";       inFile.close();       cout << "Enter the name of the file to open:\n";       cin >> fileName;       inFile.open(fileName.c_str(), ios::in);    }     // read in the matrix from inFile    for(ii=0; ii<num_vertices; ii++){      for(jj=0; jj<num_vertices; jj++){  	   inFile >> matrix[ii][jj];         }    }    // now do the sampling and run LAP m times    GAMMA=0;    srand((unsigned)time(NULL));    for(kk=0;kk<m;kk++){        max_weight_matching=0;        // initialize        for(ii=0;ii<num_vertices;ii++){           for(jj=0;jj<num_vertices;jj++){  	        weights[ii][jj]=0;	   }	}	max_weight=0;	// do the random weighting	for(ii=0;ii<num_vertices;ii++){	  for(jj=0;jj<num_vertices;jj++){	    if(matrix[ii][jj]>0){              weights[ii][jj]=random_weight_logistic((float)modified_rand()/MAXIMAL_RAND,matrix[ii][jj]);	      if(weights[ii][jj]>max_weight){		max_weight=weights[ii][jj];	      }            }  	  }	}	// assign large weight to nonedges	max_weight=max_weight+1;	nonedge_weight=2*num_vertices*max_weight;	for(ii=0;ii<num_vertices;ii++){	  for(jj=0;jj<num_vertices;jj++){	    if(matrix[ii][jj]==0){	      weights[ii][jj]=nonedge_weight;	    }	  }	}    	// Apply the Hungarian algorithm using the LAP code        max_weight_matching=-LAP(num_vertices,weights,rowsol,colsol,u,v);        GAMMA=GAMMA+max_weight_matching;    }    avg_GAMMA=(float)GAMMA/m;    // Compute the upper and lower estimates    upper_bound=upper_logistic(avg_GAMMA, num_vertices);     lower_bound=lower_logistic(avg_GAMMA, num_vertices);    // Output results    printf("\n");    printf("\n");    printf("-----------------------------------------------------\n");    if(used_nonedge==1){      cout<< "No perfect matching was found so the permanent is 0.\n";    }    else{      cout << "Log(X) should be between the following two bounds:\n";      cout << "Upper bound:\n";      printf("%f\n",upper_bound);      cout << "Lower bound:\n";      printf("%f\n",lower_bound);      cout << "GAMMA(X):\n";      printf("%f\n",avg_GAMMA);    }}// end of main()

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色屁屁一区二区| 午夜天堂影视香蕉久久| 狠狠色狠狠色综合| 欧美一区二区日韩一区二区| 亚洲va国产va欧美va观看| 欧美视频三区在线播放| 亚洲观看高清完整版在线观看 | 成人黄色小视频| 国产精品蜜臀在线观看| 91在线观看高清| 一区二区三区中文免费| 久久先锋资源网| 国产不卡视频在线观看| 国产精品久久久久久福利一牛影视| 成人av网站在线观看| 国产精品免费看片| 色综合天天做天天爱| 久久精品在线免费观看| av网站免费线看精品| 亚洲人成小说网站色在线| 卡一卡二国产精品| 久久午夜羞羞影院免费观看| 国产剧情一区二区三区| 亚洲欧美日韩国产一区二区三区| 精品婷婷伊人一区三区三| 日韩高清中文字幕一区| 国产三级欧美三级日产三级99| 国产成+人+日韩+欧美+亚洲| 亚洲丝袜制服诱惑| 7878成人国产在线观看| 国产精品综合二区| 亚洲一区二区三区在线看 | 日韩欧美在线影院| 成人精品高清在线| 婷婷国产在线综合| 欧美国产日本韩| 欧美精品一二三| 国产91精品精华液一区二区三区| 一区二区三区在线视频免费| 精品乱人伦小说| 99久久精品一区二区| 日韩国产欧美在线播放| 中文字幕在线一区免费| 欧美精品乱人伦久久久久久| 国产91富婆露脸刺激对白| 亚洲成人精品影院| 国产精品免费久久久久| 欧美日本一区二区三区四区| 成人午夜激情影院| 日韩电影免费在线看| 国产精品久久久久永久免费观看| 91精品国产综合久久香蕉麻豆| 成人夜色视频网站在线观看| 久久精品国产久精国产| 亚洲国产欧美在线| 亚洲欧美日韩久久| 久久久久一区二区三区四区| 欧美美女激情18p| 一本一道久久a久久精品综合蜜臀| 狠狠色丁香久久婷婷综合_中 | 亚洲乱码日产精品bd| 久久伊人蜜桃av一区二区| 91 com成人网| 精品视频全国免费看| 99综合电影在线视频| 国产乱妇无码大片在线观看| 免费一级欧美片在线观看| 亚洲影院在线观看| 一区二区三区国产豹纹内裤在线| 中文字幕久久午夜不卡| 久久久久久久久免费| 日韩欧美成人激情| 日韩三级视频中文字幕| 7799精品视频| 宅男在线国产精品| 在线成人小视频| 51精品视频一区二区三区| 欧美日韩一本到| 欧美日韩美少妇| 欧美精三区欧美精三区| 欧美日韩国产综合草草| 欧美日韩三级一区| 欧美男人的天堂一二区| 欧美日本一区二区| 日韩一区二区精品葵司在线| 91精品国产乱| 欧美成人精精品一区二区频| 欧美一级一区二区| 欧美成人a∨高清免费观看| 精品久久久久久亚洲综合网| 欧美大片拔萝卜| 精品999在线播放| 久久九九国产精品| 国产精品素人视频| 中文字幕佐山爱一区二区免费| 自拍偷拍亚洲综合| 亚洲一区二区三区美女| 香蕉乱码成人久久天堂爱免费| 亚洲成va人在线观看| 日本欧美在线看| 国产一区二区在线观看免费| 高清国产一区二区三区| 色婷婷亚洲综合| 欧美精品欧美精品系列| wwwwww.欧美系列| 中文字幕+乱码+中文字幕一区| 中文字幕亚洲在| 亚洲成人免费在线观看| 秋霞av亚洲一区二区三| 国产一区二区在线看| 不卡的看片网站| 欧美乱妇20p| 国产无人区一区二区三区| 亚洲美女一区二区三区| 视频一区欧美精品| 国产成人亚洲综合a∨婷婷| 精品福利一区二区三区免费视频| 日韩欧美一区二区在线视频| 国模一区二区三区白浆| 国模冰冰炮一区二区| 本田岬高潮一区二区三区| 欧美丝袜自拍制服另类| 精品美女一区二区| 亚洲免费看黄网站| 精品一区中文字幕| 色婷婷国产精品久久包臀| 精品理论电影在线观看| 亚洲欧美激情在线| 久久99日本精品| 一本色道a无线码一区v| 欧美v亚洲v综合ⅴ国产v| 国产精品福利av| 奇米色一区二区三区四区| 99精品在线免费| 欧美不卡一区二区三区| 樱桃视频在线观看一区| 国产精品一区二区免费不卡| 久久久久久亚洲综合影院红桃| 亚洲女同ⅹxx女同tv| 国产一区不卡精品| 欧美久久久久久蜜桃| 亚洲图片另类小说| 激情成人综合网| 91精品国产综合久久婷婷香蕉| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 日韩欧美国产一区二区在线播放 | 一区在线播放视频| 久久97超碰国产精品超碰| 欧美日韩中文一区| 亚洲精选一二三| 不卡电影一区二区三区| 久久精品亚洲精品国产欧美| 日韩精品一级中文字幕精品视频免费观看 | 国产乱人伦偷精品视频不卡| 91黄色激情网站| 亚洲一区二区视频在线观看| 欧美一区二区国产| 亚洲综合无码一区二区| 不卡视频免费播放| 国产亚洲精品aa| 蜜臀a∨国产成人精品| 欧美日韩在线播放一区| 蜜桃视频在线一区| 日韩午夜小视频| 亚洲一区二区免费视频| 色综合久久久久久久久| 亚洲色图都市小说| av在线播放一区二区三区| 国产精品三级久久久久三级| 国产精品一卡二卡在线观看| 欧美va亚洲va| 精品一区二区三区av| 欧美成人精精品一区二区频| 久久精品国产99久久6| 欧美电影免费观看高清完整版在线观看| 石原莉奈一区二区三区在线观看| 欧美日韩情趣电影| 日韩电影免费在线看| 欧美一级理论性理论a| 蜜臀va亚洲va欧美va天堂| 欧美成人激情免费网| 国产一区二区91| 国产精品久久久久一区二区三区 | 丁香激情综合国产| 亚洲国产精品ⅴa在线观看| 成人91在线观看| 最新久久zyz资源站| 日本韩国欧美在线| 亚洲综合图片区| 欧美一区二区久久| 国产乱人伦偷精品视频免下载| 欧美韩日一区二区三区四区| 不卡一区中文字幕| 亚洲综合视频在线观看| 欧美一卡二卡在线观看| 韩国av一区二区三区四区| 国产精品欧美一区二区三区| 色哟哟一区二区三区| 日一区二区三区| 久久欧美一区二区|