📜  gurobi 在达到时间限制时获得可行的解决方案 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:02.031000             🧑  作者: Mango

代码示例1
#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)