# GLPK/Java

Java is an object-oriented application programming language.

## GLPK for Java

GLPK for Java uses SWIG to generate code for its Java language binding. This binding is published under the GNU General Public License.

### Installation

GLPK for Java is available through the Debian package libglpk-java, which can also be used with Ubuntu. Windows binaries are provided as part of the GLPK for Windows project.
Makefiles for Windows and POSIX-compliant systems (which includes all Linux distros) are available for manual builds on other systems. You will need to install GLPK and SWIG beforehand if you choose this option.

### Documentation

The GLPK for Java file doc/glpk-java.pdf contains a short description. Practical examples can be found in the examples/java directory. For the usage of the individual methods refer to doc/glpk.pdf of the GLPK source distribution.

### Compiling and running

Below is a minimal Java class. Save it as file Test.java.
Then compile this class under 64-bit Windows:
Or compile it under Linux:
Run the resulting file on 64-bit Windows:
Or run the file on Linux (the file paths may need adjustment to match your installation):
The output will be your GLPK version number, for example: 4.47.

### Usage with Eclipse

To use GLPK for Java with Eclipse the GLPK for Java jar library has to be added to the project properties. Furthermore the path to the native DLL library has to be set here. (See screenshot).

### Linear Optimization Wrapper for Java

The Linear Optimization Wrapper for Java provides a more intuitive interface to the GLPK for Java API. Columns and rows can be directly accessed via names and indices.
Columns are created like this:
Rows can be created and populated like this:
You may download the code using subversion:
For using this library in your Maven project enter the following repository and dependency in your pom.xml (adjust the version number as needed).
When testing with Maven it may be necessary to indicate the installation path of the GLPK for Java shared library (.so or .dll).
The exec:java target may require to indicate the installation path of the GLPK for Java shared library in MAVEN_OPTS, e.g.

## Java ILP

Java ILP provides a java interface to several linear programming solvers including GLPK. It is licences under the GNU Lesser General Public License (LGPL). The link to GLPK uses GLPK for Java.
The homepage http://javailp.sourceforge.net/ provides an example code. According to the homepage GLPK ≥ 4.43 is supported.
Development seems to have stopped. The last code update was on 2012-08-02.

## OptimJ

OptimJ is a Java-based modeling language and optimization environment. OptimJ is available with several commercial and non-commercial solvers to select from, including GLPK, and is offered under a variety of licensing, free (of charge) download, and purchase arrangements. OptimJ originates from Ateji, a software company based in Paris, France.
Development seems to have stopped. The latest release dates back to 2011.

## Java Native Access

Java Native Access (JNA) can be used to call shared native libraries from Java. The project home is https://github.com/twall/jna.
Using JNA has the following drawbacks:
* Errors occurring in the GLPK library will terminate the main process.
* Callbacks cannot be used.
The following example uses JNA to display the GLPK library version number.
Compile and run with
Adjust the classpath according to your JNA installation path.

## Obsolete interfaces

GLPK 3.3 offered a Java language binding, written by Yuri Victorovich. This binding was removed from official GLPK distribution in version 4.7, because, at that time, no GNU GPL-compliant Java implementation was available. Third party projects now provide Java bindings for GLPK.
The GLPK 4.8 Java Interface was published by Björn Frank. It is no longer maintained and cannot be used with current versions of GLPK. In particular, users have reported faulty floating point arithmetic when deployed on 64-bit Linux systems.