我正在尝试设置SCIP优化求解器https://scip.zib.de/index.php
我使用Windows,并且更喜欢带有Eclipse的Java。我看到有一个Java包装器和示例文件,例如https://github.com/SCIP-Interfaces/JSCIPOpt/blob/master/examples/Linear.java
我在这里看到上一个线程:Install SCIP on Eclipse
我的项目中已正确链接scip.jar文件。
但是,编译器似乎有很多问题,从第一行开始 Scip scip =新的Scip(); 在下面的示例中。
编辑:第一个编译错误是“无法将Scip解析为类型”
编辑:最新的6.0.1下载似乎没有“ scip.jar”文件 https://scip.zib.de/download.php?fname=scip-6.0.1.tgz
编辑:带有“ scip.jar”的下载已在较早的文章中链接,并且可能已过时(适用于3.2.1版):https://scip.zib.de/download.php?fname=scipjni-3.2.1.win.x86_64.msvc.opt.spx.zip
edit2:我修复了一些问题。现在没有编译问题,但是在运行时出现了这个问题:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jscip in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at jscip.Linear.main(Linear.java:12)
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");
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();
// 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();
}
}