Java ILP is a java interface to integer linear programming (ILP) solvers. There exist several ILP solvers, free or commercial, that offer a java interface. However, these java interfaces are mostly adapted from the c/c++ code leading to a complicated configuration with arrays, integer variables, etc. In contrast, Java ILP aims to provide a simple object-oriented interface as a front-end increasing the ease of development.

Java ILP is licensed under LGPL (http://www.gnu.org/copyleft/lesser.html).

Java ILP requires Java 5 or higher.

**lp_solve**- free under LGPL license, available at http://lpsolve.sourceforge.net/5.5/**ILOG CPLEX**- commercial, limited trial version available at http://www.ilog.com/products/cplex/**Gurobi**(contribution by Fabio Genoese)- commercial, free academic version available http://www.gurobi.com/**Mosek**- commercial, limited trial version available at http://www.mosek.com/**GLPK**- free under GPL, available for linux and windows (compatible with version 4.43 and later)**SAT4J**(restricted 0-1 ILP backtracking solver to binary variables and integer coefficients) - free under LGPL license, available at http://sat4j.org/**MiniSat+**(restricted 0-1 ILP backtracking solver to binary variables and integer coefficients) - free under MIT license, available at http://minisat.se/MiniSat+.html , JNI lib is provided by Java ILP (see downloads at sourceforge)

You will need the solver specific JNI *jar* file and the system dependent libraries which are *dll* files on windows and *so* files on linux.
The *jar* files have to be on the classpath and the libraries in the library path.

- Information about setting the classpath: http://en.wikipedia.org/wiki/Classpath_(Java)
- Information about JNI and setting the library path: http://en.wikipedia.org/wiki/Java_Native_Interface (alternatively, copy the
*dll*files to the windows/system32 folder)

SolverFactory factory = new SolverFactoryLpSolve(); // use lp_solve

factory.setParameter(Solver.VERBOSE, 0);

factory.setParameter(Solver.TIMEOUT, 100); // set timeout to 100 seconds

/**

* Constructing a Problem:

* Maximize: 143x+60y

* Subject to:

* 120x+210y <= 15000

* 110x+30y <= 4000

* x+y <= 75

*

* With x,y being integers

*

*/

Problem problem = new Problem();

Linear linear = new Linear();

linear.add(143, "x");

linear.add(60, "y");

problem.setObjective(linear, OptType.MAX);

linear = new Linear();

linear.add(120, "x");

linear.add(210, "y");

problem.add(linear, "<=", 15000);

linear = new Linear();

linear.add(110, "x");

linear.add(30, "y");

problem.add(linear, "<=", 4000);

linear = new Linear();

linear.add(1, "x");

linear.add(1, "y");

problem.add(linear, "<=", 75);

problem.setVarType("x", Integer.class);

problem.setVarType("y", Integer.class);

Solver solver = factory.get(); // you should use this solver only once for one problem

Result result = solver.solve(problem);

System.out.println(result);

/**

* Extend the problem with x <= 16 and solve it again

*/

problem.setVarUpperBound("x", 16);

solver = factory.get();

result = solver.solve(problem);

System.out.println(result);

factory.setParameter(Solver.VERBOSE, 0);

factory.setParameter(Solver.TIMEOUT, 100); // set timeout to 100 seconds

/**

* Constructing a Problem:

* Maximize: 143x+60y

* Subject to:

* 120x+210y <= 15000

* 110x+30y <= 4000

* x+y <= 75

*

* With x,y being integers

*

*/

Problem problem = new Problem();

Linear linear = new Linear();

linear.add(143, "x");

linear.add(60, "y");

problem.setObjective(linear, OptType.MAX);

linear = new Linear();

linear.add(120, "x");

linear.add(210, "y");

problem.add(linear, "<=", 15000);

linear = new Linear();

linear.add(110, "x");

linear.add(30, "y");

problem.add(linear, "<=", 4000);

linear = new Linear();

linear.add(1, "x");

linear.add(1, "y");

problem.add(linear, "<=", 75);

problem.setVarType("x", Integer.class);

problem.setVarType("y", Integer.class);

Solver solver = factory.get(); // you should use this solver only once for one problem

Result result = solver.solve(problem);

System.out.println(result);

/**

* Extend the problem with x <= 16 and solve it again

*/

problem.setVarUpperBound("x", 16);

solver = factory.get();

result = solver.solve(problem);

System.out.println(result);

Results in the following output:

Objective: 6266.0 {y=52, x=22}

Objective: 5828.0 {y=59, x=16}

Objective: 5828.0 {y=59, x=16}

Read the Java API Reference.

Copyright 2008, Martin Lukasiewycz