Est*_*her 11 java math optimization apache-commons simplex
我正在尝试使用Apache Commons解决优化问题.我在这里为Commons Math 2 找到了一个"Hello World"示例.但是,我想使用Commons Math 3.2,我找不到任何关于如何使用这部分代码的示例:
PointValuePair solution = null;
SimplexSolver solver = new SimplexSolver();
solution = solver.optimize(optData);
Run Code Online (Sandbox Code Playgroud)
具体来说,我不知道什么是optData以及我把约束放在哪里.如果有人给我一个关于如何使用org.apache.commons.math3.optim库的"Hello World"示例,我将不胜感激.
最好的祝愿!
小智 11
这对我有用:
我的max cx版本:Ax <= b,x> = 0.也许不是"hello world"但我希望它有所帮助:
LinearObjectiveFunction f = new LinearObjectiveFunction(c, 0);
Collection<LinearConstraint> constraints = new
ArrayList<LinearConstraint>();
for(int i=0; i<A.length; i++) {
double[] Av = new double[A[i].length];
for(int j=0; j<A[i].length; j++) {
Av[j] = A[i][j];
}
constraints.add(new LinearConstraint(Av, Relationship.LEQ, b[i]));
}
SimplexSolver solver = new SimplexSolver();
PointValuePair optSolution = solver.optimize(new MaxIter(100), f, new
LinearConstraintSet(constraints),
GoalType.MAXIMIZE, new
NonNegativeConstraint(true));
double[] solution;
solution = optSolution.getPoint();
Run Code Online (Sandbox Code Playgroud)