R語言環境下,使用tspmeta的concorde方法出現:Can not find executables for concorde or linkern.

完整錯誤提示:Can not find executables for concorde or linkern.Please install the executables or set path manually.

問題:

    在使用R語言的tspmeta包的run_solver()函數時,調用參數method='concorde'時 或者TSP包的concode_path()和concorde_help()函數時,出現的錯誤。

原因:

    查看源代碼裏出現這句錯誤語句的地方

## path
concorde_path <- local({
  .path <- NULL
  function(path){
    if(missing(path)) {
      if(!is.null(.path)) return(.path)
      else {
        ## find concorde and/or linkern
        p <- dirname(Sys.which("concorde"))
        if(p == "") p <- dirname(Sys.which("linkern"))
        if(p == "") stop("Can not find executables for concorde or linkern. Please install the executables or set path manually.")
        return(p)
      }
    } else {
      if(!is.null(path)) {
        path <- normalizePath(path) ### translate all special characters
        ex <- c(list.files(path, pattern = "concorde",
          ignore.case = TRUE),
          list.files(path, pattern = "linkern",
            ignore.case = TRUE))
        if(length(ex) < 1)
          stop(paste("no executable (concorde and/or linkern) found in",
            path))
        cat("found:", ex, "\n")
      }
      .path <<- path

      invisible(.path)

    }
  }
})

    可以看到是 Sys.which('concorde')或者Sys.which(c('concorde'))返回爲空即""。

解決:

    推薦使用WSL Windows內置Linux(當然,Windows下使用Cygwin也可以,ps:自從有了WSL就放棄Cygwin了,現在坐等WSL2和Terminal,Microsoft Opensource Yes)

    Ubuntu下安裝Concorde--最先進的精確TSP求解器網址

    就是簡單的wget下載,然後解壓,然後./configure和make命令(詳細參考Concorde README和安裝指南

mkdir -p ~/src
cd ~/src
wget http://www.math.uwaterloo.ca/tsp/concorde/downloads/codes/src/co031219.tgz
tar xf co031219.tgz
cd co031219
./configure
make

    其他:Windows方法

    然後,將Concorde在Linux下的環境路徑指向concorde_path。

concorde_path(path = '/usr/bin/concorde')

 

備註:

    想使用Windows下WSL的Linux環境,但同時還想在Windows下開發,那就R語言工程化實踐:RStudio Server環境快速配置教程

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章