Ask Your Question
0

Sage9.3 getting MILP model status after solve()

asked 2021-08-12 04:28:15 +0200

Sim gravatar image

I'm using Sage9.3 MixedIntegerLinearProgram. After attempting to solve a milp problem M using M.solve(), when the program stops it could be
- M is solved with solution
- M is infeasible
- timeout (which I have imposed)
- terminated by some external factor

Is there a way (or function) to determine the status of M? I'm using both GLPK and Gurobi, so would appreciate solutions for both solvers. Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-14 07:29:32 +0200

dsejas gravatar image

Hello, @Sim! I don't know about Gurobi, so perhaps its behaviour could be different, but at least with GLPK, you have the following possibilities:

  1. If M has a solution: The instruction M.solve() should show you the optimum value of the objective function. Additionally, you can write M.get_values(x), where x is the family of variables of the MILP, in order to get the values that produce the optimum.
  2. M is infeasible: Sage should show you the message "MIPSolverException: GLPK: Problem has no feasible solution".
  3. Timeout (which you have imposed): Given that you imposed the time restriction, it should be as easy as to add a print statement with a message such as "Time constraint exceeded!"

Concerning the option "terminated by some external factor", it is not clear to me what you mean by "external factor". However, any event I could think of that could fit this description, should be rare enough to not have to worry about it. (Perhaps you could elaborate on this or present a couple of hypothetical examples.)

I hope this helps!

edit flag offensive delete link more

Comments

Hi @dsejas, Thanks for your suggestion.
Terminated by some external factor refers to the program terminating prematurely, e.g. by "Ctrl+c" or "kill" instruction
I'm running the program in the background so currently I'm outputting a log file of the entire solving process and manually check if there is an optimal solution found, infeasible or timeout.
But I would like to automate this process.
An example pseudocode
M.solve() if M is solved:
#output the optimal solution
if M is infeasible:
#output infeasible message
if M is timeout:
#output best upper and lower bound so far
if M is terminated by external factor:
#output best upper and lower bound so far

Sim gravatar imageSim ( 2021-08-18 18:31:29 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-08-12 04:18:10 +0200

Seen: 102 times

Last updated: Aug 14 '21