How to set types of solution variables such as binary, int
, double
in Apache Commons Math SimplexSolver
? Following is the following program:
332.6666666666667 1.0 8331.666666666668
I want the decision variables to be of type int
not double
; the output should be 333, 0, 8325
if resolved as integer decision variables.
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()); }
source share