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?
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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.