scipopt / JSCIPOpt

Java interface for the SCIP Optimization Suite
MIT License
62 stars 35 forks source link

questions relate to JSCIPOpt installation on windows #28

Closed WenjingFeng closed 3 years ago

WenjingFeng commented 3 years ago

I have some doubts about the installation steps in install.md. First of all, I have downloaded and installed the packages needed. Secondly, The next step is as follows, but there is an error that "CMake Error: The source directory "C:/Program Files/SCIPOptSuite 7.0.0" does not appear to contain CMakeLists.txt" . So I execute the step 1 int the directory of JSCIPOpt-master, and an error occurred like Error 1 as follows. 1) Create a shared library of the [SCIP Optimization Suite](http://scip.zib.de/#download) by executing mkdir build cd build cmake .. make in the SCIP Optimization Suite directory. This should have created all necessary libraries. Error 1 : ` D:\javaSCIPinterface\JSCIPOpt-master\build>cmake .. -- Building for: Visual Studio 14 2015 CMake Deprecation Warning at CMakeLists.txt:5 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

-- Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.15063. -- The C compiler identification is MSVC 19.0.24215.1 -- The CXX compiler identification is MSVC 19.0.24215.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found JNI: C:/JDK/lib/jawt.lib -- Found Java: C:/JDK/bin/java.exe (found version "1.8.0_144") -- Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) CMake Error at CMakeLists.txt:66 (find_package): Could not find a configuration file for package "SCIP" that is compatible with requested version "". The following configuration files were considered but not accepted: C:/Program Files/SCIPOptSuite 7.0.0/lib/cmake/scip/scip-config.cmake, version: 7.0.0 (64bit)

-- Configuring incomplete, errors occurred! See also "D:/javaSCIPinterface/JSCIPOpt-master/build/CMakeFiles/CMakeOutput.log". The Second step is as follows , but when I skip the first step and execute this step, error shows that : "The system cannot find the specified file". 2b) Building JSCIPOpt on Windows. Compile the interface by executing the following commands: mkdir build cd build cmake .. -G "Visual Studio 14 2015 Win64" -DSCIP_DIR=/build cmake --build . --config <"Release" or "Debug"> ` I have tried to install this interface for a long time, and I want to solve a very important nonlinear programming problem with Java and SCIP. Sincerely hope to get help.

mueldgog commented 3 years ago

Dear Wenjing, as far as I can see it, your CMake version is too old. Could you install the latest one and try to compile the SCIP Optimization Suite again? You won't be able to compile JSCIPOpt without compiling the Optimization Suite.

Btw, which version of Visual Studio did you install? I think that you just copied the command from the Install.md, but I'm pretty sure that you don't use the version of 2015, right?

mueldgog commented 3 years ago

Ok, I see. The CMake log is saying that you use MSVC 19, so you should adjust the version accordingly in your

cmake .. -G "Visual Studio XXXXXXX"

call.

mueldgog commented 3 years ago

And last but not least, do you really need to use Java? The Java interface of SCIP is not as mature as the Python interface, which is also easier to install on Windows.

In addition to that: What types of nonlinearities do you have? JSCIPOpt only supports quadratic nonlinear functions.

WenjingFeng commented 3 years ago

Thank you for your reply and suggestions, I will try these as soon as possible. 1.Well, how do I compile the Optimization Suite ? There isn't a CMakeLists.txt in the dictionary of SCIPOptSuite 7.0.0, do I need to copy the CMakeLists.txt in JSCIPOpt-master to there? Or copy all sub files of JSCIPOpt-master into the dictionary of SCIPOptSuite 7.0.0? 2.I want to deal with a path planning problem, in which there will be a quadratic decision variable.

Best wishes,Wenjing

mueldgog commented 3 years ago
  1. There should be a CMakeLists.txt in the directory of the SCIP Optimization Suite. Where did you download it from? Use this link SCIP 7.0.1 please.

  2. Ok, this you can do with JSCIPOpt, however, integrating JSCIPOpt into another Java application might require some technical knowledge of how to handle the JAR files. I won't be able to help you much with that.

wujianjack commented 3 years ago

Hi, @WenjingFeng

I saw your emails from SCIP mailing lists and try to give you some suggestions here.

You can compile the Java interface of SCIP with following steps:

  1. Download SCIPOptSuite-7.0.1-win64-VS15.exe and install it to directory such as D:\Program Files\SCIPOptSuite 7.0.1, and append D:\Program Files\SCIPOptSuite 7.0.1\bin to system environment variable PATH. Verify by run scip in command prompt (cmd);
  2. Download JSCIPOpt and extract files to directory such as D:\JSCIPOpt-master;
  3. Download SWIG and extract file to directory such as D:\Program Files\SWIG, and append path D:\Program Files\SWIG to system environment variable PATH. Verify by run swig -help in command prompt (cmd);
  4. Open x64 Native Tools Command Prompt for VS 2015 from start menu, change directory to D:\JSCIPOpt-master and type:
    mkdir build
  5. Type command to search for scip-config.cmake (critical step for finding SCIP headers and libraries):
    set SCIP_DIR="D:\Program Files\SCIPOptSuite 7.0.1\lib\cmake\scip"
  6. Change directory to D:\JSCIPOpt-master\build and type command:
    cmake -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ../

    wait for the configuration step to finish and type:

    nmake
  7. The Java interface of SCIP should be compiled within several minutes.

P.S. As @mueldgog has mentioned, it seems that the Java interface supports only linear and quadratic problems, you'd better try PySCIPOpt or C interface.

Good luck.

WenjingFeng commented 3 years ago

Thank you very much for your help. I have successfully completed the above steps. ` D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>cd D:\javaSCIPinterface\JSCIPOpt-master

D:\javaSCIPinterface\JSCIPOpt-master>mkdir build

D:\javaSCIPinterface\JSCIPOpt-master>set SCIP_DIR="C:\Program Files\SCIPOptSuite 7.0.0\lib\scip"

D:\javaSCIPinterface\JSCIPOpt-master>cd build

D:\javaSCIPinterface\JSCIPOpt-master\build>cmake -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ../ CMake Deprecation Warning at CMakeLists.txt:5 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

-- The C compiler identification is MSVC 19.0.24215.1 -- The CXX compiler identification is MSVC 19.0.24215.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found JNI: C:/Program Files/Java/jdk1.8.0_271/lib/jawt.lib -- Found Java: C:/Program Files/Java/jdk1.8.0_271/bin/java.exe (found version "1.8.0_271") -- Found SWIG: D:/JSCIP_SWIG/swigwin-4.0.2/swig.exe (found version "4.0.2") -- Configuring done -- Generating done -- Build files have been written to: D:/javaSCIPinterface/JSCIPOpt-master/build

D:\javaSCIPinterface\JSCIPOpt-master\build>nmake

Microsoft (R) 程序维护实用工具 14.00.24210.0 版 版权所有 (C) Microsoft Corporation。 保留所有权利。

Scanning dependencies of target jscip [ 7%] Building C object CMakeFiles/jscip.dir/src/scipjni_wrap.c.obj scipjni_wrap.c C:\PROGRA~1\SCIPOP~1.0\lib\cmake\scip......\include\scip/branch_distribution.h: warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 (The file contains characters that cannot be represented in the current code page (936). Please save the file in Unicode format to prevent data loss) C:\PROGRA~1\SCIPOP~1.0\lib\cmake\scip......\include\scip/heur_randrounding.h: warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 C:\PROGRA~1\SCIPOP~1.0\lib\cmake\scip......\include\scip/sepa_disjunctive.h: warning C4819: 该文件包含不能在当前代码 页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 [ 14%] Linking C shared library jscip.dll 正在创建库 jscip.lib 和对象 jscip.exp(Creating library jscip.lib And objects jscip.exp) [ 21%] Built target jscip Scanning dependencies of target scipjar [ 28%] Building Java objects for scipjar.jar [ 35%] Generating CMakeFiles/scipjar.dir/java_class_filelist [ 42%] Creating Java archive scip.jar [ 50%] Built target scipjar Scanning dependencies of target examples [ 57%] Building Java objects for examples.jar [ 64%] Generating CMakeFiles/examples.dir/java_class_filelist [ 71%] Creating Java archive examples.jar [100%] Built target examples ` And I have added scip.jar and examples.jar to a Java project, and run the following program, and some errors occured when running. I tried some ways to solve it, but it didn't work. Am I missing some necessary operations after compiling JSCIPOpt? At the same time, I will try to install the SCIP interface of Python. Thanks for all your help ❤.

` package myFirstProgram; import jscip.*; public class myTest {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scip scip = new Scip();
    scip.create("example");
    Variable[] vars = new Variable[2];
    vars[0] = scip.createVar("x", 1.0, 2.0, -1.0, SCIP_Vartype.SCIP_VARTYPE_INTEGER);
    vars[1] = scip.createVar("y", 3.0, 4.0, -2.0, SCIP_Vartype.SCIP_VARTYPE_CONTINUOUS);

    double[] vals = {1.0, -3.6};
    Constraint lincons = scip.createConsLinear("lincons", vars, vals, -scip.infinity(), 10.0);
    scip.addCons(lincons);
    scip.releaseCons(lincons);

    scip.solve();
    scip.free();

}

} Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long jscip.SCIPJNIJNI.createSCIP()' at jscip.SCIPJNIJNI.createSCIP(Native Method) at jscip.SCIPJNI.createSCIP(SCIPJNI.java:286) at jscip.Scip.create(Scip.java:24) at myFirstProgram.myTest.main(myTest.java:9) `

mueldgog commented 3 years ago

Good to hear that you could successfully compile SCIP and its Java interface!

The issue here is that your application doesn't find the library that you have created when compiling JSCIPOpt. Try to the jar and the jscip.* files to the main directory of your application. Maybe it would also suffice the change your Windows PATH variable for this but I'm not sure about this.

WenjingFeng commented 3 years ago

After append jscip.dll(D:\javaSCIPinterface\JSCIPOpt-master\build) to PATH, (and I type ‘path’ in cmd to ensure that this path exists), and execute the code as follows , and I succeed!!! All the exhausting long processes are worth it, and I will continue to apply SCIP to my research. Thank you very much for your help!

` package myFirstProgram;

import jscip.*;

/* Example how to create a problem with linear constraints. / public class Linear { public static void main(String args[]) { // load generated C-library System.loadLibrary("jscip"); **importent

  Scip scip = new Scip();

  // set up data structures of SCIP
  scip.create("LinearExample");

  // create variables (also adds variables to SCIP)
  Variable x = scip.createVar("x", 2.0, 3.0, 1.0, SCIP_Vartype.SCIP_VARTYPE_CONTINUOUS);
  Variable y = scip.createVar("y", 0.0, scip.infinity(), -3.0, SCIP_Vartype.SCIP_VARTYPE_INTEGER);

  // create a linear constraint
  Variable[] vars = {x, y};
  double[] vals = {1.0, 2.0};
  Constraint lincons = scip.createConsLinear("lincons", vars, vals, -scip.infinity(), 10.0);

  // add constraint to SCIP
  scip.addCons(lincons);

  // release constraint (if not needed anymore)
  scip.releaseCons(lincons);

  // set parameters
  scip.setRealParam("limits/time", 100.0);
  scip.setRealParam("limits/memory", 10000.0);
  scip.setLongintParam("limits/totalnodes", 1000);

  // solve problem
  scip.solve();
  System.out.println("final gap = " + scip.getGap());

  // print all solutions
  Solution[] allsols = scip.getSols();

  for( int s = 0; allsols != null && s < allsols.length; ++s )
     System.out.println("solution (x,y) = (" + scip.getSolVal(allsols[s], x) + ", " + scip.getSolVal(allsols[s], y) + ") with objective value " + scip.getSolOrigObj(allsols[s]));

  // release variables (if not needed anymore)
  scip.releaseVar(y);
  scip.releaseVar(x);

  // free SCIP
  scip.free();

} }

`

mueldgog commented 3 years ago

Wonderful! I'm really happy that we could resolve your issues! :)