|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Percolation system using Union-Find. More...
Public Member Functions | |
| PercolationSystem (size_t grid_size) | |
| Create an n×n percolation system with all sites blocked. | |
| void | open (size_t row, size_t col) |
| Open a site at (row, col) and connect to adjacent open sites. | |
| bool | is_open (size_t row, size_t col) const |
| Check if site at (row, col) is open. | |
| bool | is_full (size_t row, size_t col) |
| Check if site at (row, col) is connected to top (is "full") | |
| bool | percolates () |
| Check if system percolates (top connected to bottom) | |
| size_t | number_of_open_sites () const |
| Get number of open sites. | |
| size_t | size () const |
| Get grid size. | |
| double | open_fraction () const |
| Get fraction of open sites. | |
| void | print () const |
| Print the grid (for small grids) | |
Private Member Functions | |
| size_t | virtual_top () const |
| size_t | virtual_bottom () const |
| size_t | index (size_t row, size_t col) const |
| bool | valid (size_t row, size_t col) const |
Private Attributes | |
| size_t | n |
| vector< bool > | open_sites |
| Fixed_Relation | uf |
| size_t | num_open |
Percolation system using Union-Find.
Models an n×n grid where each site can be open or blocked. Uses virtual top and bottom nodes for efficient percolation testing.
Definition at line 221 of file percolation_example.C.
|
inline |
Create an n×n percolation system with all sites blocked.
Definition at line 249 of file percolation_example.C.
Definition at line 234 of file percolation_example.C.
References Aleph::maps(), and n.
Check if site at (row, col) is connected to top (is "full")
Definition at line 301 of file percolation_example.C.
References Fixed_Relation::are_connected(), index(), is_open(), Aleph::maps(), uf, and virtual_top().
Referenced by print().
Check if site at (row, col) is open.
Definition at line 293 of file percolation_example.C.
References index(), Aleph::maps(), open_sites, and valid().
|
inline |
Get number of open sites.
Definition at line 319 of file percolation_example.C.
References num_open.
Open a site at (row, col) and connect to adjacent open sites.
Definition at line 260 of file percolation_example.C.
References index(), is_open(), Fixed_Relation::join(), Aleph::maps(), n, num_open, open_sites, uf, valid(), virtual_bottom(), and virtual_top().
|
inline |
Get fraction of open sites.
Definition at line 329 of file percolation_example.C.
|
inline |
Check if system percolates (top connected to bottom)
Definition at line 311 of file percolation_example.C.
References Fixed_Relation::are_connected(), uf, virtual_bottom(), and virtual_top().
|
inline |
Print the grid (for small grids)
Legend: '#' = blocked, '.' = open but not full, 'O' = full (connected to top)
Definition at line 339 of file percolation_example.C.
References is_full(), is_open(), Aleph::maps(), and n.
|
inline |
Definition at line 240 of file percolation_example.C.
References Aleph::maps(), and n.
|
inlineprivate |
Definition at line 231 of file percolation_example.C.
References n.
Referenced by open(), and percolates().
|
inlineprivate |
Definition at line 230 of file percolation_example.C.
References n.
Referenced by is_full(), open(), and percolates().
|
private |
Definition at line 224 of file percolation_example.C.
Referenced by index(), open(), open_fraction(), print(), size(), valid(), virtual_bottom(), and virtual_top().
|
private |
Definition at line 227 of file percolation_example.C.
Referenced by number_of_open_sites(), open(), and open_fraction().
|
private |
Definition at line 225 of file percolation_example.C.
|
private |
Definition at line 226 of file percolation_example.C.
Referenced by is_full(), open(), and percolates().