Foggalong / RobustOCS

Robust optimal contirbution selection problems for genetics with Python
https://pypi.org/project/robustocs
MIT License
1 stars 0 forks source link

Overrunning SQP Time Cap #16

Closed Foggalong closed 1 month ago

Foggalong commented 1 month ago

At the moment the SQP time cap is applied to each sub problem, rather than the problem as a whole. It's documented as if intended, but it's only like this because I was lazy when first writing it :sweat_smile:

This is an easy fix, just needs some extra structure set up to keep a running total of how long has been spent in Gurobi/HiGHS.

time_left = T  # limit

for i = 1, ... n
   time_start = Time()
   SQP.solve()
   time_left -= Time()-time_start

   if time_limit < 0:
      break  # timeout
Foggalong commented 1 month ago

As of #26 being merged both Gurobi and HiGHS have time_limit implemented for the full problem not just one iteration. However the HiGHS functions in particular may still overrun the time cap (though nowhere near as dramatically).

See this comment for more information, but essentially there's no way at present through highspy to tell HiGHS it only has $T$ time for a particular h.run(). This means at a given iteration we can't tell HiGHS it only has time_remaining left, only check afterwards whether or not it exceeded that before starting the next iteration.

This does mean that HiGHS will overrun the time cap when reached mid-iteration. Functionality to fix this will be added in HiGHS 2.0, so nought to do on this end until that release.

jajhall commented 1 month ago

You can tell HiGHS that it has only time T for a particular call to 'run()' by setting its time limit before that run to t0+T, where t0 is the HiGHS run time - obtained with the call h.getRunTime() - before the call.

Foggalong commented 1 month ago

Nice, good to know about h.getRunTime(). Will incorporate that now