Decision Optimization

 View Only
  • 1.  Cpoptimizer java and OSX

    Posted Mon July 06, 2020 03:31 AM
    Hi,

    I'm trying to run a java program with cpoptimizer and I have some linkage errors. So, I've tried to do the same with the examples, and I still have the same errors. By the way, Cplex is working fine and I'm using cplex 12.10 on macOS Catalina (10.15.4).
    So, if I use the Makefile in the examples and I run "make java", everything compiles correctly. However, if I run "make execute_java", I have the following error:
    make execute_java
    DYLD_LIBRARY_PATH=../../../bin/x86-64_osx:../../../../cplex/bin/x86-64_osx /usr/bin/java -classpath ../../../lib/ILOG.CP.jar:. Alloc
    Native code library failed to load: ensure the appropriate library (libopl12100.dylib) is in your path.​

    If I had opl lib to the path, I still have the same error:

    make execute_java
    DYLD_LIBRARY_PATH=../../../bin/x86-64_osx:../../../../cplex/bin/x86-64_osx:../../../../opl/bin/x86-64_osx /usr/bin/java  -classpath ../../../lib/ILOG.CP.jar:. Alloc
    Native code library failed to load: ensure the appropriate library (libopl12100.dylib) is in your path.


    In my code, I have the following swig error when I add ""libopl12100.dylib":

    Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.concert.cppimpl.concert_wrapJNI.swig_module_init()V
    	at ilog.concert.cppimpl.concert_wrapJNI.swig_module_init(Native Method)
    	at ilog.concert.cppimpl.concert_wrapJNI.<clinit>(concert_wrapJNI.java:1621)
    	at ilog.concert.cppimpl.IloEnv.<init>(IloEnv.java:49)
    	at ilog.concert.IloModelerImpl.<init>(IloModelerImpl.java:34)
    	at ilog.cp.IloCP.<init>(IloCP.java:128)
    	at ilog.cp.IloCP.<init>(IloCP.java:121)


    Any idea please ?
    Thanks



    ------------------------------
    Antoine
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Cpoptimizer java and OSX

    IBM Champion
    Posted Mon July 06, 2020 12:10 PM
    Does it help if you also add ../../../../cpoptimizer/bin/x86-64_osx to the library path?

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: Cpoptimizer java and OSX

    Posted Mon July 06, 2020 12:30 PM
    I ran the examples of cpoptimizer, so "../../../bin/x86-64_osx" is "../../../../cpoptimizer/bin/x86-64_osx".
    Thanks

    ------------------------------
    Antoine Legrain
    ------------------------------



  • 4.  RE: Cpoptimizer java and OSX

    Posted Fri July 10, 2020 05:16 AM
    This problem can appear if you have in your path references to other (older) libraries of CPLEX/CP Optimizer. Then there is a mismatch between versions of the dynamic libraries found. Could you check that your path contains only references to the CPLEX version that you are currently using ?

    Thanks.

    Philippe

    ------------------------------
    --
    Philippe Refalo
    IBM ILOG CP Optimizer
    ------------------------------



  • 5.  RE: Cpoptimizer java and OSX

    Posted Fri July 10, 2020 03:20 PM
    I don't remember installing older version. I have checked my PATH and I didn't find any cplex in it.

    ------------------------------
    Antoine Legrain
    ------------------------------



  • 6.  RE: Cpoptimizer java and OSX

    Posted Wed July 15, 2020 06:23 AM
    I tried on my Mac also running under Catalina (10.15.4) and did not notice any problem:

    [static_pic] ☞ make execute_java  
    DYLD_LIBRARY_PATH=../../../bin/x86-64_osx:../../../../cplex/bin/x86-64_osx /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/bin/java  -classpath ../../../lib/ILOG.CP.jar:. Alloc
     ! -------------------------------------------------- CP Optimizer 12.10.0.0 --
     ! Minimization problem - 148 variables, 7746 constraints
     ! Presolve      : 4131 extractables eliminated, 3918 constraints generated
     ! FailLimit            = 40000
     ! CountDifferentInferenceLevel = Extended
     ! LogPeriod            = 100000
     ! Initial process time : 0.06s (0.06s extraction + 0.00s propagation)
     !  . Log search space  : 1184.0 (before), 1184.0 (after)
     !  . Memory usage      : 3.4 MB (before), 3.4 MB (after)
     ! Using parallel search with 8 workers.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed    W       Branch decision
                            0        148                 -
     + New bound is 0
                            0        148                 -
     + New bound is 1
     *           116      948  0.24s        1      (gap is 99.14%)
     *           106      167  0.24s        3      (gap is 99.06%)
      ...
    

    Could you send the list of files you have in ../../../bin/x86-64_osx and ../../../../cplex/bin/x86-64_osx ?

    In fact I get the same errors like yours if I do not specify any path to the dynamic libraries (omitting DYLD_LIBRARY_PATH= in the command)

    I know that recent versions of MacOS are very touchy about setting the environment variable on the command line. Could you try setting it with 'export' before running the execution : 

    export DYLD_LIBRARY_PATH=../../../bin/x86-64_osx:../../../../cplex/bin/x86-64_osx
    
    /usr/bin/java -classpath ../../../lib/ILOG.CP.jar:. Alloc

     



    ------------------------------
    Philippe Laborie
    ------------------------------



  • 7.  RE: Cpoptimizer java and OSX

    Posted Wed July 15, 2020 06:10 PM
    Here the listing of the folders:
    ls ../../../bin/x86-64_osx/
    cpoptimizer                     libcp_wrap_cpp_java12100.jnilib
    
    ls ../../../../cplex/bin/x86-64_osx/
    cplex                               libcplex12100mpitransport.dylib     libcplex12100remotejni.jnilib
    cplexamp                            libcplex12100mpiworker.dylib        libcplex12100tcpiptransport.dylib
    cpxworker                           libcplex12100processtransport.dylib libcplex12100tcpipworker.dylib
    libcplex12100.dylib                 libcplex12100processworker.dylib
    libcplex12100.jnilib                libcplex12100remote.dylib
    
    ls ../../../../opl/bin/x86-64_osx/
    libcplex12100.dylib                 libicudata.55.dylib                 libicutu.55.dylib
    libcplex12100.jnilib                libicudata.dylib                    libicutu.dylib
    libcplex12100mpitransport.dylib     libicui18n.55.dylib                 libicuuc.55.dylib
    libcplex12100mpiworker.dylib        libicui18n.dylib                    libicuuc.dylib
    libcplex12100processtransport.dylib libicuio.55.dylib                   libopl12100.dylib
    libcplex12100processworker.dylib    libicuio.dylib                      liboplb.dylib
    libcplex12100remote.dylib           libicule.55.dylib                   liboplnl1.12.dylib
    libcplex12100remotejni.jnilib       libicule.dylib                      liboplnl1.dylib
    libcplex12100tcpiptransport.dylib   libiculx.55.dylib                   oplrun
    libcplex12100tcpipworker.dylib      libiculx.dylib                      oplrunjava​

    If I'm exporting DYLD_LIBRARY_PATH and running the Alloc example, I still have the same error (libopl not found).
    However, if I set java.library.path, the opl library is found, but I still have the swig error. I've tried to add all the three folders to the PATH, but I still have the swig error.
    /usr/bin/java -Djava.library.path=../../../bin/x86-64_osx:../../../../cplex/bin/x86-64_osx:../../../../opl/bin/x86-64_osx -classpath ../../../lib/ILOG.CP.jar:. Alloc
    Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.concert.cppimpl.concert_wrapJNI.swig_module_init()V
    	at ilog.concert.cppimpl.concert_wrapJNI.swig_module_init(Native Method)
    	at ilog.concert.cppimpl.concert_wrapJNI.<clinit>(concert_wrapJNI.java:1621)
    	at ilog.concert.cppimpl.IloEnv.<init>(IloEnv.java:49)
    	at ilog.concert.IloModelerImpl.<init>(IloModelerImpl.java:34)
    	at ilog.cp.IloCP.<init>(IloCP.java:128)
    	at ilog.cp.IloCP.<init>(IloCP.java:121)
    	at Alloc.main(Alloc.java:89)​


    ------------------------------
    Antoine Legrain
    ------------------------------



  • 8.  RE: Cpoptimizer java and OSX

    Posted Thu July 16, 2020 10:10 AM

    The only two libraries that are required are:

    ../../../bin/x86-64_osx/libcp_wrap_cpp_java12100.jnilib
    ../../../../cplex/bin/x86-64_osx/libcplex12100.jnilib
    


    It is not clear to me why they are not found when setting variable DYLD_LIBRARY_PATH.

    When I'm using :

    java -Djava.library.path=../../../bin/x86-64_osx:../../../../cplex/bin/x86-64_osx -classpath ../../../lib/ILOG.CP.jar:. Alloc

    I get the same error as yours, it seems related with the fact the loader cannot find the CPLEX dynamic library (libcplex12100.jnilib) that is referenced in libcp_wrap_cpp_java12100.jnilib as @rpath/libcplex12100.jnilib (so I suppose here there is a problem in the specification of @rpath). I tried manually changing the path to library libcplex12100.jnilib in the CP Optimizer dynamic library libcp_wrap_cpp_java12100.jnilib by setting it to its absolute path by doing: 

    install_name_tool -change @rpath/libcplex12100.jnilib /Applications/CPLEX_Studio_1210/cplex/bin/x86-64_osx/libcplex12100.jnilib /Applications/CPLEX_Studio_1210/cpoptimizer/bin/x86-64_osx/libcp_wrap_cpp_java12100.jnilib

    (My COS is installed in /Applications/CPLEX_Studio_1210). And then -Djava.library.path seems to work (and it is even not required to add the path to the cplex lib):

    java -Djava.library.path=../../../bin/x86-64_osx -classpath ../../../lib/ILOG.CP.jar:. Alloc 
     ! -------------------------------------------------- CP Optimizer 12.10.0.0 --
     ! Minimization problem - 148 variables, 7746 constraints
     ! Presolve      : 4131 extractables eliminated, 3918 constraints generated
     ! FailLimit            = 40000
     ! CountDifferentInferenceLevel = Extended
     ! LogPeriod            = 100000
     ! Initial process time : 0.06s (0.06s extraction + 0.00s propagation)
     !  . Log search space  : 1184.0 (before), 1184.0 (after)
     !  . Memory usage      : 3.4 MB (before), 3.4 MB (after)
     ! Using parallel search with 8 workers.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed    W       Branch decision
                            0        148                 -
     + New bound is 0
    ...

    Maybe you could try something like this ...



    ------------------------------
    Philippe Laborie
    ------------------------------



  • 9.  RE: Cpoptimizer java and OSX

    Posted Thu July 16, 2020 11:45 AM
    Edited by System Fri January 20, 2023 04:38 PM
    I've run the Alloc example without the path to libopl and java is not able to find libcplex12100.jnilib: the rpath is not resolved.
    /usr/bin/java -Djava.library.path=/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx:/Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx -classpath ../../../lib/ILOG.CP.jar:. Alloc
    Native code library failed to load: ensure the appropriate library (libopl12100.dylib) is in your path.
    Exceptions:
    no opl12100 in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    no oplb in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    no opl_lang_wrap_cpp in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    no opl_core_wrap_cpp_java12100 in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    no opl_core_wrap_cpp in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    no cp_oaas12100 in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    no cp_oaas in java.library.path: [/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx, /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx]
    /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx/libcp_wrap_cpp_java12100.jnilib: dlopen(/Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx/libcp_wrap_cpp_java12100.jnilib, 1): Library not loaded: @rpath/libcplex12100.jnilib
      Referenced from: /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx/libcp_wrap_cpp_java12100.jnilib
      Reason: image not found​

    However, if I replace the rpath by the absolute path, it works like a charm ! I don't know why java is not able to resolve the rpath even if the java.library.path contains the right folder (/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx).
    install_name_tool -change @rpath/libcplex12100.jnilib /Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx/libcplex12100.jnilib /Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx/libcp_wrap_cpp_java12100.jnilib
    
    /usr/bin/java -Djava.library.path=/Applications/CPLEX_Studio1210/cpoptimizer/bin/x86-64_osx -classpath ../../../lib/ILOG.CP.jar:. Alloc
     ! -------------------------------------------------- CP Optimizer 12.10.0.0 --
     ! Minimization problem - 148 variables, 7746 constraints
     ! Presolve      : 4131 extractables eliminated, 3918 constraints generated
     ! FailLimit            = 40000
     ! CountDifferentInferenceLevel = Extended
     ! LogPeriod            = 100000
     ! Initial process time : 0.06s (0.06s extraction + 0.00s propagation)
     !  . Log search space  : 1184.0 (before), 1184.0 (after)
     !  . Memory usage      : 3.4 MB (before), 3.4 MB (after)
     ! Using parallel search with 8 workers.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed    W       Branch decision
                            0        148                 -
     + New bound is 0
                            0        148                 -
     + New bound is 1
     *           116      948  0.24s        1      (gap is 99.14%)
     *           106      167  0.24s        3      (gap is 99.06%)
     *            98     1836  0.34s        1      (gap is 98.98%)
     *            97     2131  0.42s        3      (gap is 98.97%)
    ​



    ------------------------------
    Antoine Legrain
    ------------------------------