コード例 #1
0
    def _optimize(self):
        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
        self._status = status
        return status
コード例 #2
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
コード例 #3
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
コード例 #4
0
 def value(self):
     if (glp_get_num_int(self.problem.problem) +
             glp_get_num_bin(self.problem.problem)) > 0:
         return glp_mip_obj_val(self.problem.problem)
     else:
         return glp_get_obj_val(self.problem.problem)
コード例 #5
0
 def value(self):
     if (glp_get_num_int(self.problem.problem) + glp_get_num_bin(self.problem.problem)) > 0:
         return glp_mip_obj_val(self.problem.problem)
     else:
         return glp_get_obj_val(self.problem.problem)