我使用``clp java进行线性优化,但是当我试图运行代码时,我会得到以下错误:进程继续运行,下面的代码不断地被打印出来。
加载C:\Users\Abhijay\AppData\Local\Temp\CLPExtractedLib1623275631902676\Clp.dll时BridJ: LoadLibrary错误:动态链接库初始化例程失败。
我在pom.xml中添加了以下依赖项。
<dependency>
<groupId>com.quantego</groupId>
<artifactId>clp-java</artifactId>
<version>1.16.10</version>
</dependency>
<dependency>
<groupId>com.nativelibs4java</groupId>
<artifactId>bridj</artifactId>
<version>0.7.0</version>
</dependency>这是我的代码:
import com.quantego.clp.CLP;
import com.quantego.clp.CLP.ALGORITHM;
import com.quantego.clp.CLPVariable;
public class ClpDemo {
public static void main(String[] args) {
CLP model = new CLP().algorithm(ALGORITHM.AUTO).maximization().presolve(false);
CLPVariable x1 = model.addVariable().lb(0);
CLPVariable x2 = model.addVariable().lb(0);
model.createExpression().add(10, x1).add(20, x2).leq(120);
model.createExpression().add(8, x1).add(8, x2).leq(80);
model.createExpression().add(12, x1).add(16, x2).asObjective();
model.solve();
double x1Value = model.getSolution(x1);
double x2Value = model.getSolution(x2);
System.out.println("x1 :" + x1Value + " x2 :" + x2Value);
}
} 发布于 2018-12-04 10:00:25
开发分支的最新构建解决了这个问题。很快就会被推到maven那里。
发布于 2018-12-20 16:53:28
我实现了我自己版本的线性规划,也支持混合整数线性规划。如果您对使用该工具感兴趣,下面是链接。
问题:
max: x+y
-2x + 2y >= 1
-8x + 10y <= 13
x,y : real线性规划的例子.
//Function
double[] function = new double[] {1,1};
//Constraints
List<Constraint> constraints = new ArrayList<>();
constraints.add(new Constraint(new double[] {-2,2}, Constraint.Symbol.GREATER_THAN, 1));
constraints.add(new Constraint(new double[] {-8,10}, Constraint.Symbol.LESS_THAN, 13));
LinearProgramming lp = new LinearProgramming(LinearProgramming.Objective.Maximize);
int status = lp.Solve(function, constraints);
switch(status){
case LinearProgramming.INFEASIBLE:
System.out.println("Infeasible solution");
break;
case LinearProgramming.OPTIMAL:
System.out.println("Optimal solution found");
case LinearProgramming.UNBOUNDED:
System.out.println("Unbounded solution");
}
double[] coef = lp.getCoefficients();
double solution = lp.getSolution();问题:
max: x+y
-2x + 2y >= 1
-8x + 10y <= 13
x: real
y: integer混合整数线性规划的实例.
//Function
double[] function = new double[] {1,1};
//Constraints
List<Constraint> constraints = new ArrayList<>();
constraints.add(new Constraint(new double[] {-2,2}, Constraint.Symbol.GREATER_THAN, 1));
constraints.add(new Constraint(new double[] {-8,10}, Constraint.Symbol.LESS_THAN, 13));
//Define integer variables
//1: integer
//0: double
int[] types = new int[] {0,1};
MixedIntegerLinearProgramming lp = new MixedIntegerLinearProgramming(MixedIntegerLinearProgramming.Objective.Maximize);
lp.setType(types);
int status = lp.Solve(function, constraints);
switch(status){
case LinearProgramming.INFEASIBLE:
System.out.println("Infeasible solution");
break;
case LinearProgramming.OPTIMAL:
System.out.println("Optimal solution found");
case LinearProgramming.UNBOUNDED:
System.out.println("Unbounded solution");
}
double[] coef = lp.getCoefficients();
double solution = lp.getSolution();https://stackoverflow.com/questions/53592299
复制相似问题