Java interface for the CLP linear solver, optimized towards fast model building and fast resolves.
The interface provides a number of useful features for Java programmers who want to build either large models or apply decomposition strategies that require a lot of resolves. The interface has undergone several rounds of testing and profiling outside of unit tests.
Variables, constraints, and linear expressions are available as Java objects to make model building as easy as possible.
Decision variables as well as their bounds and objective coefficients can be created in a single line. For example, and , would become
CLPVariable x = model.addVariable().lb(-3).ub(3);
CLPVariable y = model.addVariable().free();
Since there is no operator overloading in Java, algebraic formulations are not possible. To avoid excessive use of setters, constraints can be built by using a series of add statements. For example, can be expressed as
model.createExpression().add(3,x).add(4,y).leq(10);
The add statements also accepts vectors of variables and coefficients. See the javadoc for further reference.
Chunks of a model are buffered in heap for model building before being sent to the native lib. The size of the buffer can be set by the user. Models can be formulated in a row-by-row fashion, without bothering about possible performance bottlenecks. Models with millions of constraints can be generated quickly.
Once a model is build it only lives in native memory, with the exception of referenced objects of variables and constraints which remain in heap. To update model coefficients, the model is accessed directly in native memory via direct byte buffers which speeds up resolves. When the model gets gc'ed, native memory will be released automatically.
The project is available at the central repository. Simply add the following dependency to your pom file
<dependency>
<groupId>com.quantego</groupId>
<artifactId>clp-java</artifactId>
<version>1.16.15</version>
</dependency>
Download the latest build of the jar from the release page.
The jar file contains the native libs for the most important host systems (Intel Mac, Apple Silcon, Win 64, Linux ARM and x86), so there won't be UnsatisfiedLinkError
messages and there is no messing around with setting build paths. A copy of the native libs will be created in a temporary directory at runtime. Simply import the jar and you're done.
- Java JDK 8
- 64-bit Linux, Mac OS, or Windows
See the javadoc for a full class reference.
Nils Löhndorf