gurobi get feasible solution when timelimit reached code example

Example: gurobi get feasible solution when timelimit reached

#Create your problem
P = pulp.LpProblem()

#Build the solverModel for your preferred
solver = getSolver('GUROBI', timeLimit=600)
solver.buildSolverModel(P)


#Solve P
solver.callSolver(P)
solver_model = P.solverModel

# retrieve the objective value of the best integer solution
if solver_model.Status == 2:
	obj_Value = value(P.objective)
elif solver_model.SolCount > 0:  # for the case of MIP
    obj_Value = solver_model.PoolObjVal
else:
     P.roundSolution()
     obj_Value = value(P.objective)

Tags:

Misc Example