示例#1
0
 def percolationStats(self):
     for board in range(self.trials):
         percolation = Percolation(self.n, self.n, board)
         print(percolation.n)
         while 1:
             percolation.open(self.randomField(), self.randomField())
             if percolation.percolates():
                 print("Percolates")
                 threshold = percolation.numberOfOpenSites() / (self.n *
                                                                self.n)
                 yield threshold
                 break
示例#2
0
def main():
    L = 20
    trials = 15
    values = []

    for _ in range(trials):
        lattice = Percolation(L)
        sites = list(product(range(L), repeat=2))
        numpy.random.shuffle(sites)

        while not lattice.percolates():
            i, j = sites[0]
            sites.remove(sites[0])
            lattice.open(i, j)
            plot_lattice(lattice, labels=True)

    print(lattice.numberOfOpenSites() / L * L)