Percolation/Mean cluster density: Difference between revisions

m
Altered code to be more C++ idiomatic.
m (Corrected formatting due to one line length too long.)
m (Altered code to be more C++ idiomatic.)
Line 231:
class Grid {
public:
Grid(const int32_t size, const double probability) {
create_grid(size, probability);
count_clusters();
}
 
int32_t cluster_count() const {
return clusters;
}
 
double cluster_density() const {
return (double) clusters / ( grid.size() * grid.size() );
}
 
void display() const {
for ( uint64_t row = 0; row < grid.size(); row++ ) {
for ( uint64_t col = 0; col < grid.size(); col++ ) {
Line 267:
}
 
void identify_cluster(const uint64_t row, const uint64_t col, const uint64_t count) {
grid[row][col] = count;
if ( row < grid.size() - 1 && grid[row + 1][col] == CLUSTERED ) {
Line 307:
 
Grid grid(size, probability);
printf("%s%d%s%d%s%d%s%s", "This ", size, " by ", size, " grid contains ", grid.cluster_count(), " clusters:", "\n");
"This ", size, " by ", size, " grid contains ", grid.cluster_count(), " clusters:", "\n");
grid.display();
 
908

edits