当前位置: 首页>>代码示例>>Java>>正文


Java GoalType类代码示例

本文整理汇总了Java中org.apache.commons.math.optimization.GoalType的典型用法代码示例。如果您正苦于以下问题:Java GoalType类的具体用法?Java GoalType怎么用?Java GoalType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GoalType类属于org.apache.commons.math.optimization包,在下文中一共展示了GoalType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: minimize

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
/**
 * Resolve linear programming problem when minimizing the equation with current constraints. Returns
 *
 * @param solution Solution to minimize the objective the function from.
 * @return Number of printings and cost value.
 */
public Result minimize(Solution solution) {
    updateFunction(solution);
    updateConstraints(solution);
    try {
        RealPointValuePair result = new SimplexSolver().optimize(function, constraints, GoalType.MINIMIZE, true);
        double[] point = result.getPoint();
        if (result.getValue() < 0) {
            return null;
        }
        for (int i = 0; i < point.length; ++i) {
            if (point[i] < 0) {
                return null;
            }
        }
        return new Result(point, context.getSheetCost(), context.getPatternCost());
    } catch (OptimizationException e) {
        logger.debug("LinearResolutionMethod.minimize: " + e.getMessage());
    }
    return null;
}
 
开发者ID:achaussende,项目名称:tp-2D-cutting-stock-problem,代码行数:27,代码来源:LinearResolutionMethod.java

示例2: optimize

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
/** {@inheritDoc} */
public RealPointValuePair optimize(final LinearObjectiveFunction f,
                                   final Collection<LinearConstraint> constraints,
                                   final GoalType goalType, final boolean restrictToNonNegative)
     throws OptimizationException {

    // store linear problem characteristics
    this.function          = f;
    this.linearConstraints = constraints;
    this.goal              = goalType;
    this.nonNegative       = restrictToNonNegative;

    iterations  = 0;

    // solve the problem
    return doOptimize();

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:AbstractLinearOptimizer.java

示例3: testLeastSquares2

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testLeastSquares2()
throws FunctionEvaluationException, ConvergenceException {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
            { 1.0, 0.0 },
            { 0.0, 1.0 }
        }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorialFunction() {
        public double[] value(double[] variables) {
            return factors.operate(variables);
        }
    }, new double[] { 2.0, -3.0 }, new double[] { 10.0, 0.1 });
    NelderMead optimizer = new NelderMead();
    optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1.0, 1.0e-6));
    optimizer.setMaxIterations(200);
    RealPointValuePair optimum =
        optimizer.optimize(ls, GoalType.MINIMIZE, new double[] { 10.0, 10.0 });
    assertEquals( 2.0, optimum.getPointRef()[0], 5.0e-5);
    assertEquals(-3.0, optimum.getPointRef()[1], 8.0e-4);
    assertTrue(optimizer.getEvaluations() > 60);
    assertTrue(optimizer.getEvaluations() < 80);
    assertTrue(optimum.getValue() < 1.0e-6);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:NelderMeadTest.java

示例4: testQuinticMax

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testQuinticMax() throws MathException {
    // The quintic function has zeros at 0, +-0.5 and +-1.
    // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
    UnivariateRealFunction f = new QuinticFunction();
    UnivariateRealOptimizer minimizer = new BrentOptimizer();
    assertEquals(0.27195613, minimizer.optimize(f, GoalType.MAXIMIZE, 0.2, 0.3), 1.0e-8);
    minimizer.setMaximalIterationCount(30);
    try {
        minimizer.optimize(f, GoalType.MAXIMIZE, 0.2, 0.3);
        fail("an exception should have been thrown");
    } catch (MaxIterationsExceededException miee) {
        // expected
    } catch (Exception e) {
        fail("wrong exception caught");
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:BrentMinimizerTest.java

示例5: SimplexTableau

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
/**
 * Build a tableau for a linear problem.
 * @param f linear objective function
 * @param constraints linear constraints
 * @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE}
 * or {@link GoalType#MINIMIZE}
 * @param restrictToNonNegative whether to restrict the variables to non-negative values
 * @param epsilon amount of error to accept in floating point comparisons
 */
SimplexTableau(final LinearObjectiveFunction f,
               final Collection<LinearConstraint> constraints,
               final GoalType goalType, final boolean restrictToNonNegative,
               final double epsilon) {
    this.f                      = f;
    this.constraints            = normalizeConstraints(constraints);
    this.restrictToNonNegative  = restrictToNonNegative;
    this.epsilon                = epsilon;
    this.numDecisionVariables   = f.getCoefficients().getDimension() +
                                  (restrictToNonNegative ? 0 : 1);
    this.numSlackVariables      = getConstraintTypeCounts(Relationship.LEQ) +
                                  getConstraintTypeCounts(Relationship.GEQ);
    this.numArtificialVariables = getConstraintTypeCounts(Relationship.EQ) +
                                  getConstraintTypeCounts(Relationship.GEQ);
    this.tableau = createTableau(goalType == GoalType.MAXIMIZE);
    initializeColumnLabels();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:SimplexTableau.java

示例6: testMoreEstimatedParametersUnsorted

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testMoreEstimatedParametersUnsorted() {
    LinearProblem problem = new LinearProblem(new double[][] {
             { 1.0, 1.0,  0.0,  0.0, 0.0,  0.0 },
             { 0.0, 0.0,  1.0,  1.0, 1.0,  0.0 },
             { 0.0, 0.0,  0.0,  0.0, 1.0, -1.0 },
             { 0.0, 0.0, -1.0,  1.0, 0.0,  1.0 },
             { 0.0, 0.0,  0.0, -1.0, 1.0,  0.0 }
    }, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
    optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-6, 1.0e-6));
    RealPointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 2, 2, 2, 2, 2, 2 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:NonLinearConjugateGradientOptimizerTest.java

示例7: testTableauWithNoArtificialVars

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testTableauWithNoArtificialVars() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    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));
    SimplexTableau tableau =
        new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
    double[][] initialTableau = {
                                 {1, -15, -10, 25, 0, 0, 0, 0},
                                 {0,   1,   0, -1, 1, 0, 0, 2},
                                 {0,   0,   1, -1, 0, 1, 0, 3},
                                 {0,   1,   1, -2, 0, 0, 1, 4}
    };
    assertMatrixEquals(initialTableau, tableau.getData());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:SimplexTableauTest.java

示例8: testInconsistentEquations

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
public void testInconsistentEquations() throws FunctionEvaluationException, OptimizationException {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 1.0,  1.0 },
            { 1.0, -1.0 },
            { 1.0,  3.0 }
    }, new double[] { 3.0, 1.0, 4.0 });

    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[] { 1, 1 });
    assertTrue(optimum.getValue() > 0.1);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:NonLinearConjugateGradientOptimizerTest.java

示例9: testOneSet

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
public void testOneSet() throws FunctionEvaluationException, OptimizationException {

        LinearProblem problem = new LinearProblem(new double[][] {
                {  1,  0, 0 },
                { -1,  1, 0 },
                {  0, -1, 1 }
        }, 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 });
        assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
        assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
        assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);

    }
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:NonLinearConjugateGradientOptimizerTest.java

示例10: testPowell

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testPowell()
  throws FunctionEvaluationException, ConvergenceException {

  Powell powell = new Powell();
  NelderMead optimizer = new NelderMead();
  optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1.0, 1.0e-3));
  optimizer.setMaxIterations(200);
  RealPointValuePair optimum =
    optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3.0, -1.0, 0.0, 1.0 });
  assertEquals(powell.getCount(), optimizer.getEvaluations());
  assertTrue(optimizer.getEvaluations() > 110);
  assertTrue(optimizer.getEvaluations() < 130);
  assertTrue(optimum.getValue() < 2.0e-3);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:NelderMeadTest.java

示例11: testQuinticMin

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testQuinticMin() {
    // The quintic function has zeros at 0, +-0.5 and +-1.
    // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
    UnivariateRealFunction f = new QuinticFunction();
    UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(4312000053L);
    MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer =
        new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying, 5, g);

    UnivariateRealPointValuePair optimum
        = optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2);
    Assert.assertEquals(-0.2719561293, optimum.getPoint(), 1e-9);
    Assert.assertEquals(-0.0443342695, optimum.getValue(), 1e-9);

    UnivariateRealPointValuePair[] optima = optimizer.getOptima();
    for (int i = 0; i < optima.length; ++i) {
        Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1e-9);
    }
    Assert.assertTrue(optimizer.getEvaluations() >= 50);
    Assert.assertTrue(optimizer.getEvaluations() <= 100);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:MultiStartUnivariateRealOptimizerTest.java

示例12: testLeastSquares1

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testLeastSquares1()
throws FunctionEvaluationException, ConvergenceException {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
            { 1.0, 0.0 },
            { 0.0, 1.0 }
        }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorialFunction() {
        public double[] value(double[] variables) {
            return factors.operate(variables);
        }
    }, new double[] { 2.0, -3.0 });
    NelderMead optimizer = new NelderMead();
    optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1.0, 1.0e-6));
    optimizer.setMaxIterations(200);
    RealPointValuePair optimum =
        optimizer.optimize(ls, GoalType.MINIMIZE, new double[] { 10.0, 10.0 });
    assertEquals( 2.0, optimum.getPointRef()[0], 3.0e-5);
    assertEquals(-3.0, optimum.getPointRef()[1], 4.0e-4);
    assertTrue(optimizer.getEvaluations() > 60);
    assertTrue(optimizer.getEvaluations() < 80);
    assertTrue(optimum.getValue() < 1.0e-6);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:NelderMeadTest.java

示例13: testBadFunction

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testBadFunction() {
    UnivariateRealFunction f = new UnivariateRealFunction() {
            public double value(double x) {
                if (x < 0) {
                    throw new MathUserException();
                }
                return 0;
            }
        };
    UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(4312000053L);
    MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer =
        new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying, 5, g);
 
    try {
        optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2);
        Assert.fail();
    } catch (MathUserException e) {
        // Expected.
    }

    // Ensure that the exception was thrown because no optimum was found.
    Assert.assertTrue(optimizer.getOptima()[0] == null);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:MultiStartUnivariateRealOptimizerTest.java

示例14: testMath283

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@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 );

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:MultiDirectionalTest.java

示例15: testMath272

import org.apache.commons.math.optimization.GoalType; //导入依赖的package包/类
@Test
public void testMath272() throws OptimizationException {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 2, 2, 1 }, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] { 1, 1, 0 }, Relationship.GEQ,  1));
    constraints.add(new LinearConstraint(new double[] { 1, 0, 1 }, Relationship.GEQ,  1));
    constraints.add(new LinearConstraint(new double[] { 0, 1, 0 }, Relationship.GEQ,  1));

    SimplexSolver solver = new SimplexSolver();
    RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true);

    Assert.assertEquals(0.0, solution.getPoint()[0], .0000001);
    Assert.assertEquals(1.0, solution.getPoint()[1], .0000001);
    Assert.assertEquals(1.0, solution.getPoint()[2], .0000001);
    Assert.assertEquals(3.0, solution.getValue(), .0000001);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:SimplexSolverTest.java


注:本文中的org.apache.commons.math.optimization.GoalType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。