-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import functions from ryser-in-r. (#21)
- Loading branch information
1 parent
1cd54e3
commit 513681e
Showing
14 changed files
with
393 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: keedwell | ||
Title: Latin Squares in R | ||
Version: 0.1.1 | ||
Version: 0.1.1.9000 | ||
Authors@R: | ||
person("Matthew", "Henderson", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0001-7949-8208")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(add_cols) | ||
export(add_rows) | ||
export(create_latin_square) | ||
export(edge_tbl) | ||
export(next_col_matching) | ||
export(next_col_random) | ||
export(next_row) | ||
export(next_row_matching) | ||
export(next_row_random) | ||
export(to_tidygraph) | ||
export(to_tidygraph_2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#' Add new columns to a latin rectangle | ||
#' | ||
#' @param R A latin rectangle | ||
#' @param cols Indices of columns to add | ||
#' @param l_order Dimension of latin square | ||
#' @param strategy Strategy for filling columns | ||
#' | ||
#' @return A latin rectangle | ||
#' @export | ||
add_cols <- function(R, cols, l_order, strategy = next_col_matching) { | ||
|
||
for (i in cols) { | ||
|
||
R <- strategy(R, i, l_order) | ||
|
||
} | ||
|
||
return(R) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#' Matching strategy for adding new columns | ||
#' | ||
#' @param R a latin rectangle | ||
#' @param i column index | ||
#' @param l_order dimension | ||
#' | ||
#' @return a latin rectangle with more columns | ||
#' @export | ||
next_col_matching <- function(R, i, l_order) { | ||
|
||
n_rows <- max(R$row) | ||
n_cols <- max(R$column) | ||
|
||
bg <- to_tidygraph_2(R, l_order, n_rows, n_cols) | ||
|
||
m <- igraph::max_bipartite_match(bg) | ||
|
||
# names of edges in the matching | ||
matching_names <- match(m$matching, names(m$matching)) | ||
|
||
# add a matching indicator to the edges | ||
bg <- bg |> | ||
tidygraph::activate(edges) |> | ||
dplyr::mutate( | ||
matching = to == matching_names[from] | ||
) |> | ||
dplyr::filter(from <= n_rows) | ||
|
||
# just the matching itself, as a graph | ||
mg <- bg |> | ||
tidygraph::activate(edges) |> | ||
dplyr::filter(matching) | ||
|
||
EE <- igraph::ends(mg, igraph::E(mg)) | ||
|
||
R |> | ||
dplyr::bind_rows( | ||
tibble::tibble( | ||
column = rep(i, n_rows), | ||
row = 1:n_rows, | ||
symbol = as.numeric(gsub("s", "", EE[, 2])) | ||
) | ||
) | ||
|
||
} | ||
|
||
#' Random strategy for choosing a new columns | ||
#' | ||
#' @param R a latin rectangle | ||
#' @param i column index | ||
#' @param l_order dimension | ||
#' | ||
#' @return A latin rectangle with more columns | ||
#' @export | ||
next_col_random <- function(R, i, l_order) { | ||
|
||
n_rows <- max(R$row) | ||
n_cols <- max(R$column) | ||
|
||
R |> | ||
dplyr::bind_rows( | ||
tibble::tibble( | ||
column = rep(i, n_rows), | ||
row = 1:n_rows, | ||
symbol = sample(1:l_order, n_rows) | ||
) | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.