Example #1
0
def evaluate(n, p, trials):
    count = 0
    for i in range(trials):
        # Generate one random network.
        isOpen = percolationio.random(n, p)
        percolation.flow(isOpen)
        count += max(percolation.depth_l)
    return 1.0 * count / trials
def main():
    A=perc.make_sites(0.6,25)
    perc.write_grid('sites.txt',A)
    B=perc.read_grid('sites.txt')
    C=perc.flow(B)
    if perc.percolates(C):
        print('percolates')
    else:
        print('does not percolate')
Example #3
0
def main():
    A=perc.make_sites(25,0.45)
    perc.write_grid('sites.txt',A)
    infile=open('sites.txt','r')
    B=perc.read_grid(infile)
    C=perc.flow(B)
    if perc.percolates(C):
        print('percolates')
    else:
        print('does not percolate')
Example #4
0
def main():
    """Test Percolation Vertical."""
    A = perc.make_sites(25, 0.45)
    perc.write_grid('sites.txt', A)
    infile = open('sites.txt', 'r')
    B = perc.read_grid(infile)
    C = perc.flow(B)
    if perc.percolates(C):
        print('percolates')
    else:
        print('does not percolate')
def main():
    A = perc.make_sites(25, 0.65)
    perc.write_grid('test.txt', A)
    infile = open('test.txt', 'r')
    B = perc.read_grid(infile)
    C = perc.flow(B)
    if perc.percolates(C):
        print('percolates')
    else:
        print('does not percolate')

    perc.plot(B, C)
Example #6
0
def main():
    """Test Percolation Vertical."""
    A = perc.make_sites(25, 0.45)
    perc.write_grid('sites.txt', A)
    infile = open('sites.txt', 'r')
    B = perc.read_grid(infile)
    infile.close()
    C = perc.flow(B)
    if perc.percolates(C):
        print('percolates')
    else:
        print('does not percolate')
Example #7
0
def main():
    n = int(sys.argv[1])
    p = float(sys.argv[2])
    trials = int(sys.argv[3])
    for i in range(trials):
        isOpen = percolationio.random(n, p)
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        percolationio.draw(isOpen, False)
        stddraw.setPenColor(stddraw.BLUE)
        full = percolation.flow(isOpen)
        percolationio.draw(full, True)
        stddraw.show(1000.0)
    stddraw.show()
Example #8
0
def main(argv):
    n = int(argv[1])
    p = float(argv[2])
    t = int(argv[3])
    stddraw.createWindow()
    for i in range(t):
        open = percolation.random(n, p)
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        percolation.show(open, False)
        stddraw.setPenColor(stddraw.BLUE)
        full = percolation.flow(open)
        percolation.show(full, True)
        stddraw.sleep(1000)
        stddraw.show()
    stddraw.wait()
Example #9
0
def main():
    # n = int(sys.argv[1])
    # p = float(sys.argv[2])
    # trials = int(sys.argv[3])
    n = 20
    p = .5
    trials = 5
    for i in range(trials):
        isOpen = percolationio.random(n, p)
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        stddraw.setPenRadius(0.005)
        percolationio.draw(isOpen, True)
        stddraw.setPenColor(stddraw.BLUE)
        stddraw.setPenRadius(0.05)
        full = percolation.flow(isOpen)
        percolationio.draw(full, True)
        stddraw.show(1000.0)
    #print('over')
    stddraw.show()