Exemplo n.º 1
0
 def callSolver(self, lp, callback=None):
     """Solves the problem with glpk"""
     self.solveTime = -clock()
     glpk.glp_adv_basis(lp.solverModel, 0)
     glpk.glp_simplex(lp.solverModel, None)
     if self.mip and self.hasMIPConstraints(lp.solverModel):
         status = glpk.glp_get_status(lp.solverModel)
         if status in (glpk.GLP_OPT, glpk.GLP_UNDEF, glpk.GLP_FEAS):
             glpk.glp_intopt(lp.solverModel, None)
     self.solveTime += clock()
Exemplo n.º 2
0
    def solve_problem(self, problem, solverConfig):

        if (solverConfig["simplex"] in ["True", "true", "1", "TRUE"]):
            lp_solver_str = "using simplex"
            simplex = True
        else:
            lp_solver_str = "using interior point"
            simplex = False

        if (solverConfig["presolve"] in ["True", "true", "1", "TRUE"]):
            presolv_str = "with ILP presolver"
            lp_solver_str = ""
            presolve = True
        else:
            presolv_str = "no ILP presolver"
            presolve = False

        logging.info("CSR Optimizer solving problem using %s %s", presolv_str,
                     lp_solver_str)

        if (False == presolve):
            if (True == simplex):
                logging.info("CSR Optimizer solving problem using simplex...")
                glpk_lp_param = glpki.glp_smcp()
                glpki.glp_init_smcp(glpk_lp_param)
                glpk_lp_param.msg_lev = glpki.GLP_MSG_OFF
                glpki.glp_simplex(problem, glpk_lp_param)
                res = glpki.glp_get_status(problem)
            else:
                logging.info(
                    "CSR Optimizer solving problem using interior point...")
                glpk_lp_param = glpki.glp_iptcp()
                glpki.glp_init_iptcp(glpk_lp_param)
                glpk_lp_param.msg_lev = glpki.GLP_MSG_OFF
                glpki.glp_interior(problem, glpk_lp_param)
                res = glpki.glp_ipt_status(problem)

            if (res == glpki.GLP_OPT):
                logging.info("Linear optimal")
            else:
                logging.warning("Problem is linear unfeasible")
                return problem

        glpk_ilp_param = glpki.glp_iocp()
        glpki.glp_init_iocp(glpk_ilp_param)

        if (True == presolve):
            glpk_ilp_param.presolve = glpki.GLP_ON
        else:
            glpk_ilp_param.presolve = glpki.GLP_OFF

        glpk_ilp_param.msg_lev = glpki.GLP_MSG_OFF
        glpki.glp_intopt(problem, glpk_ilp_param)
        res = glpki.glp_mip_status(problem)

        if (res == glpki.GLP_OPT):
            logging.info("Integer optimal")
        else:
            logging.warning("Problem is integer unfeasible")
            return problem
        return problem