这对我有用:
http://mail-archives.apache.org/mod_mbox/commons-user/201307.mbox/%3CCAJSjvws+9uC=jMP_A_Mbc4szbJL2VXAwp=Q2A+zZ=51mLeRw6g@mail.gmail.com%3E
我的 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();