-1

For my first attemp to use CP Optimizer with java, when i run my program i get this error message :

Exception in thread "main" java.lang.NoSuchMethodError: SwigDirector_IloIntValueEvalWrapper_eval
at ilog.cp.cppimpl.cp_wrapJNI.swig_module_init(Native Method)
at ilog.cp.cppimpl.cp_wrapJNI.<clinit>(cp_wrapJNI.java:802)
at ilog.cp.cppimpl.IloCP.<init>(IloCP.java:109)
at ilog.cp.IloCP.<init>(IloCP.java:128)
at ilog.cp.IloCP.<init>(IloCP.java:120)
at buffPos.main(buffPos.java:73)

Knowing that I included the needed libraries ILOG.CP.jar and oplall.jar in the library setting of my project in IntelliJ IDEA and also in the environment variable PATH of my windows. I'm using jdk 15.0.1

The part of my program using iloIntVar is :

// define new model
            IloCP modelPos = new IloCP();

            // variables
            IloIntVar[][] x = new IloIntVar[ligne + 1][];

            for (int i = 0; i < ligne + 1; i++) {
                x[i] = modelPos.boolVarArray(colone + 1);
            }

            IloIntVar[][] a = new IloIntVar[ligne + 1][colone + 1];
xfelt
  • 1
  • 3

2 Answers2

0
  1. Would be good to post your complete main Method content as there is the root for your Exception.

2a) If it's static code: Try to see if classes have been loaded in the JVM (or even which class from which JAR lib). Ru your Java application with the - verbose option:

java -verbose ...

2b) Check in the Run Configurations which classes and libs have been configured. Maybe the lib is not included there (top right corner next to the green run triangle). 'edit configuration' and look into the classpath.

2c) It would be helpful to get an understanding if you use any package control system (Maven etc.)

3a) As there's JNI involved - make sure classes AND methods that are called are available as the "NoSuchMethodError" is throws in a method cannot be found in the JVM when called by JNI. Unfortunately not all infos is available in your snippet to debug your code. But it's very likely somethings called wrong here.

supernova
  • 1,762
  • 1
  • 14
  • 31
  • I removed all my libraries and put them all back and then one by one. I got the same error as the next times where i only kept the library oplall.jar and the native library location of cpoptimizer and opl. The error is the following : Exception in thread "main" java.lang.RuntimeException: internal error: bad cast at ilog.concert.cppimpl.IloConcertUtils.ToCppIloIntExpr(IloConcertUtils.java:342) at ilog.concert.IloModelerImpl.prod(IloModelerImpl.java:1142) at buffPos.main(buffPos.java:90) PS: I don't use Maven and my classpath has the jar of my library – xfelt Nov 06 '20 at 19:45
  • So i modified one of my prod functions in the code that summed ilointvar as ilonumvar, and now i get the error : Exception in thread "main" java.lang.RuntimeException: internal error (Please notify IBM) at ilog.concert.cppimpl.concert_wrapJNI.operator_prod__SWIG_8(Native Method) at ilog.concert.cppimpl.concert_wrap.operator_prod(concert_wrap.java:227) at ilog.concert.IloModelerImpl.prod(IloModelerImpl.java:797) at ilog.concert.IloModelerImpl.prod(IloModelerImpl.java:808) at buffPos.main(buffPos.java:89) – xfelt Nov 10 '20 at 23:38
  • You should help people to help you. If you would post a fully fleshed running example, one could potentially help. – supernova Nov 13 '20 at 14:13
0

Probably, you miss the configuration of "-Djava.library.path"

If you use IntelliJ IDEA,

first, add the ILOG.CP.jar (you have done it)

then, please add "-Djava.library.path="(your cplex path)\cplex\bin\x64_win64;(your cplex path)\cpoptimizer\bin\x64_win64" in the Run -> Configurations -> VM options of IDEA.

e.g., -Djava.library.path="D:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\bin\x64_win64;D:\Program Files\IBM\ILOG\CPLEX_Studio128\cpoptimizer\bin\x64_win64"

Procrastinator
  • 2,526
  • 30
  • 27
  • 36