Get the current solution before best objective found
AnsweredDear Gurobi team,
I worked with a MILP problem with python using gurobi solver to simulate an energy system. However, the system is so complicated that aftering 2 days of running, the best solution is still not found. Now the gap is stuck at 1.85% (I set MIPGap = 1% for optimizaton) with very low contingency speed. I don't have enough time to run it again aftering modifying anything, so I want to ask if there is a way to get the current solution(values of variables) before it terminates with 1% gap? Now my model would only write and save results after best objective found.
If it is possible, could you give me a guide on how to do it? It is a large-scale problem with many variables in 10080 time steps.
Thanks a lot and I'm looking forward to your reply.
Best,
Jiayin
-
Hi Jiayin,
You should be able to issue a keyboard interrupt, which will tell Gurobi to stop the solve. On my Mac for example the keyboard interrupt is control-C. The solver will be in a state as if it had reached a time limit so you can query the best solution as normal. If you're using a Jupyter Notebook the keyboard interrupt may not work but you can interrupt the kernel via the interface in the notebook and the result should be the same.
I suggest you run a test with our model "glass4.mps" which we distribute with Gurobi. On my mac for example this is located here
/Library/gurobi1002/macos_universal2/examples/data/glass4.mps
You can read it in and solve like this
import gurobipy as gp
m = gp.read("/Library/gurobi1002/macos_universal2/examples/data/glass4.mps")
m.optimize()Try the keyboard interrupt within the first 10 seconds or so, and if it is successful then you can be confident it will work with your model.
- Riley
0 -
Hi Riley,
thanks a lot for your help. Can you tell me how to query the current solutions now? I've interrupted the procedure. I'm not sure if it's possible as the model didn't start to write any file yet. My prints are as follows:
...... ......
H41859 20357 26.1210683 25.64906 1.81% 1155 438054s
41996 20471 26.01770 2379 3794 26.12107 25.64906 1.81% 1156 439928s
H41999 20373 26.1201197 25.64906 1.80% 1156 439935s
H42105 19797 26.1150468 25.64906 1.78% 1154 439970sCutting planes:
Gomory: 308
Cover: 184
Implied bound: 69
Clique: 32
MIR: 3386
Flow cover: 10568
RLT: 8521
Relax-and-lift: 1043Explored 42110 nodes (48885439 simplex iterations) in 440000.40 seconds
Thread count was 4 (of 4 available processors)Solution count 10: 26.115 26.1201 26.1211 ... 26.1243
Solve interrupted
Warning: max constraint violation (9.9999e-05) exceeds tolerance
Best objective 2.611504684425e+01, best bound 2.564906168949e+01, gap 1.7844%Process finished with exit code -1
Is there any commands that can be used in terminal in pycharm?
Best,
Jiayin0 -
Hi Jiayin,
How were you running Python? From a script, or interactively?
- Riley
0
Please sign in to leave a comment.
Comments
3 comments