4
如何在Apache Commons Math SimplexSolver
中設置決策變量類型,如二進制,int
,double
?以下程序的輸出是這樣的:如何在Apache Commons Math SimplexSolver中設置像binary,int和double這樣的決策變量類型?
332.6666666666667
1.0
8331.666666666668
我想決策變量是int
不double
類型;如果作爲整數決策變量求解,輸出應該是333, 0, 8325
。
public static void testSample() throws OptimizationException {
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[]{25, 15}, 0);
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
constraints.add(new LinearConstraint(new double[]{5, 8}, Relationship.LEQ, 5000));
constraints.add(new LinearConstraint(new double[]{1, 4}, Relationship.LEQ, 1500));
constraints.add(new LinearConstraint(new double[]{3, 2}, Relationship.LEQ, 1000));
constraints.add(new LinearConstraint(new double[]{1, 0}, Relationship.GEQ, 1));
constraints.add(new LinearConstraint(new double[]{0, 1}, Relationship.GEQ, 1));
SimplexSolver solver = new SimplexSolver();
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
System.out.println(solution.getPoint()[0]);
System.out.println(solution.getPoint()[1]);
System.out.println(solution.getValue());
}
嗨,謝謝你的回答。在你的答案中,你只是格式化與優化無關的數字。 333 1 8332不是優化答案,優化方案是333 0 8325.通過設置決策變量類型,我們可以得到真正的優化。有沒有人知道如何做到這一點? – user1020082
啊,我誤解了;更上面。對不起,我錯誤地編輯了你的問題。 – trashgod