SCPSolver - an easy to use Java Linear Programming Interface

Authors: Hannes Planatscher and Michael Schober.
Thanks: SCPSolver was developed using Eclipse and optimized using JProfiler.

SCPSolver should enable a Java developer to use Linear Programming in 5 minutes.

3 steps to start (works for Windows, Linux and Mac)
  1. Download the SCPSolver.jar and a solver pack:

    GLPK Solver Pack: GLPKSolverPack.jar (please note the GPL licensing terms)
    LPSOLVE Solver Pack: LPSOLVESolverPack.jar (please note the LGPL licensing terms)
  2. Add both jar-files to your Eclipse project (or the classpath)
  3. Read the example
That is it. SCPSolver will take care of extracting the required libraries, so you do not have to.

If you get an error under Windows "DEBUG: Could not find required library: xxxxxxxx_x64": Update to the most recent GLPKSolverPack.jar!

Here are some slides explaining what SCPSolver is about:


The low level interface example

If you are comfortable representing the objective function and contraints with double arrays, you will use the low level interface. Here is an example:
Min 5 x + 10 y 
Subject to
3 x + 1 y >= 8
4y >= 4
2x <= 2
Using the low level interface in SCPSolver you would write:

LinearProgram lp = new LinearProgram(new double[]{5.0,10.0});
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[]{3.0,1.0}, 8.0, "c1"));
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[]{0.0,4.0}, 4.0, "c2"));
lp.addConstraint(new LinearSmallerThanEqualsConstraint(new double[]{2.0,0.0}, 2.0, "c3"));
lp.setMinProblem(true);
LinearProgramSolver solver  = SolverFactory.newDefault();
double[] sol = solver.solve(lp);

The code above should almost explain itself.

The high level interface example

As other modeling toolkits SCPSolver supports a more high level representation of mathematical programs. The key object for this modeling interface is the LPWizard.

LPWizard lpw = new LPWizard();
lpw.plus("x1",5.0).plus("x2",10.0);
lpw.addConstraint("c1",8,"<=").plus("x1",3.0).plus("x2",1.0);
lpw.addConstraint("c2",4,"<=").plus("x2",4.0);
lpw.addConstraint("c3", 2, ">=").plus("x1",2.0);

The high level interface balances readability and rapid modeling. It also allows the incremental definition of a model. New variables can be added in each new term. Each variable has a name, which can be used in the modeling and results analysis. In mixed integer programs it often occurs that all variables in a specific constrains have to be declared as integer or binary. In the high level this is relatively straight forward:

lpw.addConstraint("c2",4,"<=").plus("x2",4.0).setAllVariablesInteger();
lpw.addConstraint("c3", 2, ">=").plus("x1",2.0).setAllVariablesBoolean();
.
By exposing these methods directly on the objects defining the term, they are immediately available by syntax completion in Java Integrated Development Environments (e.g. Eclipse, Netbeans, etc.).

Documentation

Most solvers for linear programs are implemented in C/C++ for performance reasons. Java developers can use JNI interfaces for some solvers. However most interfaces are pretty difficult to setup, and lock the developer in to a specific solver. SCPSolver was developed to overcome those issues. The library has the following features:

We have generated the Javadoc Documentation of the SCPSolver API. The most important classes are:

Building SCPSolver and the solver packs from source (not required!)

Most users of SCPSolver will use the prebuilt binaries. The whole idea of SCPSolver is to take the pain of building the JNI libraries away from the developer. However in some cases, like changing SCPSolver itself, adding a new solver pack (please go ahead!) or updating binaries in the solver packs, will require to build SCPSolver from source.

The official GIT repository is hosted on Bitbucket. This is the URL to clone it, which is the preferred way to obtain the source code:
https://bitbucket.org/hplanatscher/scpsolver.git
If you are not comfortable with GIT, please follow these steps:
  1. Get the source zip-files SCPSolver, GLPK Solver Pack, LPSOLVE Solver Pack and CPLEX.
  2. Unpack the source using your preferred tool (e.g. tar xvfz scpsolver-src.tar.gz)
  3. get in the directory and use 'ant build' or set up your Eclipse project by copying the src/scpsolver directory in the source path.
Building the core library is simple, since it has no dependencies, except an installed JRE version 1.5 or 1.6. It can be built withouth much pain in any development environment, or in the command-line with ANT (version > 1.7).
Building the solver packages is more tricky, because a lot (like a C compiler, static libraries, ..) is required to be installed on the system. However we have included nice build-scripts (for Linux, Mac Os X and Windows), which should work out of the box, if all required tools are set up correctly. The build scripts however are not exactly sustainable for all three platforms yet: they might break after a major update. Meanwhile we will try our best to provide working solverpacks.

Licensing

A few words on the license: SCPSolver uses a flexible license. It pulls the license model from its solverpacks.
If you use the GLPK Solver as a backend, which is licensed under the GNU GPL, automatically your instance of SCPSolver is also licensed GPL. If you use the LPSOLVE Solver as a backend, which is licensed under the GNU LGPL, automatically your instance of SCPSolver is also licensed LGPL. If you use other solvers the respective licensing restrictions on the linked code apply. The SCPSolver Core per se is licensed under BSD License.
In short: If you use SCPSolver with GLPK as backend, and distribute your software to the public, you have to publish the source code.

Support

Please report bugs to Hannes Planatscher.

Follow @SCPSolver Tweet to @SCPSolver
SCPSolver is powered by and .