예제 #1
0
    def _solve_optimization(self, solver: pywraplp.Solver) -> None:
        # The MIP solver is usually fast (milliseconds). If we hit a weird problem,
        # accept a suboptimal solution after 10 seconds.
        solver.SetTimeLimit(10000)
        status = solver.Solve()

        if status == pywraplp.Solver.INFEASIBLE:
            raise Exception("Infeasible problem")
        elif status == pywraplp.Solver.NOT_SOLVED:
            raise Exception("Problem unsolved")
예제 #2
0
    def _solve_optimization(self, solver: pywraplp.Solver) -> bool:
        # The MIP solver is usually fast (milliseconds). If we hit a weird problem,
        # accept a suboptimal solution after 10 seconds.
        solver.SetTimeLimit(10000)
        status = solver.Solve()

        if status == pywraplp.Solver.INFEASIBLE:
            logger.warning("Optimization problem is infeasible")
            return False
        elif status == pywraplp.Solver.NOT_SOLVED:
            logger.warning("Optimization problem could not be solved in time")
            return False

        return True