Skip to content

Commit

Permalink
Merge pull request #15 from mckib2/add-equality-duals
Browse files Browse the repository at this point in the history
BUG: report dual variables correctly
  • Loading branch information
mckib2 authored Dec 1, 2020
2 parents 84f002f + 780683e commit b8ea43d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions glpk/_glpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ def glpk(
if status == GLPK.GLP_OPT:

res.fun = _lib.glp_get_obj_val(prob)
res.x = np.array([_lib.glp_get_col_prim(prob, ii) for ii in range(1, len(c)+1)])
res.dual = np.array([_lib.glp_get_row_dual(prob, ii) for ii in range(1, len(b_ub)+1)])
res.x = np.array([_lib.glp_get_col_prim(prob, ii) for ii in range(1, _lib.glp_get_num_cols(prob)+1)])
res.dual = np.array([_lib.glp_get_row_dual(prob, ii) for ii in range(1, _lib.glp_get_num_rows(prob)+1)])

# We don't get slack without doing sensitivity analysis since GLPK
# uses auxiliary variables instead of slack!
Expand Down Expand Up @@ -418,8 +418,8 @@ def glpk(
if status == GLPK.GLP_OPT:

res.fun = _lib.glp_ipt_obj_val(prob)
res.x = np.array([_lib.glp_ipt_col_prim(prob, ii) for ii in range(1, len(c)+1)])
res.dual = np.array([_lib.glp_ipt_row_dual(prob, ii) for ii in range(1, len(b_ub)+1)])
res.x = np.array([_lib.glp_ipt_col_prim(prob, ii) for ii in range(1, _lib.glp_get_num_cols(prob)+1)])
res.dual = np.array([_lib.glp_ipt_row_dual(prob, ii) for ii in range(1, _lib.gpl_get_num_rows(prob)+1)])

# We don't get slack without doing sensitivity analysis since GLPK uses
# auxiliary variables instead of slack!
Expand Down
6 changes: 6 additions & 0 deletions glpk/_glpk_defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,12 @@ def __init__(self):
ctypes.c_int, # dual value of jth col
]

_lib.glp_get_row_dual.restype = ctypes.c_double
_lib.glp_get_row_dual.argtypes = [
ctypes.POINTER(glp_prob),
ctypes.c_int, # dual value of ith row
]

# Interior point variants
_lib.glp_ipt_status.restype = ctypes.c_int
_lib.glp_ipt_status.argtypes = [ctypes.POINTER(glp_prob)]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_export_symbols(self, ext):

setup(
name='scikit-glpk',
version='0.4.0',
version='0.4.1',
author='Nicholas McKibben',
author_email='[email protected]',
url='https://github.com/mckib2/scikit-glpk',
Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
message_level=GLPK.GLP_MSG_OFF,
maxit=100,
timeout=10,
solver='mip',
solver='simplex',
basis_fac='btf+cbg',
simplex_options={
'init_basis': 'adv',
'method': 'dual',
'presolve': True,
'exact': True,
# 'exact': True,
})
print('GLPK:')
print(res)
Expand Down

0 comments on commit b8ea43d

Please sign in to comment.