Reputation: 433
I'm using the CPLEX solver via PULP in Python. When I solve a problem with time limit, CPLEX prints to the screen the code 107 which means "Time limit exceeded, but integer solution exists". However, if I print the status of pulp.LpStatus[problem.status]
what I get back is the value 1 which according to pulp's documentation means an optimal solution has been found, which is actually wrong.
How can I access the CPLEX status codes instead of PULP's?
Upvotes: 2
Views: 1553
Reputation: 11939
You can directly access CPLEX status code and status string. Consider the following example:
>>> import pulp
>>> prob = pulp.LpProblem("example", pulp.LpMinimize)
>>> x = pulp.LpVariable('x', lowBound=0, upBound=1)
>>> prob+= x <= -1
Example 1 - Time limit exceeded
>>> solver = pulp.CPLEX_PY(msg=0, timeLimit=0)
>>> prob.setSolver(solver)
>>> prob.solve()
-3
>>> solver.solverModel.solution.get_status()
108
>>> solver.solverModel.solution.get_status_string()
'time limit exceeded, no integer solution'
Example 2 - Infeasible
>>> solver = pulp.CPLEX_PY(msg=0)
>>> prob.setSolver(solver)
>>> prob.solve()
-1
>>> solver.solverModel.solution.get_status()
103
>>> solver.solverModel.solution.get_status_string()
'integer infeasible'
Upvotes: 2