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

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

?? span_forest.c

?? Computes estimates for the number of forests of a graph, input as a 0-1 incidence matrix. Notes: Com
?? C
字號:
// **********************************************************************
// author   : Alexander Yong
// email    : ayong@umich.edu
// version  : April 30, 2003
// 
// Code for approximating number of spanning forests of a graph, based on
// "Random weighting, asymptotic counting and inverse isoperimetry" by:
// Alexander Barvinok and Alex Samorodnitsky.
//
// Standard Kruskal algorithm implementation.
// **********************************************************************

#include <stdio.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <climits>

const int MAXDIM = 300;            // maximal number of vertices of G
const int MAXEDGES = 10000;        // make at least MAXDIM choose 2
const int MAXIMAL_RAND = RAND_MAX;
const float BIG_NEGATIVE_FOR_NONEDGE = -6789;   
const float SOLVER_ACCURACY = 0.000001;      
const float PI = 3.14159254;

// ----------------------------------------------------------------------
// KRUSKAL'S ALGORITHM FUNCTIONS

int U[MAXDIM];        
int used_nonedge = 0;  

float search(float i){  
  
   int j;

   j = (int)i;
   while (U[j] != j)
      j = U[j];
   return (j);
}

float kruskal(float W[MAXDIM][MAXDIM], int N, int num_edges_forest, int M){
  
   float E[MAXEDGES][3];            // complete set of edges           
   float F[MAXEDGES][3];            // set of edges in max span. forest
   int num_edges = 0;               
   int next_edge = 0;               
   float weight = 0;                
   int i, j, k, q;                     
   float a, b, c;

   // initialize set of edges 
   k = 0;
   for (i = 0; i < N; i++){
     for (j = 0; j < N; j++){
         if (j > i){  
	   E[k][0] = i;          // first vertex of edge 
	   E[k][1] = j;          // second vertex of edge 
	   E[k][2] = W[i][j];    // weight of edge 
           k=k+1;
         }
     }
   }
   
   // bubblesort set of edges in non-increasing order by weight 
   for (i = M - 1; i > 0; i--){
      for (j = 0; j < i; j++){
	 if (E[j][2] < E[j+1][2]){
            a = E[j][0];
            b = E[j][1];
            c = E[j][2];
            E[j][0] = E[j+1][0];
            E[j][1] = E[j+1][1];
            E[j][2] = E[j+1][2];
            E[j+1][0] = a;
            E[j+1][1] = b;
            E[j+1][2] = c;   
         }
     }
   }

   // create N disjoint subsets 
   for(q=0;q<N;q++){
     U[q]=q;
   }

   // initialize set of edges in max. span. forest to empty 
   for (i = 0; i < N - 1; i++){
     for (j = 0; j < 3; j++){
	 F[i][j] = -1;            // -1 denotes empty 
     }
   }

   // find maximal spanning forest
   while (num_edges < num_edges_forest){  
      a = E[next_edge][0];
      b = E[next_edge][1];      
      i = (int)search(a);
      j = (int)search(b);
      
      if(i!=j){
	 if(i<j){
	   U[j]=i;
	 }
	 else{
	   U[i]=j;
	 }
         F[num_edges][0] = E[next_edge][0];
         F[num_edges][1] = E[next_edge][1];
         F[num_edges][2] = E[next_edge][2];
         num_edges=num_edges+1;
      }
      
      next_edge=next_edge+1;
   }
   
   // compute maximal weight and check for use of nonedges
   for (i = 0; i < num_edges_forest; i++){  
      if(F[i][2]!=BIG_NEGATIVE_FOR_NONEDGE){
	weight = weight + F[i][2];
      }
      else{
	used_nonedge=1;
	weight=0;
      }
   }
   return(weight);
}

// Modification of rand(): since problems occur when
// rand() returns 0 or MAXIMAL_RAND
int modified_rand(){

  int temp;

  temp=rand();
  if(temp==0){
    temp=temp+1;
  }
  else if(temp==MAXIMAL_RAND){
    temp=MAXIMAL_RAND-1;
  }
  return(temp);
}

// ---------------------------------------------------------------------
// EXPONENTIAL DISTRIBUTION FUNCTIONS

// Redistribute a point from the uniform distribution
// to the exponential distribution
float random_weight_exp(float x){
 
  float exp_rand;

  // now get the exponential distribution
  if(x<=.5){
    exp_rand=(float)log(2*x);
  }
  else{
    exp_rand=-(float)log(2-2*x);
  }
  return(exp_rand);
}

// h(t) for the exponential distribution
float H_fn_exp(float t){
  float Hoft;

  Hoft= sqrt(1+t*t)+log(sqrt(1+t*t)-1)-2*log(t)+log(2)-1;
  return(Hoft);
}

float upper_exp(float avg_GAMMA, int k){

  float upper_ans;
  
  upper_ans=avg_GAMMA+log(2)*k;
  return(upper_ans);
}

float lower_exp(float avg_GAMMA, int k){

  float lower_ans;
 
  lower_ans=(k-1)*H_fn_exp((float)avg_GAMMA/(k-1));
  return(lower_ans);
}

// -----------------------------------------------------------------------
// LOGISTIC DISTRIBUTION FUNCTIONS

// Redistribute a point from the uniform distribution
// to the logistic distribution
float random_weight_logistic(float x){
 
  float log_rand;

  log_rand=log(x)-log(1-x);
  return(log_rand);
}

// h(t) for the logistic distribution
float 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, num_edges_forest;
    string fileName;
    ifstream inFile;
    int matrix[MAXDIM][MAXDIM];          // vertex 0-1 incidence matrix
    float weights[MAXDIM][MAXDIM];      
    float GAMMA, avg_GAMMA;                         
    float max_weight_forest;
    float upper_bound,lower_bound;
    float prob;
    int m;                               // number of times to sample       
    int complete_num_edges;              // equals (num_vertices choose 2)
    int dist_type;                       // which distribution to use 

    cout << "--------------------------------------------------------------\n";
    cout << "This program takes a given graph G and embeds it into the\n";
    cout << "hypersimplex. It then estimates the number of spanning forests\n";
    cout << "of G by assigning random weights to each edge of G, and\n";
    cout << "applying Kruskal's algorithm to find a maximal weight spanning\n";
    cout << "forest. 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 spanning forests 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 number of edges in the forest.\n";
    cout << "This must be less than the number of vertices.\n";
    cin >> num_edges_forest;

    cout << "Enter the name of the input file:\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 input file:\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];
	}
    }

    cout << "Which distribution?:\n";
    cout << "1. Exponential\n";
    cout << "2. Logistic\n";
    cout << "Enter 1 or 2\n";
    cin >> dist_type;

    while(dist_type!=1 && dist_type!=2){
	cout << "Please choose distribution 1 or 2.\n";
	cin >> dist_type;
    }

    complete_num_edges=(int)(num_vertices)*(num_vertices-1)/2;

    // now sample weights and run Kruskal m times
    GAMMA=0;
    srand((unsigned)time(NULL));
    for(kk=0;kk<m;kk++){
        max_weight_forest=0;

	// randomly weight the edges
        for(ii=0;ii<num_vertices;ii++){
           for(jj=0;jj<num_vertices;jj++){
  	        weights[ii][jj]=0;
	   }
	}
	for(ii=0;ii<num_vertices;ii++){
	  for(jj=0;jj<num_vertices;jj++){
	    if(matrix[ii][jj]==1){
              if(dist_type==1){
	            weights[ii][jj]=random_weight_exp((float)modified_rand()/MAXIMAL_RAND);
              }
              else if(dist_type==2){
                    weights[ii][jj]=random_weight_logistic((float)modified_rand()/MAXIMAL_RAND);
              }
	    }
	    else{
	      weights[ii][jj]=BIG_NEGATIVE_FOR_NONEDGE;  // nonedges get a 
	                                                 // very negative weight
	    }
	  }
	}
    	  
	// Apply Kruskal's algorithm to find the maximal weight 
	// of a spanning forest. Check that nonedges are never used.
     
        max_weight_forest=kruskal(weights,num_vertices,num_edges_forest,complete_num_edges);
        GAMMA=GAMMA+max_weight_forest;
    }

    // Compute the upper and lower estimates
    avg_GAMMA=(float)GAMMA/m;
    if(dist_type==1){
      upper_bound=upper_exp(avg_GAMMA, num_vertices); 
      lower_bound=lower_exp(avg_GAMMA, num_vertices);
    }
    else if(dist_type==2){
      upper_bound=upper_logistic(avg_GAMMA, num_vertices); 
      lower_bound=lower_logistic(avg_GAMMA, num_vertices);
    }

    // Output results
    cout<< "\n";
    cout<< "\n";
    cout<< "-----------------------------------------------------\n";
    if(used_nonedge==1){
      cout<< "The graph was not connected, so no results returned\n";
    }
    else{
      cout << "Bounds for Log(X) are:\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);
    }

}











?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产精品传媒在线观看| 麻豆国产一区二区| 性感美女久久精品| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美性受极品xxxx喷水| 欧美一卡二卡在线观看| 亚洲婷婷在线视频| 国模套图日韩精品一区二区| 欧美中文字幕一区二区三区亚洲| 久久影院电视剧免费观看| 亚洲永久精品大片| 成人激情图片网| 日韩欧美一二三四区| 亚洲大尺度视频在线观看| 不卡的av网站| 久久美女艺术照精彩视频福利播放| 亚洲综合成人网| www.66久久| 久久美女艺术照精彩视频福利播放 | 国产乱码精品一区二区三| 欧美三级电影一区| 亚洲欧美二区三区| 波多野结衣中文字幕一区| www国产精品av| 精品在线播放免费| 日韩久久免费av| 五月天亚洲精品| 欧美日韩一级片网站| 亚洲乱码日产精品bd| 99国产欧美另类久久久精品| 国产精品视频免费看| 成人爽a毛片一区二区免费| 久久人人97超碰com| 国产麻豆午夜三级精品| 久久综合精品国产一区二区三区| 日韩精品视频网站| 4438x亚洲最大成人网| 日韩主播视频在线| 日韩午夜小视频| 久久91精品久久久久久秒播| 精品国精品自拍自在线| 狠狠色丁香久久婷婷综合_中| 日韩欧美国产高清| 国内精品免费**视频| 国产视频一区在线播放| 成人h精品动漫一区二区三区| 中文av一区特黄| 99热在这里有精品免费| 一区二区三区中文字幕电影| 欧美性受xxxx| 蜜臀av性久久久久av蜜臀妖精 | 日韩影院免费视频| 91精品综合久久久久久| 激情综合色综合久久综合| www国产成人| 99re视频精品| 亚洲成人自拍偷拍| 精品嫩草影院久久| 成人在线视频首页| 亚洲午夜在线视频| 欧美一区二区精美| 丰满白嫩尤物一区二区| 亚洲乱码国产乱码精品精可以看| 欧美日韩免费观看一区三区| 久久99精品久久久久久久久久久久| 日韩美女主播在线视频一区二区三区| 精彩视频一区二区三区| 亚洲欧美日韩国产综合在线 | 色88888久久久久久影院按摩| 午夜私人影院久久久久| 久久精品欧美日韩精品 | 国产精品久久久久久久岛一牛影视| 91视视频在线观看入口直接观看www| 亚洲va天堂va国产va久| 国产午夜亚洲精品不卡| 欧美亚洲高清一区二区三区不卡| 日本成人在线看| 中文字幕一区二区三区乱码在线| 在线播放一区二区三区| 国产91在线看| 日韩精品一区第一页| 国产精品天天看| 欧美一区在线视频| 91麻豆国产精品久久| 免费成人av在线| 一区二区久久久久久| 国产视频一区二区三区在线观看| 欧美日韩性生活| www.在线成人| 国产二区国产一区在线观看| 天堂在线亚洲视频| 一区二区三区在线观看国产| 久久亚洲私人国产精品va媚药| 欧美日韩中文字幕一区二区| 成人av网址在线| 国产乱人伦偷精品视频免下载| 亚洲制服丝袜在线| 亚洲欧洲国产日韩| 国产日韩三级在线| 精品女同一区二区| 欧美浪妇xxxx高跟鞋交| 色哟哟一区二区| caoporn国产精品| 国产成人综合视频| 国内精品伊人久久久久影院对白| 日韩精品一二三区| 亚洲第一电影网| 亚洲一区二区三区四区不卡| 亚洲欧美乱综合| 中文字幕视频一区二区三区久| 国产色产综合色产在线视频 | 国产呦精品一区二区三区网站| 亚洲成人av免费| 亚洲大型综合色站| 亚洲一区在线观看视频| 亚洲综合自拍偷拍| 一区二区三区在线高清| 亚洲免费电影在线| 一区二区三区四区精品在线视频 | 久久久国产精品不卡| 欧美r级电影在线观看| 精品久久久久一区| 精品国产在天天线2019| xnxx国产精品| 中文av一区特黄| 亚洲黄色小说网站| 亚洲高清免费观看| 蜜桃视频第一区免费观看| 久久精品噜噜噜成人88aⅴ| 久久99热这里只有精品| 国内精品国产三级国产a久久| 国产精品99久久久久久久vr| 国产91在线|亚洲| 色老头久久综合| 欧美一区午夜精品| 26uuu另类欧美亚洲曰本| 国产三级久久久| 一区二区三区四区蜜桃| 丝袜美腿亚洲色图| 韩国三级电影一区二区| 风间由美一区二区av101 | 亚洲一区二区综合| 日本亚洲一区二区| 国产成人综合在线| 欧美性猛交xxxx乱大交退制版| 在线观看91av| 国产精品久久久久久久久快鸭| 亚洲综合视频在线观看| 美国十次综合导航| 丁香激情综合五月| 欧美日韩一区二区三区不卡 | 国产精品成人网| 亚洲第一会所有码转帖| 国产乱子伦视频一区二区三区| 99久久婷婷国产综合精品| 欧美另类videos死尸| 中文字幕欧美国产| 亚洲一级在线观看| 国产精品一区久久久久| 91精品办公室少妇高潮对白| 精品国产污污免费网站入口| 亚洲欧洲99久久| 美国三级日本三级久久99| 91色婷婷久久久久合中文| 精品裸体舞一区二区三区| 日韩毛片精品高清免费| 精品中文字幕一区二区| 欧美性生活一区| 中文字幕乱码日本亚洲一区二区| 亚洲成a人片在线不卡一二三区| 国产剧情在线观看一区二区| 欧美中文字幕一区| 国产精品人人做人人爽人人添| 日本午夜一区二区| 91国产丝袜在线播放| 日本一区二区成人| 精品一区二区三区久久| 欧美性xxxxxxxx| 中文字幕日韩一区二区| 国产精品一级在线| 日韩一区二区精品| 亚洲国产精品欧美一二99| www.欧美亚洲| 中文乱码免费一区二区| 国产乱码字幕精品高清av| 欧美一级电影网站| 亚洲高清在线精品| 欧美在线free| 亚洲欧洲综合另类| 97久久精品人人澡人人爽| 国产网站一区二区三区| 国产麻豆日韩欧美久久| 久久久一区二区| 九色综合狠狠综合久久| 欧美mv日韩mv| 欧美a级理论片| 日韩欧美亚洲国产精品字幕久久久 | 国产欧美日韩一区二区三区在线观看| 免费观看30秒视频久久| 日韩女优制服丝袜电影|