Java Code Examples for org.apache.commons.math.optimization.RealPointValuePair#getPoint()
The following examples show how to use
org.apache.commons.math.optimization.RealPointValuePair#getPoint() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(); optimizer.setSimplex(new MultiDirectionalSimplex(2)); final Gaussian2D function = new Gaussian2D(0, 0, 1); RealPointValuePair estimate = optimizer.optimize(1000, 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 ); }
Example 2
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(); optimizer.setSimplex(new MultiDirectionalSimplex(2)); final Gaussian2D function = new Gaussian2D(0, 0, 1); RealPointValuePair estimate = optimizer.optimize(1000, 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 ); }
Example 3
Source File: PowellOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @param func Function to optimize. * @param optimum Expected optimum. * @param init Starting point. * @param goal Minimization or maximization. * @param fTol Tolerance (relative error on the objective function) for * "Powell" algorithm. * @param pointTol Tolerance for checking that the optimum is correct. */ private void doTest(MultivariateRealFunction func, double[] optimum, double[] init, GoalType goal, double fTol, double pointTol) { final MultivariateRealOptimizer optim = new PowellOptimizer(fTol, Math.ulp(1d)); final RealPointValuePair result = optim.optimize(1000, func, goal, init); final double[] found = result.getPoint(); for (int i = 0, dim = optimum.length; i < dim; i++) { Assert.assertEquals(optimum[i], found[i], pointTol); } }
Example 4
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 5
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 6
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 7
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 8
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(); optimizer.setSimplex(new MultiDirectionalSimplex(2)); final Gaussian2D function = new Gaussian2D(0, 0, 1); RealPointValuePair estimate = optimizer.optimize(1000, 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 ); }
Example 9
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 10
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 11
Source File: PowellOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @param func Function to optimize. * @param optimum Expected optimum. * @param init Starting point. * @param goal Minimization or maximization. * @param fTol Tolerance (relative error on the objective function) for * "Powell" algorithm. * @param pointTol Tolerance for checking that the optimum is correct. */ private void doTest(MultivariateRealFunction func, double[] optimum, double[] init, GoalType goal, double fTol, double pointTol) { final MultivariateRealOptimizer optim = new PowellOptimizer(fTol, Math.ulp(1d)); final RealPointValuePair result = optim.optimize(1000, func, goal, init); final double[] found = result.getPoint(); for (int i = 0, dim = optimum.length; i < dim; i++) { Assert.assertEquals(optimum[i], found[i], pointTol); } }
Example 12
Source File: MultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() throws FunctionEvaluationException, OptimizationException { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check MultiDirectional multiDirectional = new MultiDirectional(); 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 ); }
Example 13
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 14
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 15
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 16
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 17
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 18
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 19
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }
Example 20
Source File: SimplexSolverTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testMath293() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0)); SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001); Assert.assertEquals(0.0, solution1.getPoint()[1], .0001); Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001); Assert.assertEquals(0.0, solution1.getPoint()[3], .0001); Assert.assertEquals(0.0, solution1.getPoint()[4], .0001); Assert.assertEquals(30.0, solution1.getPoint()[5], .0001); Assert.assertEquals(40.57143, solution1.getValue(), .0001); double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1]; double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3]; double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5]; f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 ); constraints = new ArrayList<LinearConstraint>(); constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0)); constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB)); constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC)); RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); Assert.assertEquals(40.57143, solution2.getValue(), .0001); }