True/False function about the solvability of linear programming

36 views
Skip to first unread message

husi...@gmail.com

unread,
Apr 28, 2019, 8:31:31 AM4/28/19
to sage-support
Hello everyone! I would like to ask a question about the solvability of a linear programming problem.
I use sagemath to check whether my LP problem has any feasible solution or not.
The program is similar to the following one without details
sage: p = MixedIntegerLinearProgram(maximization=False, solver = "PPL")
sage: w = p.new_variable(integer=True, nonnegative=True)
sage: p.set_objective(w[0])

Then I use p.solve() to solve this problem, and when there is no feasible solution, the program will
print out quite a few sentences with the last one like this:
MIPSolverException: PPL : There is no feasible solution

My question is whether I can define a True/False function such that when the LP porble p has any feasible solution,
then it returens True; otherwise it returns False?

Thank you very much for your kind help!

Peter Mueller

unread,
Apr 28, 2019, 1:18:39 PM4/28/19
to sage-support
You can use an exception, something as follows:

def is_lp_solvable(P):
    try:
        P.solve()
        return True
    except:
        return False

husi...@gmail.com

unread,
Apr 29, 2019, 3:33:02 AM4/29/19
to sage-support
Thank you very much for the answer. It works perfectly.

在 2019年4月28日星期日 UTC+2下午7:18:39,Peter Mueller写道:
Reply all
Reply to author
Forward
0 new messages