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


Java TestUtils.assertStateNotLessThanOptimal方法代码示例

本文整理汇总了Java中org.ojalgo.TestUtils.assertStateNotLessThanOptimal方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.assertStateNotLessThanOptimal方法的具体用法?Java TestUtils.assertStateNotLessThanOptimal怎么用?Java TestUtils.assertStateNotLessThanOptimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ojalgo.TestUtils的用法示例。


在下文中一共展示了TestUtils.assertStateNotLessThanOptimal方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRelaxedNodeP11

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * P11
 */
public void testRelaxedNodeP11() {

    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).lower(THREE);
    tmpModel.getVariable(1).upper(ONE);
    tmpModel.getVariable(0).lower(FOUR);
    tmpModel.getVariable(1).upper(ZERO);
    tmpModel.getVariable(0).upper(FOUR);

    final Optimisation.Result tmpResult = tmpModel.minimise();

    //TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResult);

    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.00 }, { 0.00 } });

    TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);

    TestUtils.assertEquals(-8.00, tmpModel.minimise().getValue(), PRECISION);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:24,代码来源:UCLAee236aCase.java

示例2: testP20150809

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * Issue reported at GitHub. A set of problems related to when Q is zero - a linear problem. Generally the
 * ConvexSolver is not the right option to handle linear problems, but there is some desireable behaviour.
 */
public void testP20150809() {

    final Primitive64Array tmpExpectedSolution = Primitive64Array.wrap(new double[] { 0.12, -0.05, 0.08, 0.07 });
    final Primitive64Array tmpBoundedSolution = Primitive64Array.wrap(new double[] { 99999, -99999, 99999, 99999 });

    ConvexSolver tmpSolver = P20150809.buildModel(true, false);
    Result tmpResult = tmpSolver.solve();
    TestUtils.assertStateNotLessThanOptimal(tmpResult);
    TestUtils.assertEquals(tmpExpectedSolution, tmpResult);

    tmpSolver = P20150809.buildModel(true, true);
    tmpResult = tmpSolver.solve();
    TestUtils.assertStateNotLessThanOptimal(tmpResult);
    TestUtils.assertEquals(tmpExpectedSolution, tmpResult);

    tmpSolver = P20150809.buildModel(false, false);
    tmpResult = tmpSolver.solve();
    TestUtils.assertEquals(Optimisation.State.UNBOUNDED, tmpResult.getState());

    tmpSolver = P20150809.buildModel(false, true);
    tmpResult = tmpSolver.solve();
    TestUtils.assertStateNotLessThanOptimal(tmpResult); // Since it is now constrained, the solver should be able find the optimal solution.
    TestUtils.assertEquals(tmpBoundedSolution, tmpResult);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:29,代码来源:ConvexProblems.java

示例3: testP20150908

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * Problem reported to ojalgo-user. A simple bug caused a java.lang.ArithmeticException: / by zero. ojAlgo
 * did not handle the case with inequality constraints that are all active (the set of excluded
 * constraints was empty).
 */
public void testP20150908() {

    final PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2, 0 }, { 0, 2 } });
    final PrimitiveDenseStore tmpC = PrimitiveDenseStore.FACTORY.columns(new double[] { 0, 0 });
    final PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -1, -1 } });
    final PrimitiveDenseStore tmpBI = PrimitiveDenseStore.FACTORY.columns(new double[] { -1 });
    final Builder tmpBuilder = new ConvexSolver.Builder(tmpQ, tmpC).inequalities(tmpAI, tmpBI);
    final ConvexSolver tmpSolver = tmpBuilder.build();
    final Optimisation.Result tmpResult = tmpSolver.solve();

    final PrimitiveDenseStore tmpExpectedSolution = PrimitiveDenseStore.FACTORY.columns(new double[] { 0.5, 0.5 });
    final Optimisation.Result tmpExpectedResult = new Optimisation.Result(Optimisation.State.OPTIMAL, 0.5, tmpExpectedSolution);

    TestUtils.assertStateNotLessThanOptimal(tmpResult);

    TestUtils.assertEquals(tmpExpectedResult, tmpResult);

    OptimisationConvexTests.assertDirectAndIterativeEquals(tmpBuilder, null);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:25,代码来源:ConvexProblems.java

示例4: testFacilityLocation

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * http://www.ohio.edu/people/melkonia/math3050/slides/IPextendedintro.ppt Slide 8
 */
public void testFacilityLocation() {

    final ArrayList<Variable> tmpVariables = new ArrayList<>();
    tmpVariables.add(Variable.makeBinary("Factory in LA").weight(9));
    tmpVariables.add(Variable.makeBinary("Factory in SF").weight(5));
    tmpVariables.add(Variable.makeBinary("Warehouse in LA").weight(6));
    tmpVariables.add(Variable.makeBinary("Warehouse in SF").weight(4));

    final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel();
    tmpModel.addVariables(tmpVariables);

    final Expression tmpBudgetCost = tmpModel.addExpression("Budget").upper(10);
    tmpBudgetCost.set(tmpVariables.get(0), 6);
    tmpBudgetCost.set(tmpVariables.get(1), 3);
    tmpBudgetCost.set(tmpVariables.get(2), 5);
    tmpBudgetCost.set(tmpVariables.get(3), 2);

    //tmpModel.options.debug(GenericSolver.class);

    final Result tmpResult = tmpModel.maximise();

    TestUtils.assertStateNotLessThanOptimal(tmpResult);

    TestUtils.assertEquals(15.0, tmpResult.getValue());

    TestUtils.assertEquals(0.0, tmpResult.doubleValue(0));
    TestUtils.assertEquals(1.0, tmpResult.doubleValue(1));
    TestUtils.assertEquals(1.0, tmpResult.doubleValue(2));
    TestUtils.assertEquals(1.0, tmpResult.doubleValue(3));
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:34,代码来源:DesignCase.java

示例5: testRelaxedButConstrainedToOptimalMIP

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testRelaxedButConstrainedToOptimalMIP() {

        final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);

        tmpModel.getVariable(0).lower(TWO);
        tmpModel.getVariable(0).upper(TWO);
        tmpModel.getVariable(1).lower(TWO);
        tmpModel.getVariable(1).upper(TWO);

        final Optimisation.Result tmpResult = tmpModel.minimise();

        //TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
        TestUtils.assertStateNotLessThanOptimal(tmpResult);

        final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } });

        TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:19,代码来源:UCLAee236aCase.java

示例6: testP20140819

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * <a href="http://bugzilla.optimatika.se/show_bug.cgi?id=211">BugZilla-211</a>
 */
public void testP20140819() {

    final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel();

    final double[] tmpWeights = new double[] { 2691.5357279536333, 2600.760150603986, 2605.8958795795374, 2606.7208332501104, 2715.0757845953835,
            2602.194912040238, 2606.0069468717575, 2609.0385816244316, 2750.0520522057927, 2602.048261785581, 2600.507229973181, 2602.046307869504,
            2721.343937605796, 2601.7367414553805, 2600.595318433882, 2599.405979211142 };

    for (int v = 0; v < tmpWeights.length; v++) {
        tmpModel.addVariable(Variable.make("x" + v).integer(true).lower(0).upper(414).weight(tmpWeights[v]));
    }

    // 117 <= 30 30 30 30 0 4 0 0 0 4 0 0 0 4 0 0 <= 14868
    // 36 <= 0 4 0 0 40 40 40 40 0 0 4 0 0 0 4 0 <= 170569
    // 341 <= 0 0 8 0 0 0 8 0 68 68 68 68 0 0 0 5 <= 140833
    // 413 <= 0 0 0 8 0 0 0 9 0 0 0 6 59 59 59 59 <= 48321

    final int[] tmpLower = new int[] { 117, 36, 341, 413 };
    final int[] tmpUpper = new int[] { 14868, 170569, 140833, 48321 };
    final int[][] tmpFactors = new int[4][];
    tmpFactors[0] = new int[] { 30, 30, 30, 30, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0 };
    tmpFactors[1] = new int[] { 0, 4, 0, 0, 40, 40, 40, 40, 0, 0, 4, 0, 0, 0, 4, 0 };
    tmpFactors[2] = new int[] { 0, 0, 8, 0, 0, 0, 8, 0, 68, 68, 68, 68, 0, 0, 0, 5 };
    tmpFactors[3] = new int[] { 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 6, 59, 59, 59, 59 };

    for (int c = 0; c < tmpFactors.length; c++) {
        final Expression tmpExpr = tmpModel.addExpression("C" + c);
        tmpExpr.lower(tmpLower[c]).upper(tmpUpper[c]);
        for (int v = 0; v < tmpFactors[c].length; v++) {
            tmpExpr.set(v, tmpFactors[c][v]);
        }
    }

    // tmpModel.options.debug(IntegerSolver.class);

    final Result tmpResult = tmpModel.minimise();

    if (OptimisationIntegerTests.DEBUG) {
        BasicLogger.debug(tmpResult);
        BasicLogger.debug(tmpModel);
    }

    TestUtils.assertStateNotLessThanOptimal(tmpResult);

    TestUtils.assertTrue(tmpModel.validate(tmpResult));

}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:51,代码来源:IntegerProblems.java

示例7: builAndTestModel

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
static void builAndTestModel(final PrimitiveDenseStore[] matrices, final PrimitiveDenseStore expectedSolution, final NumberContext modelValidationContext,
        final boolean testSolverDirectly) {

    final MatrixStore<Double> tmpPartQ = expectedSolution.transpose().multiply(matrices[2].multiply(expectedSolution));
    final MatrixStore<Double> tmpPartC = matrices[3].transpose().multiply(expectedSolution);

    final double tmpExpectedValue = tmpPartQ.multiply(HALF.doubleValue()).subtract(tmpPartC).doubleValue(0);

    final Optimisation.Result tmpExpectedResult = new Optimisation.Result(Optimisation.State.OPTIMAL, tmpExpectedValue, expectedSolution);

    final ExpressionsBasedModel tmpModel = ConvexProblems.buildModel(matrices, expectedSolution);

    OptimisationConvexTests.assertDirectAndIterativeEquals(tmpModel, modelValidationContext);

    if (DEBUG) {
        tmpModel.options.debug(ConvexSolver.class);
        tmpModel.options.validate = false;
    }

    TestUtils.assertTrue("Expected solution not ok!", tmpModel.validate(tmpExpectedResult, modelValidationContext));
    TestUtils.assertTrue("Expected solution not ok!", tmpModel.validate(modelValidationContext)); // The expected solution is written to the variables

    // When/if the correct/optimal solution is used to kickStart ojAlgo should return that solution
    final Result tmpInitialisedModelResult = tmpModel.minimise();
    TestUtils.assertStateNotLessThanOptimal(tmpInitialisedModelResult);
    TestUtils.assertEquals(tmpExpectedResult, tmpInitialisedModelResult, modelValidationContext);
    TestUtils.assertEquals(tmpExpectedValue, tmpInitialisedModelResult.getValue(), modelValidationContext);
    TestUtils.assertEquals(tmpExpectedValue, tmpModel.objective().evaluate(tmpInitialisedModelResult).doubleValue(), modelValidationContext);
    TestUtils.assertEquals(tmpExpectedValue, tmpModel.objective().toFunction().invoke(expectedSolution).doubleValue(), modelValidationContext);

    for (final Variable tmpVariable : tmpModel.getVariables()) {
        tmpVariable.setValue(null);
    }

    // Initial variable values have been cleared
    final Result tmpUninitialisedModelResult = tmpModel.minimise();
    TestUtils.assertStateNotLessThanOptimal(tmpUninitialisedModelResult);
    TestUtils.assertEquals(tmpExpectedResult, tmpUninitialisedModelResult, modelValidationContext);
    TestUtils.assertEquals(tmpExpectedValue, tmpUninitialisedModelResult.getValue(), modelValidationContext);
    TestUtils.assertEquals(tmpExpectedValue, tmpModel.objective().evaluate(tmpUninitialisedModelResult).doubleValue(), modelValidationContext);
    TestUtils.assertEquals(tmpExpectedValue, tmpModel.objective().toFunction().invoke(expectedSolution).doubleValue(), modelValidationContext);

    if (testSolverDirectly) {

        final ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(matrices);
        final ConvexSolver tmpSolver = tmpBuilder.build();
        // tmpSolver.options.debug(ConvexSolver.class);
        // tmpSolver.options.validate = false;
        final Optimisation.Result tmpResult = tmpSolver.solve();

        TestUtils.assertStateNotLessThanOptimal(tmpResult);
        TestUtils.assertEquals(tmpExpectedResult, tmpResult, NumberContext.getGeneral(2, 4));
        TestUtils.assertEquals(tmpExpectedValue, tmpModel.objective().evaluate(tmpResult).doubleValue(), NumberContext.getGeneral(4, 8));
    }
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:56,代码来源:ConvexProblems.java

示例8: testP20111010

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * Depending on how the constraints were constructed the solver could fail to solve and report the problem
 * to be unbounded.
 */
public void testP20111010() {

    final Variable[] tmpVariables = new Variable[] { new Variable("X").lower(ZERO).weight(ONE), new Variable("Y").lower(ZERO).weight(ZERO),
            new Variable("Z").lower(ZERO).weight(ZERO) };
    final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);

    final Expression tmpExprC1 = tmpModel.addExpression("C1");
    tmpExprC1.level(ZERO);
    tmpExprC1.set(0, ONE);

    final Expression tmpExprC2 = tmpModel.addExpression("C2");
    tmpExprC2.level(ZERO);
    tmpExprC2.set(0, ONE);
    tmpExprC2.set(1, NEG);

    final Expression tmpExprC3 = tmpModel.addExpression("C3");
    tmpExprC3.level(ZERO);
    tmpExprC3.set(0, ONE);
    tmpExprC3.set(2, NEG);

    final BasicMatrix tmpExpectedSolution = PrimitiveMatrix.FACTORY.makeZero(3, 1);

    final Optimisation.Result tmpResult11 = tmpModel.minimise();
    //TestUtils.assertEquals(tmpExpectedState, tmpResult11.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResult11);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResult11));

    tmpExprC2.set(0, NEG);
    tmpExprC2.set(1, ONE);

    tmpExprC3.set(0, ONE);
    tmpExprC3.set(2, NEG);

    final Optimisation.Result tmpResultN1 = tmpModel.minimise();
    //TestUtils.assertEquals(tmpExpectedState, tmpResultN1.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResultN1);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResultN1));

    tmpExprC2.set(0, ONE);
    tmpExprC2.set(1, NEG);

    tmpExprC3.set(0, NEG);
    tmpExprC3.set(2, ONE);

    final Optimisation.Result tmpResult1N = tmpModel.minimise();
    //TestUtils.assertEquals(tmpExpectedState, tmpResult1N.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResult1N);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResult1N));

    tmpExprC2.set(0, NEG);
    tmpExprC2.set(1, ONE);

    tmpExprC3.set(0, NEG);
    tmpExprC3.set(2, ONE);

    final Optimisation.Result tmpResultNN = tmpModel.minimise();
    //TestUtils.assertEquals(tmpExpectedState, tmpResultNN.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResultNN);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResultNN));
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:65,代码来源:LinearProblems.java

示例9: testP20170508

import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
 * There were several problems (symptoms) related to this case. This test primarily tests that the
 * returned solution is actually valid. There was a problem (among others) that a subproblem from the
 * Markowitz model class (set up this way) did not produce a valid/feasible solution.
 */
public void testP20170508() {

    final BigDecimal raf = BigDecimal.valueOf(177.82794100389228);

    final ExpressionsBasedModel model = FinancePortfolioProblem.buildModel(P20170508.COVARIANCES, P20170508.RETURNS, raf);

    //        model.options.debug(Optimisation.Solver.class);
    //        model.options.validate = false;

    final BigDecimal w0 = BigDecimal.valueOf(0.9639383);
    final BigDecimal w1 = BigDecimal.valueOf(0.036061702);

    model.getVariable(0).setValue(w0);
    model.getVariable(1).setValue(w1);

    final Result result = model.minimise();

    if (DEBUG) {
        BasicLogger.debug(result);
    }

    TestUtils.assertStateNotLessThanOptimal(result);
    TestUtils.assertTrue(model.validate());
    TestUtils.assertTrue(model.validate(result));

    OptimisationConvexTests.assertDirectAndIterativeEquals(model);
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:33,代码来源:FinancePortfolioProblem.java


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