1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| LinearMultivariateRealFunction objectiveFunction = new LinearMultivariateRealFunction(new double[]{4.0, 3.0}, 0);
ConvexMultivariateRealFunction[] inequalities = new ConvexMultivariateRealFunction[4];
inequalities[0] = new LinearMultivariateRealFunction(new double[]{-1.0, 0.00}, 0.0);
inequalities[1] = new LinearMultivariateRealFunction(new double[]{0.0, -1.00}, 0.0);
inequalities[2] = new LinearMultivariateRealFunction(new double[]{8, 6}, -25);
inequalities[3] = new LinearMultivariateRealFunction(new double[]{-3, -4}, 15);
OptimizationRequest or = new OptimizationRequest(); or.setF0(objectiveFunction); or.setFi(inequalities);
JOptimizer opt = new JOptimizer(); opt.setOptimizationRequest(or);
try { opt.optimize(); } catch (Exception e) { e.printStackTrace(); }
if (opt.getOptimizationResponse() != null) { double[] sol = opt.getOptimizationResponse().getSolution();
for (int i = 0; i < sol.length / 2; i++) { System.out.println("x" + (i + 1) + ": " + Math.round(sol[i]) + "\ty" + (i + 1) + ": " + Math.round(sol[i + 1])); } }
|