Skip to content

Commit

Permalink
export applyRandomMutation; applyRandomMutation now also 'forces to b…
Browse files Browse the repository at this point in the history
…ounds'
  • Loading branch information
jakobbossek committed Mar 25, 2021
1 parent 566da45 commit 3e0a62e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -2,6 +2,7 @@

S3method(print,tspgen_collection)
export(addMutator)
export(applyRandomMutation)
export(build)
export(doAxisProjectionMutation)
export(doClusterMutation)
Expand Down
8 changes: 1 addition & 7 deletions R/build.R
Expand Up @@ -28,13 +28,7 @@
#' Instance generation takes place in \eqn{[0,1]^2}. Use \code{upper} to
#' upscale the boundaries, i.e., place nodes in \eqn{[0, upper]^2}.
#' Default is 1.
#' @param bound.handling [\code{character(1)}]\cr
#' Occasionally during instance generation points are moved outside the boundaries
#' of the point space. The parameter \code{bound.handling} determines how to deal
#' with these points. Option \dQuote{uniform} places outliers uniform at random within
#'. the boundaries while option \dQuote{boundary} places them on the corresponding
#' violates boundary/boundaries.
#' Default is \dQuote{uniform}.
#' @template arg_bound_handling
#' @return Either a netgen \code{Network} if \code{return.all = FALSE}, otherwise a
#' list of netgen networks of length \code{iters + 1}.
#' @examples
Expand Down
16 changes: 15 additions & 1 deletion R/collection.R
Expand Up @@ -141,7 +141,15 @@ listToString = function(x, wrap = NULL) {
return(s)
}

applyRandomMutation = function(collection, coords) {
#' Apply a random mutation from a collection.
#'
#' @template arg_collection
#' @param coords [\code{matrix(n, 2)}]\cr
#' Coordinate matrix.
#' @template arg_bound_handling
#' @return [\code{matrix(n, 2)}] Mutated coordinate matrix.
#' @export
applyRandomMutation = function(collection, coords, bound.handling = "boundary") {
checkmate::assertClass(collection, "tspgen_collection")
checkmate::assertMatrix(coords, mode = "numeric", min.rows = 2L, ncols = 2L, any.missing = FALSE, all.missing = FALSE)

Expand All @@ -157,5 +165,11 @@ applyRandomMutation = function(collection, coords) {

# apply mutation
coords = do.call(mutator.fun, mutator.pars)
attr(coords, "df") = NULL

# repair points outside the bounding box
coords = forceToBounds(coords, bound.handling = bound.handling)
# avoid duplicate nodes
coords = relocateDuplicates(coords)
return(coords)
}
7 changes: 7 additions & 0 deletions man-roxygen/arg_bound_handling.R
@@ -0,0 +1,7 @@
#' @param bound.handling [\code{character(1)}]\cr
#' Occasionally during instance generation points are moved outside the boundaries
#' of the point space. The parameter \code{bound.handling} determines how to deal
#' with these points. Option \dQuote{uniform} places outliers uniform at random within
#'. the boundaries while option \dQuote{boundary} places them on the corresponding
#' violates boundary/boundaries.
#' Default is \dQuote{uniform}.
29 changes: 29 additions & 0 deletions man/applyRandomMutation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e0a62e

Please sign in to comment.