Example #1
0
void TestMonteCarlo(){
  int size = 5;
  int opensites = 0;
  Percolation* pobj = new Percolation(size);
  pobj->open(7/size,7%size);
  pobj->open(6/size,6%size);
  pobj->open(5/size,5%size);
  
  if( pobj->percolates()){
	  cout<< "percolation started after: " << opensites << "out of " << size * size <<endl;

	}
 
}
Example #2
0
void PercolationStat<GIRD_NUM>::doPercolate(){
    cout << "percolation starts!" << endl;
    for (int i = 0; i < _time; i++){
        Percolation<GIRD_NUM> p;
        int open_num = 0;

        while (!p.percolates() && open_num <= GIRD_NUM * GIRD_NUM){
            int row = rand() % GIRD_NUM;
            int column = rand() % GIRD_NUM;
            if (!p.isOpen(row, column)){
                p.open(row, column);
                open_num ++;
            }
        }

        double fraction = double(open_num) / double(GIRD_NUM * GIRD_NUM);
        _fraction_list.push_back(fraction);
        cout << "fraction=" << fraction << endl;
    }
}
Example #3
0
void  RunMonteCarlo(){
  int size = 10000;
  int opensites = 0;
  Percolation* pobj = new Percolation(size);
  srand((unsigned)time(0));  /* system call should not be inside the loop */
  while(1){
	int sindex = GenerateRandomNumberBetweenRange(0,size*size);
	if(pobj->isOpen(sindex/size,sindex%size)){
	  continue;
	}
	//cout<< "Adding site: " << sindex << " As open" <<endl;
	pobj->open(sindex/size,sindex%size);
	opensites++;
	if(pobj->percolates()){
	  cout<< "percolation started after: " << opensites << "out of " << size * size <<endl;
	  break;
	}
   
  }
	
}