Java Plugin (for Choco)

_images/ibex.jpg _images/choco.png

The Java plugin of Ibex allows to use Ibex with Choco, for solving mixed integer-continuous CSP (constraint satisfaction problems).

Installation (with Ibex 2.8)

Note

Read how to install Ibex before installing this plugin.

Warning

The option --with-java-package has been changed to --java-package-name

The installation of the plugin will generate, in addition to the Ibex library, the libibex-java library that contains the glue code between C++ and Java.

Note

Under Windows, Ibex is compiled as a 32-bit library although the platform is 64 bits (this is mainly because the MinGW environment is 32-bits). Hence, Java will fail in loading Ibex unless you have a 32-bits JVM.

The following instructions must be typed in the shell of MinGW.

Linux/MacOS

  • Uncompress the archive ibex-2.8.8.tar.gz in some Ibex folder:

    ~/Ibex/$ tar xvfz ibex-2.8.8.tar.gz
    
  • Download the last release of the ibex-java plugin (1.0.0)

  • Uncompress the archive ibex-java-1.0.0.tar.gz

  • Rename the folder ibex-java-1.0.0 to ibex-java and place this folder under ~/Ibex/ibex-2.8.8/plugins

  • Set the environment variable JAVA_HOME. Typical paths are /Library/Java/Home (MacOS) or /usr/lib/jvm/java-7-openjdk-i38 (Linux). Example:

    ~/Ibex/$ export JAVA_HOME=/Library/Java/Home
    
  • Then configure and install Ibex as follows:

    ~/Ibex/$ cd ibex-2.8.8
    ~/Ibex/ibex-2.8.8/$ ./waf configure [...] --enable-shared --with-jni --java-package-name=org.chocosolver.solver.constraints.real
    ~/Ibex/ibex-2.8.8/$ ./waf install
    

    Note: the --enable-shared option is mandatory.

Windows

  • Open a MinGW prompt window.

  • Uncompress the archive ibex-2.8.8.tar.gz in some Ibex folder:

    ~/Ibex/$ tar xvfz ibex-2.8.8.tar.gz
    
  • Download the last release of the ibex-java plugin (1.0.0)

  • Uncompress the archive ibex-java-1.0.0.tar.gz

  • Rename the folder ibex-java-1.0.0 to ibex-java and place this folder under ~/Ibex/ibex-2.8.8/plugins

  • Set the environment variable JAVA_HOME to the home directory of the 32 bits JDK. The variable must be set in Linux-style (don’t use backslash (“") as separator), e.g.:

    ~/Ibex/$ export JAVA_HOME=/c/Java/jdk1.7.1_17
    
  • Update the path as follows:

    ~/Ibex/$ set PATH=%PATH%;[prefix]\lib;C:\MinGW\bin
    

    where [prefix] is the path specified via --prefix

  • Then configure Ibex as follows:

    ~/Ibex/$ cd ibex-2.8.8
    ~/Ibex/ibex-2.8.8/$ ./waf configure [...] --enable-shared --with-jni --java-package-name=org.chocosolver.solver.constraints.real
    ~/Ibex/ibex-2.8.8/$ ./waf install
    

    Note: the --enable-shared option is mandatory.

Configuration options

The IbexOpt plugin supports the following options (to be used with waf configure) :

--with-jni

Activate the Java plugin.

--java-package-name=PACKAGE_NAME

The plugin will create the PACKAGE_NAME.jar file. This file is put into the [prefix]/share/java where [prefix] is /usr/local by default or whatever path specified via --prefix.

Troubleshooting

UnsatisfiedLinkError with Choco

When running the “CycloHexan” example from Choco using Ibex, the following error appears:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.chocosolver.solver.constraints.real.Ibex.add_ctr(ILjava/lang/String;I)V
at org.chocosolver.solver.constraints.real.Ibex.add_ctr(Native Method)
at org.chocosolver.solver.constraint.propagators.real.RealPropagator.<init>(RealPropagator.java:77)
at org.chocosolver.solver.constraints.real.RealConstraint.addFunction(RealConstraint.java:82)
at samples.real.CycloHexan.buildModel(CycloHexan.java:87)
at samples.AbstractProblem.execute(AbstractProblem.java:130)
at samples.real.CycloHexan.main(CycloHexan.java:134)

Solution: You probably did not set the Java package properly. The java package of the Ibex class in Choco is org.chocosolver.solver.constraints.real, try:

./waf configure [....] --java-package-name=org.chocosolver.solver.constraints.real

JAVA_HOME does not seem to be set properly

I get this message when running waf configure.

Solution: The JAVA_HOME must be the path of the JDK and contain a subdirectoy include which, in turn, contains the jni.h header file (for Java versions <10). On MacOS this path can be /Library/Java/JavaVirtualMachines/jdkXXXX.jdk/Contents/Home.