Skip to content

Commit

Permalink
Merge pull request #20 from mckib2/mps-integer-support
Browse files Browse the repository at this point in the history
ENH: support writing MIP MPS files via integrality argument
  • Loading branch information
mckib2 authored Dec 25, 2021
2 parents 399efec + d4dc6a9 commit 81a531b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion glpk/_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ def mpswrite(
A_eq=None,
b_eq=None,
bounds=None,
integrality=None,
sense=GLPK.GLP_MIN,
filename='prob.mps',
fmt=GLPK.GLP_MPS_FILE):
'''Write an MPS file.'''

filename = pathlib.Path(filename)
prob, _lp = _fill_prob(c, A_ub, b_ub, A_eq, b_eq, bounds, sense, filename.stem)
prob, _lp = _fill_prob(c, A_ub, b_ub, A_eq, b_eq, bounds, integrality, sense, filename.stem)

# Get the library
_lib = GLPK()._lib
Expand Down
8 changes: 6 additions & 2 deletions glpk/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from scipy.sparse import coo_matrix
from scipy.optimize._linprog_util import _LPProblem, _clean_inputs

from ._glpk_defines import GLPK, glp_prob
from ._glpk_defines import GLPK


def _convert_bounds(processed_bounds):
Expand All @@ -30,10 +30,11 @@ def _convert_bounds(processed_bounds):
return bounds


def _fill_prob(c, A_ub, b_ub, A_eq, b_eq, bounds, sense, prob_name):
def _fill_prob(c, A_ub, b_ub, A_eq, b_eq, bounds, integrality, sense, prob_name):
'''Create and populate GLPK prob struct from linprog definition.'''

# Housekeeping
# TODO: modify to use integrality after https://github.com/mckib2/scipy/pull/28 makes it into scipy master
lp = _clean_inputs(_LPProblem(c, A_ub, b_ub, A_eq, b_eq, bounds, None))
c, A_ub, b_ub, A_eq, b_eq, processed_bounds, _x0 = lp

Expand Down Expand Up @@ -68,6 +69,9 @@ def _fill_prob(c, A_ub, b_ub, A_eq, b_eq, bounds, sense, prob_name):
_lib.glp_set_col_bnds(prob, ii + first_col, bnd[0], bnd[1], bnd[2])
# else: default is GLP_FX with lb=0, ub=0

if integrality and integrality[ii] == 1:
_lib.glp_set_col_kind(prob, ii + first_col, GLPK.GLP_IV)

# Need to load both matrices at the same time
first_row = _lib.glp_add_rows(prob, A.shape[0])

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def scrape_makefile_list(filename, START_TOKEN, END_TOKEN):


class build_ext(_build_ext):
'''Overide get_export_symbols to provide them for Windows DLL.'''
'''Override get_export_symbols to provide them for Windows DLL.'''
def get_export_symbols(self, ext):
'''Only for generating Windows DLL.'''
def_file = GLPK_SRC_DIR / '../w64/glpk_4_65.def'
Expand All @@ -41,7 +41,7 @@ def get_export_symbols(self, ext):

setup(
name='scikit-glpk',
version='0.4.3',
version='0.4.4',
author='Nicholas McKibben',
author_email='[email protected]',
url='https://github.com/mckib2/scikit-glpk',
Expand Down

0 comments on commit 81a531b

Please sign in to comment.