Usage
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
import logging
logging.basicConfig(level=logging.DEBUG)
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_objective_sense(qsoptex.ObjectiveSense.MAXIMIZE)
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()
p.read('netlib/cycle.mps', filetype='MPS') # 'LP' is also supported
p.set_param(qsoptex.Parameter.SIMPLEX_DISPLAY, 1)
status = p.solve()
Known issues
When creating a problem with the QSopt_ex library, the variables and constraints will be assigned a default name if no name is specified by the user. Variables will be named xN or x_N and constraints will be named cN or c_N (where N is an integer). If the user later adds a named variable or constraint which uses a name that is already in use, the name of the new variable or constraint will be silently changed by the QSopt_ex library. For example, the last line of the following code will remove the first constraint from the problem, not the second.
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.add_linear_constraint(qsoptex.ConstraintSense.LESS,
{'x': 1}, rhs=15, name='c1')
# Deletes the first constraint, not the second
p.delete_linear_constraint('c1')
This issue can be avoided by always assigning names to variables and constraints, or by avoiding using the same names as QSopt_ex uses as default names.
Building
The module requires the QSopt_ex library to be installed. Currently, the modified version at https://github.com/jonls/qsopt-ex is required at version 2.5.10.3 or later.
Use setup.py 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
GnuMP: GMP_INCLUDE_DIR and GMP_LIBRARY_DIR
QSopt_ex: QSOPTEX_INCLUDE_DIR and QSOPTEX_LIBRARY_DIR
For example, if GnuMP is installed in the /opt/local prefix
$ GMP_INCLUDE_DIR=/opt/local/include GMP_LIBRARY_DIR=/opt/local/lib \
./setup.py install
Metadata
Release files for python-qsoptex 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python-qsoptex-0.5.tar.gz | 60.9 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_qsoptex-0.5-cp34-cp34m-macosx_10_11_x86_64.whl | CPython 3.4 | CPython 3.4 pymalloc | macOS 10.11+ x86-64 | Details |
| python_qsoptex-0.5-cp27-none-macosx_10_11_x86_64.whl | CPython 2.7 | none | macOS 10.11+ x86-64 | Details |
Total release size: 153.3 kB
Release files / python-qsoptex-0.5.tar.gz
| Download URL | python-qsoptex-0.5.tar.gz |
|---|---|
| Size | 60.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7705dc95277b5b70e9a38c8fdc251213b677bf75dc87159b8deb7a6617132503
|
|
BLAKE2b-256 checksum How to use checksums |
e7e7e0b69c7f4ac7398ef4e845d090abcfe6009ca0a6823e79fca795fb02ff52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / python_qsoptex-0.5-cp34-cp34m-macosx_10_11_x86_64.whl
| Download URL | python_qsoptex-0.5-cp34-cp34m-macosx_10_11_x86_64.whl |
|---|---|
| Size | 45.9 kB |
| Tags | CPython 3.4 CPython 3.4 pymalloc macOS 10.11+ x86-64 |
|
SHA-256 checksum How to use checksums |
53f90f03613be6a673b6e22ce55296c99cdcffb625eac5869a6bf842668f49c1
|
|
BLAKE2b-256 checksum How to use checksums |
844166a7d17a5437e2c3524fdf4135f97a670cae8c222b37b45c690b4353f67f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / python_qsoptex-0.5-cp27-none-macosx_10_11_x86_64.whl
| Download URL | python_qsoptex-0.5-cp27-none-macosx_10_11_x86_64.whl |
|---|---|
| Size | 46.5 kB |
| Tags | CPython 2.7 macOS 10.11+ x86-64 |
|
SHA-256 checksum How to use checksums |
0ff7b7381413ac8b55eb0c9c9d11979f80d60438bddde28586863a04d7b109de
|
|
BLAKE2b-256 checksum How to use checksums |
0728b761112d3da3e1edf039efbee862355d5e26adafb26248599ea05f21e0b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |