gpt4 book ai didi

java - Intellij 中的 Google OR 工具 : UnsatisfiedLinkError

转载 作者:太空宇宙 更新时间:2023-11-04 09:17:18 30 4
gpt4 key购买 nike

我正在设置一个应使用 Google OR-Tools 的 java 框架。下面的代码编译成功,但在运行时抛出异常:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.google.ortools.linearsolver.operations_research_linear_solverJNI.MPSolver_CLP_LINEAR_PROGRAMMING_get()I
at com.google.ortools.linearsolver.operations_research_linear_solverJNI.MPSolver_CLP_LINEAR_PROGRAMMING_get(Native Method)
at com.google.ortools.linearsolver.MPSolver$OptimizationProblemType.<clinit>(MPSolver.java:221)
at Main.main(Main.java:15)

我在 Windows 10 上使用 Intellij 2018.3。我花了很多时间尝试运行此程序,但没有成功。根据我在互联网上找到的信息,异常可能是由于链接不良和/或缺少 OR-Tools 所依赖的外部库引起的。但是,我没有解决这个问题的背景,而且 Intellij 也没有突出显示任何内容。知道问题出在哪里吗?

为了完成,这是我运行的代码:

import com.google.ortools.linearsolver.MPObjective;
import com.google.ortools.linearsolver.MPSolver;
import com.google.ortools.linearsolver.MPVariable;

public final class Main {

public static void main(String[] args) {

// Create the linear solver with the GLOP backend.
MPSolver solver =
new MPSolver("SimpleLpProgram", MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING);

// Create the variables x and y.
MPVariable x = solver.makeNumVar(0.0, 1.0, "x");
MPVariable y = solver.makeNumVar(0.0, 2.0, "y");

System.out.println("Number of variables = " + solver.numVariables());

// Create a linear constraint, 0 <= x + y <= 2.
MPConstraint ct = solver.makeConstraint(0.0, 2.0, "ct");
ct.setCoefficient(x, 1);
ct.setCoefficient(y, 1);

System.out.println("Number of constraints = " + solver.numConstraints());

// Create the objective function, 3 * x + y.
MPObjective objective = solver.objective();
objective.setCoefficient(x, 3);
objective.setCoefficient(y, 1);
objective.setMaximization();

solver.solve();

System.out.println("Solution:");
System.out.println("Objective value = " + objective.value());
System.out.println("x = " + x.solutionValue());
System.out.println("y = " + y.solutionValue());
}
}

最佳答案

就我而言,解决方案很简单 - 我只需要添加这一行代码:

Loader.loadNativeLibraries();

加载程序来自com.google.ortools.Loader

关于java - Intellij 中的 Google OR 工具 : UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819070/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com