Package org.apache.commons.math.optimization

Examples of org.apache.commons.math.optimization.RealPointValuePair


      multiDirectional.setMaxIterations(100);
      multiDirectional.setMaxEvaluations(1000);

      final Gaussian2D function = new Gaussian2D(0.0, 0.0, 1.0);

      RealPointValuePair estimate = multiDirectional.optimize(function,
                                    GoalType.MAXIMIZE, function.getMaximumPosition());

      final double EPSILON = 1e-5;

      final double expectedMaximum = function.getMaximum();
      final double actualMaximum = estimate.getValue();
      Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON);

      final double[] expectedPosition = function.getMaximumPosition();
      final double[] actualPosition = estimate.getPoint();
      Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON );
      Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON );

  }
View Full Code Here


        }, new double[] { 1, 1, 1 });
        NonLinearConjugateGradientOptimizer optimizer =
            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
        optimizer.setMaxIterations(100);
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-6, 1.0e-6));
        RealPointValuePair optimum =
                optimizer.optimize(problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
        assertTrue(optimum.getValue() > 0.5);
    }
View Full Code Here

        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-13, 1.0e-13));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-15);
        solver.setRelativeAccuracy(1.0e-15);
        optimizer.setLineSearchSolver(solver);
        RealPointValuePair optimum1 =
            optimizer.optimize(problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 });
        assertEquals(1.0, optimum1.getPoint()[0], 1.0e-5);
        assertEquals(1.0, optimum1.getPoint()[1], 1.0e-5);
        assertEquals(1.0, optimum1.getPoint()[2], 1.0e-5);
        assertEquals(1.0, optimum1.getPoint()[3], 1.0e-5);

        LinearProblem problem2 = new LinearProblem(new double[][] {
                { 10.00, 7.00, 8.10, 7.20 },
                7.08, 5.04, 6.00, 5.00 },
                8.00, 5.98, 9.89, 9.00 },
                6.99, 4.99, 9.00, 9.98 }
        }, new double[] { 32, 23, 33, 31 });
        RealPointValuePair optimum2 =
            optimizer.optimize(problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 });
        assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1);
        assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1);
        assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1);
        assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1);

    }
View Full Code Here

        LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 3 }, 0);
        Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
        constraints.add(new LinearConstraint(new double[] { 1 }, Relationship.LEQ, 10));

        SimplexSolver solver = new SimplexSolver();
        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, false);
        assertEquals(10.0, solution.getPoint()[0], 0.0);
        assertEquals(30.0, solution.getValue(), 0.0);
    }
View Full Code Here

        constraints.add(new LinearConstraint(new double[] { 1, 0 }, Relationship.LEQ, 2));
        constraints.add(new LinearConstraint(new double[] { 0, 1 }, Relationship.LEQ, 3));
        constraints.add(new LinearConstraint(new double[] { 1, 1 }, Relationship.LEQ, 4));

        SimplexSolver solver = new SimplexSolver();
        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, false);
        assertEquals(2.0, solution.getPoint()[0], 0.0);
        assertEquals(2.0, solution.getPoint()[1], 0.0);
        assertEquals(50.0, solution.getValue(), 0.0);
    }
View Full Code Here

        constraints.add(new LinearConstraint(new double[] { 1, 2 }, Relationship.LEQ, 6));
        constraints.add(new LinearConstraint(new double[] { 3, 2 }, Relationship.LEQ, 12));
        constraints.add(new LinearConstraint(new double[] { 0, 1 }, Relationship.GEQ, 0));

        SimplexSolver solver = new SimplexSolver();
        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, false);
        assertEquals(4.0, solution.getPoint()[0], 0.0);
        assertEquals(0.0, solution.getPoint()[1], 0.0);
        assertEquals(-13.0, solution.getValue(), 0.0);
    }
View Full Code Here

        Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
        constraints.add(new LinearConstraint(new double[] { 1, 1 }, Relationship.GEQ, 6));
        constraints.add(new LinearConstraint(new double[] { 1, 2 }, Relationship.LEQ, 14));

        SimplexSolver solver = new SimplexSolver();
        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, false);
        assertEquals(-2.0, solution.getPoint()[0], 0.0);
        assertEquals(8.0, solution.getPoint()[1], 0.0);
        assertEquals(12.0, solution.getValue(), 0.0);
    }
View Full Code Here

        constraints.add(new LinearConstraint(new double[] {     8768,   034, 7456 }, Relationship.LEQ,  1923421));
        constraints.add(new LinearConstraint(new double[] { 12342, 234234, 678, 2342 }, Relationship.GEQ,     4356));
        constraints.add(new LinearConstraint(new double[] {    456787652,   23 }, Relationship.EQ,    456356));

        SimplexSolver solver = new SimplexSolver();
        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
        assertEquals(2902.92783505155, solution.getPoint()[0], .0000001);
        assertEquals(480.419243986254, solution.getPoint()[1], .0000001);
        assertEquals(0.0, solution.getPoint()[2], .0000001);
        assertEquals(0.0, solution.getPoint()[3], .0000001);
        assertEquals(0.0, solution.getPoint()[4], .0000001);
        assertEquals(1438556.7491409, solution.getValue(), .0000001);
    }
View Full Code Here

      constraints.add(new LinearConstraint(new double[] {  9, 8, 0 }, Relationship.EQ,  17));
      constraints.add(new LinearConstraint(new double[] {  0, 7, 8 }, Relationship.LEQ,  7));
      constraints.add(new LinearConstraint(new double[] { 10, 0, 2 }, Relationship.LEQ, 10));

      SimplexSolver solver = new SimplexSolver();
      RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, false);
      assertEquals(1.0, solution.getPoint()[0], 0.0);
      assertEquals(1.0, solution.getPoint()[1], 0.0);
      assertEquals(0.0, solution.getPoint()[2], 0.0);
      assertEquals(15.0, solution.getValue(), 0.0);
  }
View Full Code Here

        LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 1, 1 }, 0);
        Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
        constraints.add(new LinearConstraint(new double[] { 1, 1 }, Relationship.EQ,  0));

        SimplexSolver solver = new SimplexSolver();
        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
        assertEquals(0, solution.getValue(), .0000001);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.optimization.RealPointValuePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.