Skip to main content

Python bindings for QSopt_ex, an exact linear programming solver

Project description

Build Status


The Python module does not yet expose the full interface of the library but just enough is available to be able to build problems or load problems from a file and solve it. After solving, the values of variables can be obtained, as shown below.

These values will be returned as fractions.Fraction or (if the value is an integer) int. Similarly, when building a problem the parameters can be given as fractions.Fraction or int (or any other numbers.Rational) or anything that can be converted to Fraction using the Fraction constructor (i.e. float, Decimal, etc.).

import qsoptex

p = qsoptex.ExactProblem()

p.add_variable(name='x', objective=2, lower=3.5, upper=17.5)
p.add_variable(name='y', objective=-1, lower=None, upper=2)
p.add_linear_constraint(qsoptex.ConstraintSense.EQUAL, {'x': 1, 'y': 1}, rhs=0)

p.set_param(qsoptex.Parameter.SIMPLEX_DISPLAY, 1)
status = p.solve()
if status == qsoptex.SolutionStatus.OPTIMAL:
    print 'Optimal solution'
    print p.get_objective_value()
    print p.get_value('x')

The module is also able to load problems from external files:

p = qsoptex.ExactProblem()'netlib/cycle.mps', filetype='MPS') # 'LP' is also supported
p.set_param(qsoptex.Parameter.SIMPLEX_DISPLAY, 1)
status = p.solve()


The module requires the QSopt_ex library to be installed. Currently, the modified version at is required at version or later.

Use to build the extension. The setup script is based on setuptools.

$ ./setup install

If GnuMP or QSopt_ex is installed non-standard locations, the include and library paths can be set using the environment variables


For example, if GnuMP is installed in the /opt/local prefix

$ GMP_INCLUDE_DIR=/opt/local/include GMP_LIBRARY_DIR=/opt/local/lib \
        ./ install

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-qsoptex, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size python_qsoptex-0.3-cp27-none-macosx_10_10_x86_64.whl (42.1 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size python_qsoptex-0.3-cp34-cp34m-macosx_10_10_x86_64.whl (41.4 kB) File type Wheel Python version cp34 Upload date Hashes View
Filename, size python-qsoptex-0.3.tar.gz (55.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page