【发布时间】:2018-06-04 11:42:32
【问题描述】:
如果您在C:/OSRM_API5/ 中安装了 OSRM API 版本 5,则下面可重现示例中的以下循环会生成错误(或多或少是随机的。上次我运行代码是在 i=17 时。我们运行了在 3 台不同的笔记本电脑上的代码并获得以下不同的消息:
viaroute5 中的错误(locs$x[i], locs$y[i], locs$x[j], locs$y[j]) :
找不到对象“res”另外:警告消息:1:在 文件(con,“r”):InternetOpenUrl 失败:'Die Serververbindung konnte nicht hergestellt werden。 2:在值[3L]:达到 经过时间限制 [cpu=1s, elapsed=1s]
或
options() 中的错误:已达到已用时间限制另外:警告 消息:在文件中(con,“r”):InternetOpenUrl 失败:'死 Serververbindung konnte nicht hergestellt werden.'
或
粘贴错误("Error in", dcall, ":") : 已达到时间限制
最初我们认为是setWinProgressBar,但现在错误仍然存在,尽管setWinProgressBar 已被注释掉。
有人知道发生了什么或如何追踪此错误吗?
viaroute5 <- function(lat1, lng1, lat2, lng2, instructions) {
address <- "http://localhost:5000"
request <- paste(address, "/route/v1/driving/",
lng1, ",", lat1, ";", lng2, ",", lat2,
"?overview=false", sep = "", NULL)
R.utils::withTimeout({
repeat {
res <- try(
route <- rjson::fromJSON(
file = request))
if (class(res) != "try-error") {
if (!is.null(res)) {
break
} else {
stop("???")
}
}
}
}, timeout = 1, onTimeout = "warning")
if (res$code == "Ok") {
return(res$routes[[1]]$duration)
} else {
t_guess <- 16*60
warning("Route not found: ", paste(lat1, lng1, lat2, lng2, collapse = ", "),
". Time set to ", t_guess/60 , " min.")
}
}
n <- 1e3 # ................................... if set to 10, everything is fine!
locs <- data.frame(x = c(47.424536, 47.427061),
y = c(9.365103, 9.365062), stringsAsFactors = FALSE)
# pb <- winProgressBar(title = "Test",
# label = "0% done", min=0, max=100, initial=0)
wd <- getwd()
setwd("C:/OSRM_API5")
shell(paste0("osrm-routed ", "switzerland-latest.osrm", " >nul 2>nul"), wait = F)
Sys.sleep(3) # OSRM needs time
setwd(wd)
for (i in 1:n) {
print(i)
# info <- paste0("done ", round(i/nrow(locs)*100, 1), "%")
# setWinProgressBar(pb, i/nrow(locs)*100, label = info)
for (j in 1:n) {
viaroute5(locs$x[1], locs$y[1], locs$x[2], locs$y[2])
}
}
shell("TaskKill /F /IM osrm-routed.exe >nul 2>nul")
# close(pb)
评论 1
如果我用一些微不足道的东西替换viaroute5(locs$x[1], locs$y[1], locs$x[2], locs$y[2]),例如i+j 错误消失了(当然)。
评论 2 当我从 `i=17 开始时,它看起来像
[1] 17
Error in file(con, "r") : reached elapsed time limit
Error in file(con, "r") : reached elapsed time limit
[1] 18
[1] 19
[1] 20
[1] 21
[1] 22
[1] 23
[1] 24
Error in readLines(file, warn = FALSE) : reached elapsed time limit
[1] 25
[1] 26
[1] 27
[1] 28
[1] 29
[1] 30
[1] 31
[1] 32
[1] 33
[1] 34
Error in viaroute5(locs$x[1], locs$y[1], locs$x[2], locs$y[2]) :
object 'res' not found
In addition: Warning messages:
1: In file(con, "r") :
InternetOpenUrl failed: 'Die Serververbindung konnte nicht hergestellt werden.'
2: In value[[3L]](cond) : reached elapsed time limit [cpu=1s, elapsed=1s]
【问题讨论】:
标签: r