diff --git a/R/next-row.R b/R/next-row.R index 7483e36..0c625de 100644 --- a/R/next-row.R +++ b/R/next-row.R @@ -1,42 +1,3 @@ -#' Find a compatible row for extending a latin rectangle -#' -#' Given an input latin rectangle this function will -#' generate a new row that can be added to the latin -#' rectangle. -#' -#' The method used is to create a bipartite graph -#' with vertex partitions for columns and symbols -#' missing from columns and then find a maximum -#' matching in that bipartite graph. -#' -#' @param R A latin square -#' @param l_order The order of the input latin square -#' -#' @return A bipartite graph. -next_row <- function(R, l_order) { - bg <- to_tidygraph(R, l_order) - - 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] - ) - - # just the matching itself, as a graph - mg <- bg |> - tidygraph::activate(edges) |> - dplyr::filter(matching) - - EE <- igraph::ends(mg, igraph::E(mg)) - return(as.numeric(gsub("s", "", EE[,2]))) -} - #' Find a random new row for a latin rectangle #' #' @param R A latin rectangle diff --git a/man/next_row.Rd b/man/next_row.Rd deleted file mode 100644 index 52e896f..0000000 --- a/man/next_row.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/next-row.R -\name{next_row} -\alias{next_row} -\title{Find a compatible row for extending a latin rectangle} -\usage{ -next_row(R, l_order) -} -\arguments{ -\item{R}{A latin square} - -\item{l_order}{The order of the input latin square} -} -\value{ -A bipartite graph. -} -\description{ -Given an input latin rectangle this function will -generate a new row that can be added to the latin -rectangle. -} -\details{ -The method used is to create a bipartite graph -with vertex partitions for columns and symbols -missing from columns and then find a maximum -matching in that bipartite graph. -}