R TSP包与Concorde

3
我已安装并成功使用了TSP软件包。我从Concorde(TSP/Waterloo)网站下载了所有文件,尝试了不同的版本,甚至提取了所有文件。
我将这些文件放在R工作目录中。最后,当运行concorde_path()时,它能够找到这些文件。然而,当我运行concorde_help()时,我收到了一个错误。
我遇到了cygwin1.dll未找到的错误。因此,我安装了cygwin。但我仍然收到错误信息。我尝试将所有的concorde文件放在cygwin的bin文件夹中(其中cygwin1.dll存放),并将R工作目录和concorde_path()指向那里,但我得到了一个状态123的错误。
我还下载了Concorde Windows应用程序,并且它可以正常工作。我发现另一篇帖子建议必须先让它在R中工作才能使用。
我在Windows下运行R/Rstudio。
感谢您提供的任何建议和帮助。

我想反驳这是一个非常具体的问题。我还说明了我在连接Concorde函数时遇到的问题。它是一个不托管于CRAN上的外部函数,但TSP包可以连接它。我已编辑问题以删除“逐步教程”部分。 - alwayslearningHALP
2个回答

1
我刚刚为TSPMap使其工作,希望能帮到某些人。
Concorde for windows似乎没有与TSP包兼容的命令行接口。这就是Cygwin派上用场的地方,因为该版本的Concorde可以在命令行上工作并与TSP包进行交互。
您真的需要先在cygwin中使其工作。所以您需要启动cygwin控制台。
如果您已经使控制台工作,那么您可以下载和解压缩concorde二进制文件并测试它。只需在cygwin中运行./concorde.exe即可显示程序的帮助信息。
另一个测试是使用以下测试文件,看看是否可以通过concorde运行。
NAME: TEST
TYPE: TSP
DIMENSION: 6
EDGE_WEIGHT_TYPE: EXPLICIT
EDGE_WEIGHT_FORMAT: FULL_MATRIX
EDGE_WEIGHT_SECTION:
0 1 2 1 1 2
1 0 1 2 2 1
2 1 0 1 2 1
1 2 1 0 1 2
1 2 2 1 0 1
2 1 1 2 1 0

一旦在cygwin中使其正常工作,就可以尝试从命令行开始,看看cygwin是否与Windows集成。如果没问题,R就不应该有问题。
如果您的系统能够识别它,此命令应该显示concorde命令行帮助。
t1 <- try(system("c:/cygwin64/home/davisst5/concorde.exe"))
这个测试concorde_path是否有效。
concorde_path("c:/cygwin64/home/davisst5/")
找到:concorde.exe 如果您已经完成了所有这些工作但仍然遇到问题,则可能存在32/64位版本问题,其中R或cygwin以不同的模式运行,无法正确调用对方(这可能是dll问题的源头)。我在64位的RGui和Cygwin中都有64位。我读过的一个教程说,安装32位的cygwin非常重要才能使其工作,所以可能是这个原因。

0

我按照上面“Stephen Davison”给出的答案进行尝试,但是仍然遇到了缺少cygwin1.dll文件的错误。我的C盘中已安装32位的cygwin。我所做的是从C:\cygwin\bin目录下获取cygwin1.dll文件,并将其粘贴到我的R工作目录E:\ RA \ Concorde_Code中。

然后在我安装有64位R-studio的计算机上,我运行了以下代码来检查Concorde是否可用:

concordePath = "E:/RA/Concorde_Code/"
concorde_path(concordePath)

它说以下内容

found: concorde concorde.exe

然后我运行了以下代码

concorde_help()

它给了我以下的输出。
The following options can be specified in solve_TSP with method "concorde" using clo in control:

/Concorde_Code/concorde
Usage: /Concorde_Code/concorde [-see below-] [dat_file]
   -B    do not branch
   -C #  maximum chunk size in localcuts (default 16)
   -d    use dfs branching instead of bfs
   -D f  edgegen file for initial edge set
   -e f  initial edge file
   -E f  full edge file (must contain initial edge set)
   -f    write optimal tour as edge file (default is tour file)
   -F f  read extra cuts from file
   -g h  be a grunt for boss h
   -h    be a boss for the branching
   -i    just solve the blossom polytope
   -I    just solve the subtour polytope
   -J #  number of tentative branches
   -k #  number of nodes for random problem
   -K h  use cut server h
   -M f  master file
   -m    use multiple passes of cutting loop
   -n s  problem location (just a name or host:name, not a file name)
   -o f  output file name (for optimal tour)
   -P f  cutpool file
   -q    do not cut the root lp
   -r #  use #x# grid for random points, no dups if #<0
   -R f  restart file
   -s #  random seed
   -S f  problem file
   -t f  tour file (in node node node format)
   -u v  initial upperbound
   -U    do not permit branching on subtour inequalities
   -v    verbose (turn on lots of messages)
   -V    just run fast cuts
   -w    just subtours and trivial blossoms
   -x    delete files on completion (sav pul mas)
   -X f  write the last root fractional solution to f
   -y    use simple cutting and branching in DFS
   -z #  dump the #-lowest reduced cost edges to file xxx.rcn
   -N #  norm (must specify if dat file is not a TSPLIB file)
         0=MAX, 1=L1, 2=L2, 3=3D, 4=USER, 5=ATT, 6=GEO, 7=MATRIX,
         8=DSJRAND, 9=CRYSTAL, 10=SPARSE, 11-15=RH-norm 1-5, 16=TOROIDAL
         17=GEOM, 18=JOHNSON

这证实了Concorde已经正确安装并且正常工作。

安装完成后,我运行了TSP代码来检查Concorde的工作情况,使用以下代码:

tour_test <- solve_TSP(tsp_test, method = "concorde")

现在它正常工作了。我得到了以下输出

Used control parameters:
clo  =  
exe  =  E:\RA\Concorde_Code\/concorde
precision    =  6
verbose  =  TRUE
keep_files   =  FALSE
/Concorde_Code/concorde -x -o file225841777aa0.sol file225841777aa0.dat
Host: Pasha  Current process id: 1193
Using random seed 1586547969
Problem Name: TSP
Generated by write_TSPLIB (R-package TSP)
Problem Type: TSP
Number of Nodes: 6
Explicit Lengths (CC_MATRIXNORM)
Optimal Solution: 60000.00
Total Running Time: 0.01 (seconds)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接