Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bound type MI in pulp.LpProblem.fromMPS #792

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pulp/mps_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import re

from . import constants as const

CORE_FILE_ROW_MODE = "ROWS"
Expand Down Expand Up @@ -178,6 +179,9 @@ def set_both_bounds(value_low, value_up):
elif bound == "PL":
# bounds equal to defaults
return
elif bound == "MI":
set_one_bound("LO", None)
return

value = float(line[3])
if bound in ["LO", "UP"]:
Expand Down
27 changes: 21 additions & 6 deletions pulp/tests/test_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
Tests for pulp
"""

import functools
import os
import re
import tempfile
import unittest

from pulp.constants import PulpError
from pulp.apis import *
from pulp import LpVariable, LpProblem, lpSum, LpConstraintVar, LpFractionConstraint
from pulp import LpConstraintVar, LpFractionConstraint, LpProblem, LpVariable
from pulp import constants as const
from pulp import lpSum
from pulp.apis import *
from pulp.constants import PulpError
from pulp.tests.bin_packing_problem import create_bin_packing_problem
from pulp.utilities import makeDict
import re
import functools
import unittest

try:
import gurobipy as gp
Expand Down Expand Up @@ -48,6 +49,10 @@
"LO BND1 YTWO -1", "PL BND1 YTWO "
)

EXAMPLE_MPS_MI_BOUNDS = EXAMPLE_MPS_RHS56.replace(
"LO BND1 YTWO -1", "MI BND1 YTWO "
)


def gurobi_test(test_item):
@functools.wraps(test_item)
Expand Down Expand Up @@ -1158,6 +1163,16 @@ def test_importMPS_PL_bound(self):
os.unlink(h.name)
self.assertIsInstance(problem, LpProblem)

def test_importMPF_MI_bound(self):
"""Import MPS file with MI bound type."""
with tempfile.NamedTemporaryFile(delete=False) as h:
h.write(str.encode(EXAMPLE_MPS_MI_BOUNDS))
vars, problem = LpProblem.fromMPS(h.name)
os.unlink(h.name)
self.assertIsInstance(problem, LpProblem)
mi_var = vars["YTWO"]
self.assertEqual(mi_var.lowBound, None)

def test_unset_objective_value__is_valid(self):
"""Given a valid problem that does not converge,
assert that it is still categorised as valid.
Expand Down