如何打破 R 中的 lpSolveAPI?

how to break lpSolveAPI in R?

在我的代码中,我 运行 多次迭代,每次迭代都使用 lpSolveAPI 解决了一个 LP 问题。在某些情况下,LP 会花费过多的时间,所以我想设置一个时间限制,以便我可以跳过当前迭代并转到下一个迭代。

for (i in 1:1000)
{
  #create LP model for problem for instance i
  solve(model)
}

我已经试过了:

solve(model,timeout = 10, time_limit = 10)

和:

evalWithTimeout(solve(model), timeout = 10, onTimeout = "error")

但在这两种情况下,LPsolver 都以相同的方式工作,就好像我没有指定时间限制一样。

你有什么建议?

根据 lpSolveAPI 包的 reference manual,使用

lp.control(model, timeout = 10)
status = solve(model)

您尝试过的方法不起作用,因为 solve 会忽略除第一个参数之外的所有参数,并且 evalWithTimeout 无法中断 C 代码。