예제 #1
0
    def reset_basis(self, basis_type='std'):
        'reset initial lp basis'

        if basis_type == 'std':
            glpk.glp_std_basis(self.lp)
        elif basis_type == 'adv':
            glpk.glp_adv_basis(self.lp, 0)
        else:
            assert basis_type == 'cpx'
            glpk.glp_cpx_basis(self.lp)
예제 #2
0
def reset_solver(community):
    """Reset the solver."""
    interface = interface_to_str(community.solver.interface)
    logger.info("resetting solver, hoping for the best.")
    if interface == "cplex":
        logger.warning("switching cplex LP algorithm to `network`.")
        community.solver.configuration.lp_method = "network"
    elif interface == "gurobi":
        community.solver.problem.reset()
    elif interface == "glpk":
        glp_adv_basis(community.solver.problem, 0)
예제 #3
0
def reset_solver(community):
    """Reset the solver."""
    interface = interface_to_str(community.solver.interface)
    logger.info("resetting solver, hoping for the best.")
    if interface == "cplex":
        community.solver.configuration.lp_method = "network"
        community.solver.configuration.lp_method = "barrier"
    elif interface == "gurobi":
        community.solver.problem.reset()
    elif interface == "glpk":
        glp_adv_basis(community.solver.problem, 0)
    elif interface == "osqp":
        community.solver.problem.reset()
예제 #4
0
    def _optimize(self):
        status = self._run_glp_simplex()

        # Sometimes GLPK gets itself stuck with an invalid basis. This will help it get rid of it.
        if status == interface.UNDEFINED and self.configuration.presolve is not True:
            glp_adv_basis(self.problem, 0)
            status = self._run_glp_simplex()

        if status == interface.UNDEFINED and self.configuration.presolve is True:
            # If presolve is on, status will be undefined if not optimal
            self.configuration.presolve = False
            status = self._run_glp_simplex()
            self.configuration.presolve = True
        if self._glpk_is_mip():
            status = self._run_glp_mip()
            if status == 'undefined' or status == 'infeasible':
                # Let's see if the presolver and some scaling can fix this issue
                glp_scale_prob(self.problem, GLP_SF_AUTO)
                original_presolve_setting = self.configuration.presolve
                self.configuration.presolve = True
                status = self._run_glp_mip()
                self.configuration.presolve = original_presolve_setting
        return status
예제 #5
0
    def _optimize(self):
        status = self._run_glp_simplex()

        # Sometimes GLPK gets itself stuck with an invalid basis. This will help it get rid of it.
        if status == interface.UNDEFINED and self.configuration.presolve is not True:
            glp_adv_basis(self.problem, 0)
            status = self._run_glp_simplex()

        if status == interface.UNDEFINED and self.configuration.presolve is True:
            # If presolve is on, status will be undefined if not optimal
            self.configuration.presolve = False
            status = self._run_glp_simplex()
            self.configuration.presolve = True
        if (glp_get_num_int(self.problem) + glp_get_num_bin(self.problem)) > 0:
            status = self._run_glp_mip()
            if status == 'undefined' or status == 'infeasible':
                # Let's see if the presolver and some scaling can fix this issue
                glp_scale_prob(self.problem, GLP_SF_AUTO)
                original_presolve_setting = self.configuration.presolve
                self.configuration.presolve = True
                status = self._run_glp_mip()
                self.configuration.presolve = original_presolve_setting
        return status