Source code for naginterfaces.library.examples.mip.ilp_dense_ex
#!/usr/bin/env python3
"``naginterfaces.library.mip.ilp_dense`` Python Example."
# NAG Copyright 2017-2019.
# pylint: disable=invalid-name,too-many-locals
import warnings
import numpy as np
from naginterfaces.base import utils
from naginterfaces.library import mip, opt
[docs]def main():
"""
Example for :func:`naginterfaces.library.mip.ilp_dense`.
Dense integer LP.
>>> main()
naginterfaces.library.mip.ilp_dense Python Example Results.
Solve an ILP problem.
Final objective value is -1.4000000e+01
"""
print('naginterfaces.library.mip.ilp_dense Python Example Results.')
print('Solve an ILP problem.')
# Silence deprecation warning:
warnings.simplefilter('ignore', utils.NagDeprecatedWarning)
# Initialize the solver:
comm = opt.nlp1_init('opt.lp_solve')
# The initial guess:
x = [1., 1.]
# Unbounded iteration limit:
itmax = 0
# No diagnostic output:
msglvl = 0
# The general constraints:
a = np.array(
[
[2., 5.],
[2., -2.],
[3., 2.],
]
)
# The infinite bound size:
bigbnd = 1.e20
# The bounds:
bl = [0., 0., -bigbnd, -bigbnd, 5.]
bu = [bigbnd, bigbnd, 15., 5., bigbnd]
# The integer variables:
intvar = [1, 1]
# The objective coefficients:
cvec = [-3., -4.]
# No limit on the node search:
maxnod = 0
# No early termination:
intfst = 0
# Maximum depth:
maxdpt = 4
# Use computed default tolerances:
toliv = 0.
tolfes = 0.
objmip = mip.ilp_dense(
itmax, msglvl, a, bl, bu, intvar, cvec,
maxnod, intfst, toliv, tolfes, bigbnd, x, comm, maxdpt=maxdpt,
).objmip
print('Final objective value is {:.7e}'.format(objmip))
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.REPORT_NDIFF,
).failed
)