What follows is a guide for installing yaposib very quickly and solve your first linear program using it.
Recommended method: pip¶
- Install the basic compilation tools and pkg-config. On Ubuntu:
sudo apt-get install -qq build-essential pkg-config
- Install the boost python development packages. On Ubuntu:
sudo apt-get install python-dev libboost-python-dev
- Install osi and dependencies. If you want support for commercial solvers, you will probably need to recompile yaposib. Otherwise, using a package from your distribution is fine. On Ubuntu:
sudo apt-get install coinor-libosi-dev coinor-libcoinutils-dev coinor-libclp-dev libbz2-dev
- Install python-pip. On Ubuntu:
sudo apt-get install python-pip
- Use pip to install yaposib:
sudo pip install yaposib
Alternative: development version¶
- Follow 1., 2. and 3. from the previous method
- Clone the repository
git clone https://github.com/coin-or/yaposib.git
- Run setup.py
cd yaposib sudo python setup.py install
Checking your installation¶
The utility yaposib-config is a helper script that helps you determine if your installation went fine. Run it without any argument.
This tool runs the yaposib test suite on every solvers that you Osi build reportedly supports. Since not all solvers behave equivalently, some tests might fail with some solvers, and succeed with others. A failure does not necessarily means that yaposib is completely unusable with your solver, it might simply mean that it was not tested yet combined with your solver. Please report any failures on the bugtracker.
Let’s dive into the code. Here is an example program that illustrates some features of yaposib:
""" builds the following problem 0 <= x <= 4 -1 <= y <= 1 0 <= z 0 <= w minimize obj = x + 4*y + 9*z such that: c1: x+y <= 5 c2: x+z >= 10 c3: -y+z == 7 c4: w >= 0 """ import yaposib prob = yaposib.Problem("Clp") obj = prob.obj obj.name = "MyProblem" obj.maximize = False # names cols = prob.cols for var_name in ["x", "y", "z", "w"]: col = cols.add(yaposib.vec()) col.name = var_name # lowerbounds for col in cols: col.lowerbound = 0 cols.lowerbound = -1 # upperbounds cols.upperbound = 4 cols.upperbound = 1 # constraints rows = prob.rows rows.add(yaposib.vec([(0,1),(1,1)])) rows.add(yaposib.vec([(0,1),(2,1)])) rows.add(yaposib.vec([(1,-1),(2,1)])) rows.add(yaposib.vec([(3,1)])) # constraints bounds rows.upperbound = 5 rows.lowerbound = 10 rows.lowerbound = 7 rows.upperbound = 7 rows.lowerbound = 0 # constraints names for row, name in zip(rows, ["c1", "c2", "c3", "c4"]): row.name = name # obj prob.obj = 1 prob.obj = 4 prob.obj = 9 prob.solve() for col in prob.cols: print("%s=%s" % (col.name, col.solution))
It is also easy to write a generic command line solver in a few lines of code. The following script is part of the yaposib distribution and is shipped as the command line utility yaposib-solve
import yaposib import sys def main(): """Extra simple command line mps solver""" if len(sys.argv) <= 1: print("Usage: yaposib-solve <file1.mps> [<file2.mps> ...]") sys.exit(0) solver = yaposib.available_solvers() for filename in sys.argv[1:]: problem = yaposib.Problem(solver) print("Will now solve %s" % filename) err = problem.readMps(filename) if not err: problem.solve() if problem.status == 'optimal': print("Optimal value: %f" % problem.obj.value) for var in problem.cols: print("\t%s = %f" % (var.name, var.solution)) else: print("No optimal solution could be found.") if __name__ == "__main__": main()
Other examples are available in the examples directory.