Skip to content

Commit

Permalink
GLPK and Gurobi improvements
Browse files Browse the repository at this point in the history
setup.pysetup.py#
  • Loading branch information
axelvonkamp committed Aug 30, 2021
1 parent d8fea05 commit d06ff30
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = '0.0.5' %}
{% set version = '0.0.6' %}

package:
name: optlang_enumerator
Expand Down
16 changes: 7 additions & 9 deletions optlang_enumerator/cMCS_enumerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,18 @@ def call_back_func(model, where): # encapsulating with functools.partial not acc
global_optimum = enum_method == 1 or \
(self._optlang_interface is optlang.cplex_interface and
self.model.problem.solution.MIP.get_mip_relative_gap() < self.model.configuration.tolerances.optimality) or \
(self._optlang_interface is optlang.glpk_interface and self.model.status == 'optimal') # geht das sicher?
(self._optlang_interface is optlang.gurobi_interface and
self.model.problem.getAttr(GRB.attr.MIPGap) < self.model.configuration.tolerances.optimality) or \
(self._optlang_interface is optlang.glpk_interface and self.model.status == 'optimal')
if global_optimum: #enum_method == 1: # only for this method optlang 'optimal' is a guaranteed global optimum
ov = round(self.model.objective.value)
if ov > self.evs_sz_lb:
self.evs_sz_lb = ov
#if ov > e.evs_sz.lb: # increase lower bound of evs_sz constraint, but is this really always helpful?
# e.evs_sz.lb = ov
#if ov > self.evs_sz.lb: # increase lower bound of evs_sz constraint, but is this really always helpful?
# self.evs_sz.lb = ov
# print(ov)

# not necessary when self.evs_sz.ub = max_mcs_size
# if round(self.model.objective.value) > max_mcs_size:
# print('MCS size limit exceeded, stopping enumeration.')
# break
else: # enum_method == 3: # and self.model.status == 'feasible':
# query best bound and use it to update self.evs_sz_lb
print("CS", mcs, end="")
mcs = mcs_computation.make_minimal_cut_set(model, mcs, target_constraints)
print(" -> MCS", mcs)
Expand All @@ -395,7 +393,7 @@ def call_back_func(model, where): # encapsulating with functools.partial not acc
all_mcs.append(mcs)
else:
print('Stopping enumeration with status', self.model.status)
if self.model.status != 'infeasible':
if self.model.status != 'infeasible' and self.model.status != 'time_limit':
err_val = 1
continue_loop = False
elif enum_method == 2: # populate by cardinality
Expand Down
5 changes: 4 additions & 1 deletion optlang_enumerator/mcs_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ def compute_mcs(model, targets, desired=None, cuts=None, enum_method=1, max_mcs_
# e.model.problem.threads = -1 # activate multithreading

e.evs_sz_lb = 1 # feasibility of all targets has been checked
e.model.configuration.tolerances.optimality = mip_opt_tol
if optlang_interface.__name__ == 'optlang.glpk_interface':
e.model.configuration._smcp.tol_dj = mip_opt_tol
else:
e.model.configuration.tolerances.optimality = mip_opt_tol # nicht bei GLPK
e.model.configuration.tolerances.feasibility = mip_feas_tol
e.model.configuration.tolerances.integrality = mip_int_tol
if set_mip_parameters_callback != None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='optlang_enumerator',
version='0.0.1',
version='0.0.6',
description='Enumeration of multiple solutions to a MILP with optlang.',
url='https://github.com/cnapy-org/optlang_enumerator.git',
author='Axel von Kamp',
Expand Down

0 comments on commit d06ff30

Please sign in to comment.