Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is not specific to glpk solver, and absence of solutions is serious enough to raise an excepting rather than giving just a warning. Anyway, you can easily catch this exception by enclosing .solve() into try and except like in the example below:

from sage.numerical.mip import MIPSolverException

M = MixedIntegerLinearProgram()
x = M.new_variable()
M.add_constraint(x[0] == 0)
M.add_constraint(x[0] == 1)
try:
    M.solve()
except MIPSolverException:
    print("No feasible solution")

This is not specific to glpk solver, and absence of solutions is serious enough to raise an excepting exception rather than giving just a warning. Anyway, you can easily catch this exception by enclosing .solve() into try and except like in the example below:

from sage.numerical.mip import MIPSolverException

M = MixedIntegerLinearProgram()
x = M.new_variable()
M.add_constraint(x[0] == 0)
M.add_constraint(x[0] == 1)
try:
    M.solve()
except MIPSolverException:
    print("No feasible solution")