Solved–Project 1– (Percolation)– Solution

$35.00 $24.00

Percolation Given a composite system comprising of randomly distributed insulating and metallic materials: what fraction of the system needs to be metallic so that the composite system is an electrical conductor? Given a porous landscape with water on the surface (or oil below), under what conditions will the water be able to drain through to…

You’ll get a: . zip file solution

 

 
Categorys:

Description

5/5 – (2 votes)

Percolation Given a composite system comprising of randomly distributed insulating and metallic materials: what fraction of the system needs to be metallic so that the composite system is an electrical conductor? Given a porous landscape with water on the surface (or oil below), under what conditions will the water be able to drain through to the bottom (or the oil to gush through to the surface)? Scientists have de ned an abstract process known as percolation to model such situations.

The Model We model a percolation system using an N-by-N grid of sites. Each site is either open or blocked. A full site is an open site that can be connected to an open site in the top row via a chain of neighboring (left, right, up, down) open sites. We say the system percolates if there is a full site in the bottom row. In other words, a system percolates if we ll all open sites connected to the top row and that process lls some open site on the bottom row. For the insulating/metallic materials example, the open sites correspond to metallic materials, so that a system that percolates has a metallic path from top to bottom, with full sites conducting. For the porous substance example, the open sites correspond to empty space through which water might ow, so that a system that percolates lets water ll open sites, owing from top to bottom.

The Problem In a famous scienti c problem, researchers are interested in the following question: if sites are independently set to be open with probability p (and therefore blocked with probability 1 p), what is the probability that the system percolates? When p equals 0, the system does not percolate; when p equals 1, the system percolates. The plots below show the site vacancy probability p versus the percolation probability for 20-by-20 random grid (left) and 100-by-100 random grid (right).

When N is su ciently large, there is a threshold value p? such that when p < p? a random N-by-N grid almost never percolates, and when p > p?, a random N-by-N grid almost always percolates. No mathematical solution for determining the percolation threshold p? has yet been derived. Your task is to write a computer program to estimate p?.

Problem 1. (Model a Percolation System) To model a percolation system, create a data type Percolation in Percolation.java with the following API:

1 of 4
CS210 Project 1 (Percolation) Swami Iyer

method description

Percolation(int N) create an N-by-N grid, with all sites blocked
void open(int i, int j) open site (i; j)
boolean isOpen(int i, int j) is site (i; j) open?
boolean isFull(int i, int j) is site (i; j) full?
int numberOfOpenSites() number of open sites
boolean percolates() does the system percolate?
Corner cases. By convention, the row and column indices i and j are integers between 0 and N 1, where (0; 0) is the

upper-left site. Throw a java.lang.IndexOutOfBoundsException if any argument to open(), isOpen(), or isFull() is outside its prescribed range. The constructor should throw a java.lang.IllegalArgumentException if N 0.

Performance requirements. The constructor should take time proportional to N2; all methods should take constant time plus a constant number of calls to the union- nd methods union(), find(), connected(), and count().

$ java P e r c o l a t i o n data / input10 . txt 56 open sites

p e r c o l a t e s

$ java P e r c o l a t i o n data / input10 – no . txt 55 open sites

does not p er c ol at e

Problem 2. (Estimate Percolation Threshold) To estimate the percolation threshold, consider the following computational (Monte Carlo simulation) experiment:

Initialize all sites to be blocked.

Repeat the following until the system percolates:

{ Choose a site (row i, column j) uniformly at random among all blocked sites. { Open the site (row i, column j).

The fraction of sites that are opened when the system percolates provides an estimate of the percolation threshold.

For example, if sites are opened in a 20-by-20 grid according to the snapshots below, then our estimate of the percolation threshold is 204/400 = 0.51 because the system percolates when the 204th site is opened.

By repeating this computational experiment T times and averaging the results, we obtain a more accurate estimate of the percolation threshold. Let xt be the fraction of open sites in computational experiment t. The sample mean provides an estimate of the percolation threshold, and the sample standard deviation measures the sharpness of the threshold:

= x1 + x2 + + xT ; 2 = (x1 )2 + (x2 )2 + + (xT)2 :

T T 1

2 of 4
CS210 Project 1 (Percolation) Swami Iyer

Assuming T is su ciently large (say, at least 30), the following provides a 95% con dence interval for the percolation threshold:
h 96 1:96 i:
1p: ; + p
T T

To perform a series of computational experiments, create a data type PercolationStats in PercolationStats.java with the following API:

method description

PercolationStats(int N, int T) perform T independent experiments on an N-by-N grid

double mean() sample mean of percolation threshold
double stddev() sample standard deviation of percolation threshold
double confidenceLow() low endpoint of 95% con dence interval
double confidenceHigh() high endpoint of 95% con dence interval

The constructor should take two arguments N and T , and perform T independent computational experiments (discussed above) on an N-by-N grid. Using this experimental data, it should calculate the mean, standard deviation, and the 95% con dence interval for the percolation threshold.

Corner cases. The constructor should throw a java.lang.IllegalArgumentException if either N 0 or T 0.

$ java P e r c o l a t i o n S t a t s 100 1000

mean = 0.592804

stddev = 0.015764
c o n f i d e n c e L o w = 0.591827

c o n f i d e n c e H i g h = 0.593781

Data The directory data contains some sample les for use with the percolation clients. Associated with most input .txt les are output .png les that show the desired output.

Visualization Clients In addition to the test client in Percolation, we provide two visualization clients that serve as large-scale visual traces. We highly recommend using them for testing and debugging your Percolation data type.

1. The client PercolationVisualizer takes as command-line argument the name of a le specifying the size and open sites of a percolation system, and visually reports if the system percolates or not.

2. The client InteractivePercolationVisualizer constructs an N-by-N percolation system, where N is speci ed as command-line argument, and allows you to interactively open sites in the system by clicking on them and visually inspect if the system percolates or not.

Files to Submit

1. Percolation.java

2. PercolationStats.java

3. report.txt

3 of 4
CS210 Project 1 (Percolation) Swami Iyer

Before you submit:

Make sure your programs meet the input and output speci cations by running the following command on the terminal:

$ python3 r un _ te st s . py -v [ < problems >]

where the optional argument lists the problems (Problem1, Problem2, etc.) you want to test, separated by spaces; all the problems are tested if no argument is given.

Make sure your programs meet the style requirements by running the following command on the terminal:

$ c h e c k _ s t y l e < program >

where is the .java le whose style you want to check.

Make sure your report isn’t too verbose, doesn’t contain lines that exceed 80 characters, and doesn’t contain spelling/grammatical mistakes

Acknowledgements This project is an adaptation of the Percolation assignment developed at Princeton University by Robert Sedgewick and Kevin Wayne.

4 of 4