Search code examples
rtimeoutlpsolve

how to break lpSolveAPI in R?


In my code I'm running several iterations each of which solves an LP problem using lpSolveAPI. In some cases the LP takes an excessive amount of time, so I want to set a time limit so that I can skip the current iteration and go to the next one.

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

I already tried:

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

and:

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

but in both cases the LPsolver keeps working the same way as if I had not specified a time limit.

What do you suggest?


Solution

  • Per reference manual of lpSolveAPI package, use

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

    The methods you've tried don't work because solve ignores all arguments except the first one, and evalWithTimeout can't interrupt C code.