M ChangeLog => ChangeLog +4 -0
@@ 1,3 1,7 @@
+2021-09-01 Enrico Schumann <es@enricoschumann.net>
+
+ * R/neighbourfun.R (ans): add type "permute"
+
2020-06-05 Enrico Schumann <es@enricoschumann.net>
* R/neighbourfun.R (compare_vectors): simplify
M DESCRIPTION => DESCRIPTION +1 -1
@@ 2,7 2,7 @@ Package: neighbours
Type: Package
Title: Neighbourhood Functions for Local-Search Algorithms
Version: 0.1-0
-Date: 2020-08-02
+Date: 2021-09-01
Maintainer: Enrico Schumann <es@enricoschumann.net>
Authors@R: person(given = "Enrico", family = "Schumann",
role = c("aut", "cre"),
M NEWS => NEWS +1 -1
@@ 1,4 1,4 @@
-v0.1-0 (2020-??-??)
+v0.1-0 (2021-??-??)
o Initial release. The package provides a function
neighbourfun() that constructs neighbourhood
M R/neighbourfun.R => R/neighbourfun.R +20 -0
@@ 118,6 118,26 @@ neighbourfun <- function(min = 0,
return(ans)
}
+ if (type == "permute") {
+
+ if (missing(stepsize) || stepsize == 1L)
+ stepsize <- 2L
+
+ if (stepsize == 2L) {
+ ans <- function(x, ...) {
+ ii <- sample.int(length(x), stepsize)
+ x[ii] <- x[ii[2:1]]
+ x
+ }
+ } else {
+ ans <- function(x, ...) {
+ ii <- sample.int(length(x), stepsize)
+ x[ii] <- x[sample.int(ii)]
+ x
+ }
+ }
+ return(ans)
+ }
if (type == "logical") {