2016-11-13 28 views
1

在我的代碼中,我運行了幾個迭代,每個迭代使用lpSolveAPI解決LP問題。在某些情況下,LP會花費過多的時間,所以我想設置一個時間限制,以便我可以跳過當前的迭代並轉到下一個迭代。如何破解R中的lpSolveAPI?

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保持,如果我沒有具體的時間限制的工作方式相同。

你有什麼建議?

+0

消除需要花費過多時間的問題。一般來說LP不需要很多時間來解決,除非你有整數限制。我建議你看一下NEOS服務器 –

+0

如果你把這個變成一個完全可重複的例子 –

回答

0

每lpSolveAPI包reference manual,使用

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

你試過沒有工作,因爲解決的方法忽略除了第一個所有參數,並evalWithTimeout不能中斷C代碼。