| Title: | Enumerate Partitions of Grid Graphs |
|---|---|
| Description: | Enumerates polyomino tilings of grid graphs. Partitions an m by n grid into k connected pieces where each piece has a size within given bounds, under rook or queen contiguity rules. A translation of the Julia 'enumerator' package by Schutzman (2019) <doi:10.5281/zenodo.3467675>. |
| Authors: | Christopher T. Kenny [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-9386-6860>), Zachary Schutzman [cph] (Author of the original Julia enumerator) |
| Maintainer: | Christopher T. Kenny <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-05-31 06:18:32 UTC |
| Source: | https://github.com/christopherkenny/enum |
Count the number of valid partitions of an nrow by ncol grid into
num_parts connected pieces. Part sizes can be constrained either as a
range via min_size and max_size, or as an explicit set of allowed sizes
via exact_sizes. Prefer this over enum_partitions() when only the count
is needed, as it avoids storing all partitions in memory.
enum_count_partitions( nrow, ncol, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, contiguity = c("rook", "queen"), progress = TRUE )enum_count_partitions( nrow, ncol, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, contiguity = c("rook", "queen"), progress = TRUE )
nrow |
Integer. Number of rows in the grid. |
ncol |
Integer. Number of columns in the grid. |
num_parts |
Integer. Number of parts to partition the grid into. |
min_size |
Integer or |
max_size |
Integer or |
exact_sizes |
Integer vector or |
contiguity |
Character. Either |
progress |
Logical. Whether to report enumeration progress. Default
|
A single integer giving the number of valid partitions.
# Count partitions of a 2x3 grid into 2 rook-connected parts of size 3 enum_count_partitions(2, 3, num_parts = 2, min_size = 3, max_size = 3) # Count with exact sizes enum_count_partitions(4, 4, num_parts = 3, exact_sizes = c(4, 8))# Count partitions of a 2x3 grid into 2 rook-connected parts of size 3 enum_count_partitions(2, 3, num_parts = 2, min_size = 3, max_size = 3) # Count with exact sizes enum_count_partitions(4, 4, num_parts = 3, exact_sizes = c(4, 8))
Count the number of valid partitions of an arbitrary graph into num_parts
connected subgraphs. Part sizes can be constrained either as a range via
min_size and max_size, or as an explicit set of allowed sizes via
exact_sizes. Prefer this over enum_partitions_graph() when only the
count is needed, as it avoids storing all partitions in memory.
enum_count_partitions_graph( graph, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, progress = TRUE )enum_count_partitions_graph( graph, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, progress = TRUE )
graph |
An |
num_parts |
Integer. Number of parts to partition the graph into. |
min_size |
Integer or |
max_size |
Integer or |
exact_sizes |
Integer vector or |
progress |
Logical. Whether to report enumeration progress. Default
|
A single integer giving the number of valid partitions.
g <- igraph::make_ring(6) enum_count_partitions_graph(g, num_parts = 2, min_size = 3, max_size = 3)g <- igraph::make_ring(6) enum_count_partitions_graph(g, num_parts = 2, min_size = 3, max_size = 3)
Enumerate all partitions of an nrow by ncol grid into num_parts
connected pieces. Part sizes can be constrained either as a range via
min_size and max_size, or as an explicit set of allowed sizes via
exact_sizes. Exactly one of these two forms must be supplied.
enum_partitions( nrow, ncol, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, contiguity = c("rook", "queen"), file = NULL, progress = TRUE )enum_partitions( nrow, ncol, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, contiguity = c("rook", "queen"), file = NULL, progress = TRUE )
nrow |
Integer. Number of rows in the grid. |
ncol |
Integer. Number of columns in the grid. |
num_parts |
Integer. Number of parts to partition the grid into. |
min_size |
Integer or |
max_size |
Integer or |
exact_sizes |
Integer vector or |
contiguity |
Character. Either |
file |
Character or |
progress |
Logical. Whether to report enumeration progress. Default
|
When file is NULL (default), an integer matrix where each column
is a partition and each row corresponds to a cell of the grid in row-major
order. Cell values are integers from 1 to num_parts indicating part
membership. When file is a path, returns the number of partitions
written, invisibly.
# Partition a 2x3 grid into 2 rook-connected parts of size 3 enum_partitions(2, 3, num_parts = 2, min_size = 3, max_size = 3) # Allow only parts of size 4 or 8 (exact sizes) enum_partitions(4, 4, num_parts = 3, exact_sizes = c(4, 8))# Partition a 2x3 grid into 2 rook-connected parts of size 3 enum_partitions(2, 3, num_parts = 2, min_size = 3, max_size = 3) # Allow only parts of size 4 or 8 (exact sizes) enum_partitions(4, 4, num_parts = 3, exact_sizes = c(4, 8))
Enumerate all partitions of an arbitrary graph into num_parts connected
subgraphs. Part sizes can be constrained either as a range via min_size
and max_size, or as an explicit set of allowed sizes via exact_sizes.
Accepts igraph objects and adj objects (1-indexed adjacency lists).
enum_partitions_graph( graph, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, file = NULL, progress = TRUE )enum_partitions_graph( graph, num_parts, min_size = NULL, max_size = NULL, exact_sizes = NULL, file = NULL, progress = TRUE )
graph |
An |
num_parts |
Integer. Number of parts to partition the graph into. |
min_size |
Integer or |
max_size |
Integer or |
exact_sizes |
Integer vector or |
file |
Character or |
progress |
Logical. Whether to report enumeration progress. Default
|
When file is NULL (default), an integer matrix where each column
is a partition and each row corresponds to a vertex (in igraph vertex
order). Cell values are integers from 1 to num_parts indicating part
membership. When file is a path, returns the number of partitions
written, invisibly.
g <- igraph::make_ring(6) enum_partitions_graph(g, num_parts = 2, min_size = 3, max_size = 3)g <- igraph::make_ring(6) enum_partitions_graph(g, num_parts = 2, min_size = 3, max_size = 3)
Read the binary file produced by enum_partitions() or
enum_partitions_graph() when called with the file argument.
enum_read_partitions(file, skip = 0L, n = NULL)enum_read_partitions(file, skip = 0L, n = NULL)
file |
Character. Path to the binary file. |
skip |
Integer. Number of partitions to skip before reading.
Defaults to |
n |
Integer or |
An integer matrix with one row per cell/vertex and one column per
partition read. Cell values are integers from 1 to the number of parts
indicating part membership.
tmp <- tempfile() enum_partitions(3, 3, num_parts = 3, min_size = 3, max_size = 3, file = tmp) enum_read_partitions(tmp) enum_read_partitions(tmp, skip = 5) enum_read_partitions(tmp, skip = 2, n = 3)tmp <- tempfile() enum_partitions(3, 3, num_parts = 3, min_size = 3, max_size = 3, file = tmp) enum_read_partitions(tmp) enum_read_partitions(tmp, skip = 5) enum_read_partitions(tmp, skip = 2, n = 3)