Closed cpanse closed 2 years ago
Hi Christian, I replicated your short R code
recmap::recmapGA(recmap::checkerboard(4))
without any issues on my Mac (no M1). Perhaps this is an issue with C++ code via Rcpp.
Luca; it is definitely an issue on the M1 only. C
I experience the same issue on Apple M1 .
Code:
library(igraph)
library(GA)
# TSP problem example this is the data of 21 europian cities
data("eurodist", package = "datasets")
D <- as.matrix(eurodist)
# given a tour, calculate the total distance
tourLength <- function(tour, distMatrix) {
tour <- c(tour, tour[1])
route <- embed(tour, 2)
sum(distMatrix[route])
}
# inverse of thetotal distance is the fitness
tpsFitness <- function(tour, ...) 1/tourLength(tour, ...)
undebug(tourLength)
# run a GA algorithm
GA.fit <- ga(type = "permutation", fitness = tpsFitness, distMatrix = D, lower = 1,
upper = 21, popSize = 100, maxiter = 100, run = 10, pmutation = 0.2)
returns error:
GA | iter = 1 | Mean = 3.196610e-05 | Best = 3.812283e-05
Error in gaperm_oxCrossover_Rcpp(object, parents) : index error
Session info:
R version 4.1.1 (2021-08-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.6
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] igraph_1.2.6 GA_3.2.2 iterators_1.0.13 foreach_1.5.1
loaded via a namespace (and not attached):
[1] compiler_4.1.1 magrittr_2.0.1 cli_3.0.1 tools_4.1.1 crayon_1.4.1 Rcpp_1.0.7 codetools_0.2-18 pkgconfig_2.0.3
The same code works well on linux
some update regarding my example above, using setting:
gaControl("useRcpp" = FALSE)
works fine
Yes of course, this option forces the use of standard R function for the genetic operators. Not using the Rcpp versions you paid a bit in terms of speed but not too much in my experience.
Dear Luca;
I am happy that you provide the GA package.
CRAN reports an index error for my recmap package using GA. Please see: https://www.stats.ox.ac.uk/pub/bdr/M1mac/recmap.out
I also ran into the same error executing the following code snippet
r recmap::recmapGA(recmap::checkerboard(4))
on my brand-new apple M1 device.At the moment it is not urgent but it would be nice to investigate the reason.
Thanks and best wishes,
Christian