【问题标题】:Hello World example for SimplexSolverSimplexSolver 的 Hello World 示例
【发布时间】:2013-07-31 00:36:46
【问题描述】:

我正在尝试使用 Apache Commons 解决优化问题。我为 Commons Math 2 找到了一个“Hello World”示例 here。但是,我想使用 Commons Math 3.2,但我找不到任何关于如何使用这部分代码的示例:

PointValuePair solution = null;
SimplexSolver solver = new SimplexSolver();
solution = solver.optimize(optData);

具体来说,我不知道什么是 optData 以及我将约束放在哪里。如果有人告诉我如何使用 org.apache.commons.math3.optim 库的“Hello World”示例,我将不胜感激。

【问题讨论】:

    标签: java math optimization apache-commons simplex


    【解决方案1】:

    这对我有用:

    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 = 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();
    

    【讨论】:

    • 你能说这个方法实现是使用两阶段还是其他?
    猜你喜欢
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多