Reputation: 196
I'm running an optimization problem on Atom, using Julia.
The solver I use is Gurobi:
m=Model(solver=GurobiSolver())
...
solve(m)
My model may need hours to days of computation to reach the optimal value, so I would like to know if I can do the following when solve() is running :
1. Interrupt upon interrupting/stopping Julia
2. Interrupt if the objective function returns a sufficiently good result
3. Interrupt after a set time
and then display and save the current state reached so I can resume the computation later.
Upvotes: 0
Views: 535
Reputation: 33532
That's very broad and misses a lot of details why mentioning things which do not matter (Atom as Editor).
Also: consider this as educated guess.
This should be easily achievable by defining a callback, which goes through your conditions and act according to these (e.g. waiting some seconds or for user-input).
There is one thing to decide on: Gurobi's Callback Codes of types where, which will decide when your callback is called.
For going through your conditions, you will want to use the values for what (see above docs).
Viable candidates:
POLLING 0 Periodic polling callback
MIPSOL 4 Found a new MIP incumbent
Now polling will in general not allow you to query what values. This makes it pretty useless for your task and we won't consider it. The only advantage is that it's probably very frequently called, without a potentially huge variance of times between calls.
MIPSOL would allow you to get access to the interesting variables like MIP_OBJBST (current best objective) and co.
The core assumption here: Gurobi has no callback-timelimit and kills off your callback (safeguard-like). I don't think there is something like that (at least not without a warning in the docs)!
In general, you can't save the whole state of Gurobi (link applies to Gurobi 7). From a software-engineering-based standpoint, it's not too surprising (not impossible, but potentially tricky).
You can turn-off your computer (hibernation!), while solving or while being in some waiting-state in your callback. Now i will say it again: we are talking about Hibernation of Operating-systems. Either a suspend-to-ram (PC will use less energy) or suspend-to-disk (completely off).
Now:
Using callbacks and queries on internal-states as mentioned above, you can use your own kind of serialization to outsource the current best solution and maybe more.
These things, the most important being the MIP start vector you can later use for a completely newly started optimization-process.
You need to decide on how to serialize this data. Database, HDF5, Text-files and co.!
Reading out and Reusing should follow Gurobi's docs.
Now:
Upvotes: 2