# PyLPSolve

PyLPSolve is an object oriented wrapper for the open source LP solver
lpsolve. The focus is on usability and integration with existing
python packages used for scientific programming (i.e. numpy and
scipy).

One unique feature is a convenient bookkeeping system that allows the
user to specify blocks of variables by string tags, or other index
block methods, then work with these blocks instead of individual
indices. All the elements of the LP are cached until solve is called,
with memory management and proper sizing of the LP in lpsolve handled
automatically.

PyLPSolve is written in Cython, with all low-level processing done in
optimized and compiled C for speed. Thus there should be minimal
overhead to using this wrapper.

Like LPSolve, it is licensed under the LGPLv2 license.

## PyLPSolve Distinctives

- A design emphasis on usability and reliability.
- Many bookkeeping operations are automatically handled by abstracting
similar variables into blocks that can be handled as a unit with
arrays or matrices.
- LP sizing is handled automatically; a buffering system ensures this
is fast and usable.
- Full integration with numpy arrays.
- Written in Cython for speed; all low-level operations are done in
compiled and optimized C code.
- Good coverage by test cases.
- Licensed under the LGPLv2 open source license (as is LPSolve).

## Short Example

Consider the following simple linear program:

This can be specified by the following code:

from pylpsolve import LP
lp = LP()
# Specify constraints
lp.addConstraint([[1,1,0], [0,1,2]], "<=", [3, 4])
# set objective
lp.setObjective([1,1,1], mode="maximize")
# Run
lp.solve()
# print out the solution:
print lp.getSolution()

which would print the solution:

This is the simplest way to work with constraints; numerous other ways
are possible including replacing the nested list with a 2d numpy
array or working with named variable blocks. For example, this code
is an equivalent way to specify the constraints and objective:

# Specify constraints
lp.addConstraint({"x" : 1, "y" : 1}, "<=", 3)
lp.addConstraint({"y" : 1, "z" : 2}, "<=", 4)
# set objective
lp.setObjective({"x": 1, "y" : 1, "z" : 1}, mode="maximize")

Numerous other ways of working with constraints and named blocks of
variables are possible. For more examples and information, see the
*PyLPSolve Reference*.

# Authors

The PyLPSolve wrapper was written by Hoyt Koepke, building on the
work of the lpsolve team. Contributions are welcome.