• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Optimisation类的典型用法和代码示例

java 1次浏览

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

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

示例1: handle

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
protected final BasicMatrix handle(final Optimisation.Result optimisationResult) {

        final int tmpLength = myVariables.length;

        myOptimisationState = optimisationResult.getState();
        final boolean tmpFeasible = optimisationResult.getState().isFeasible();
        final boolean tmpShortingAllowed = this.isShortingAllowed();

        final Builder<PrimitiveMatrix> tmpMtrxBuilder = MATRIX_FACTORY.getBuilder(tmpLength);

        BigDecimal tmpValue;
        for (int i = 0; i < tmpLength; i++) {
            if (tmpFeasible) {
                tmpValue = tmpShortingAllowed ? optimisationResult.get(i) : optimisationResult.get(i).max(ZERO);
            } else {
                tmpValue = ZERO;
            }
            myVariables[i].setValue(tmpValue);
            tmpMtrxBuilder.set(i, tmpValue);
        }

        return tmpMtrxBuilder.get();
    }
 

开发者ID:optimatika,
项目名称:ojAlgo-finance,
代码行数:24,
代码来源:OptimisedPortfolio.java

示例2: translate

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
Optimisation.State translate(final IloCplex.Status status) {
    if (status.equals(Status.Bounded)) {
        return State.VALID;
    } else if (status.equals(Status.Error)) {
        return State.FAILED;
    } else if (status.equals(Status.Feasible)) {
        return State.FEASIBLE;
    } else if (status.equals(Status.Infeasible)) {
        return State.INFEASIBLE;
    } else if (status.equals(Status.InfeasibleOrUnbounded)) {
        return State.INVALID;
    } else if (status.equals(Status.Optimal)) {
        return State.OPTIMAL;
    } else if (status.equals(Status.Unbounded)) {
        return State.UNBOUNDED;
    } else if (status.equals(Status.Unknown)) {
        return State.UNEXPLORED;
    } else {
        return State.FAILED;
    }
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:22,
代码来源:SolverCPLEX.java

示例3: testCompensate

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * https://github.com/optimatika/ojAlgo-extensions/issues/3 <br>
 * "compensating" didn't work because of an incorrectly used stream - did peek(...) instead of map(...).
 */
@Test
public void testCompensate() {

    ExpressionsBasedModel.addIntegration(SolverCPLEX.INTEGRATION);

    final ExpressionsBasedModel test = new ExpressionsBasedModel();
    test.addVariable(Variable.make("X1").lower(0).upper(5).weight(1));
    test.addVariable(Variable.make("X2").lower(0).upper(5).weight(1));
    test.addVariable(Variable.make("X3").level(4).weight(1));
    final Expression expressions = test.addExpression("1").upper(5);
    expressions.set(0, 1).set(1, 1).set(2, 1);
    final Optimisation.Result result = test.maximise();

    Assert.assertTrue(test.validate(result));

    Assert.assertTrue(result.getState().isOptimal());

    Assert.assertEquals(5.0, result.getValue(), PrimitiveMath.MACHINE_EPSILON);

    Assert.assertEquals(0.0, result.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(1.0, result.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(4.0, result.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:28,
代码来源:ProblemCPLEX.java

示例4: testGitHubIssue2

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * https://github.com/optimatika/ojAlgo-extensions/issues/2 <br>
 * Reported as a problem with the Gurobi integration
 */
@Test
public void testGitHubIssue2() {

    final Variable[] objective = new Variable[] { new Variable("X1").weight(0.8), new Variable("X2").weight(0.2), new Variable("X3").weight(0.7),
            new Variable("X4").weight(0.3), new Variable("X5").weight(0.6), new Variable("X6").weight(0.4) };

    ExpressionsBasedModel.addIntegration(SolverCPLEX.INTEGRATION);
    final ExpressionsBasedModel model = new ExpressionsBasedModel(objective);

    model.addExpression("C1").set(0, 1).set(2, 1).set(4, 1).level(23);
    model.addExpression("C2").set(1, 1).set(3, 1).set(5, 1).level(23);
    model.addExpression("C3").set(0, 1).lower(10);
    model.addExpression("C4").set(2, 1).lower(8);
    model.addExpression("C5").set(4, 1).lower(5);

    final Optimisation.Result result = model.maximise();

    // A valid solution of 25.8 can be produced with:
    //     X1=10, X2=0, X3=8, X4=0, X5=5, X6=23
    Assert.assertEquals(25.8, result.getValue(), 0.001);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:26,
代码来源:ProblemCPLEX.java

示例5: testCompensate

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * https://github.com/optimatika/ojAlgo-extensions/issues/3 <br>
 * "compensating" didn't work because of an incorrectly used stream - did peek(...) instead of map(...).
 * <br>
 * Reported as a problem with the CPLEX integration
 */
@Test
public void testCompensate() {

    ExpressionsBasedModel.addIntegration(SolverGurobi.INTEGRATION);

    final ExpressionsBasedModel test = new ExpressionsBasedModel();
    test.addVariable(Variable.make("X1").lower(0).upper(5).weight(1));
    test.addVariable(Variable.make("X2").lower(0).upper(5).weight(1));
    test.addVariable(Variable.make("X3").level(4).weight(1));
    final Expression expressions = test.addExpression("1").upper(5);
    expressions.set(0, 1).set(1, 1).set(2, 1);
    final Optimisation.Result result = test.maximise();

    Assert.assertTrue(test.validate(result));

    Assert.assertTrue(result.getState().isOptimal());

    Assert.assertEquals(5.0, result.getValue(), PrimitiveMath.MACHINE_EPSILON);

    Assert.assertEquals(0.0, result.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(1.0, result.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(4.0, result.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:30,
代码来源:ProblemGurobi.java

示例6: testGitHubIssue2

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * https://github.com/optimatika/ojAlgo-extensions/issues/2
 */
@Test
public void testGitHubIssue2() {

    final Variable[] objective = new Variable[] { new Variable("X1").weight(0.8), new Variable("X2").weight(0.2), new Variable("X3").weight(0.7),
            new Variable("X4").weight(0.3), new Variable("X5").weight(0.6), new Variable("X6").weight(0.4) };

    ExpressionsBasedModel.addIntegration(SolverGurobi.INTEGRATION);
    final ExpressionsBasedModel model = new ExpressionsBasedModel(objective);

    model.addExpression("C1").set(0, 1).set(2, 1).set(4, 1).level(23);
    model.addExpression("C2").set(1, 1).set(3, 1).set(5, 1).level(23);
    model.addExpression("C3").set(0, 1).lower(10);
    model.addExpression("C4").set(2, 1).lower(8);
    model.addExpression("C5").set(4, 1).lower(5);

    final Optimisation.Result result = model.maximise();

    // A valid solution of 25.8 can be produced with:
    //     X1=10, X2=0, X3=8, X4=0, X5=5, X6=23
    Assert.assertEquals(25.8, result.getValue(), 0.001);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:25,
代码来源:ProblemGurobi.java

示例7: testCompensate

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Copied from ProblemCPLEX <br>
 * https://github.com/optimatika/ojAlgo-extensions/issues/3
 */
@Test
public void testCompensate() {

    ExpressionsBasedModel.addIntegration(SolverJOptimizer.INTEGRATION);

    final ExpressionsBasedModel test = new ExpressionsBasedModel();
    test.addVariable(Variable.make("X1").lower(0).upper(5).weight(1));
    test.addVariable(Variable.make("X2").lower(0).upper(5).weight(1));
    test.addVariable(Variable.make("X3").level(4).weight(1));
    final Expression expressions = test.addExpression("1").upper(5);
    expressions.set(0, 1).set(1, 1).set(2, 1);
    final Optimisation.Result result = test.maximise();

    Assert.assertTrue(test.validate(result));

    Assert.assertTrue(result.getState().isOptimal());

    Assert.assertEquals(5.0, result.getValue(), PrimitiveMath.MACHINE_EPSILON);

    Assert.assertEquals(0.0, result.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(1.0, result.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(4.0, result.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:28,
代码来源:DesignJOptimizer.java

示例8: getBoundKey

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
boundkey getBoundKey(final Optimisation.Constraint modelEntity) {

        if (modelEntity.getLowerLimit() != null) {
            if (modelEntity.getUpperLimit() != null) {
                if (modelEntity.getLowerLimit().compareTo(modelEntity.getUpperLimit()) == 0) {
                    return boundkey.fx;
                } else {
                    return boundkey.ra;
                }
            } else {
                return boundkey.lo;
            }
        } else {
            if (modelEntity.getUpperLimit() != null) {
                return boundkey.up;
            } else {
                return boundkey.fr;
            }
        }
    }
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:21,
代码来源:SolverMosek.java

示例9: testRelaxedNodeP11

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的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

示例10: testP20091102b

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Infeasible problem, but solver reports optimal solution!
 */
@SuppressWarnings("unchecked")
public void testP20091102b() {

    final MatrixStore<Double>[] tmpMtrxs = new MatrixStore[6];

    tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0 } });
    tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 } });
    tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 },
            { 5.429710780966787, 23.181215288234903, 27.883770791602895 }, { 5.910932781021423, 27.883770791602895, 34.37266787775051 } });
    tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } });
    tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 },
            { -1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, -1.0 } });
    tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { -0.8 }, { 0.0 }, { 0.0 } });

    final ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs);

    final ConvexSolver tmpSolver = tmpBuilder.build();

    final Optimisation.Result tmpResult = tmpSolver.solve();

    TestUtils.assertStateLessThanFeasible(tmpResult);

    OptimisationConvexTests.assertDirectAndIterativeEquals(tmpBuilder, null);
}
 

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

示例11: testP20150809

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的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

示例12: testP20150908

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的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

示例13: attempt5

点赞 3

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
static void attempt5(final boolean identity, final boolean addDummyConstraints) {

        final ConvexSolver cs = P20150809.buildModel(identity, addDummyConstraints);

        try {
            final Optimisation.Result solution = cs.solve();
            if ((solution.getState() == Optimisation.State.DISTINCT) || (solution.getState() == Optimisation.State.APPROXIMATE)
                    || (solution.getState() == Optimisation.State.OPTIMAL)) {
                final double[] pt = new double[4];
                for (int i = 0; i < pt.length; i++) {
                    pt[i] = solution.doubleValue(i);
                }

                System.out.println("Objective " + solution.getValue());
                for (int ii = 0; ii < 4; ii++) {
                    System.out.println("x[" + ii + "] = " + solution.doubleValue(ii));
                }
            } else {
                System.out.println("Failure State = " + solution.getState().name());

            }

        } catch (final Exception e) {
            System.out.println(e);
        }
    }
 

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

示例14: assertStateAndSolution

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public static void assertStateAndSolution(final String message, final Optimisation.Result expected, final Optimisation.Result actual,
        final NumberContext context) {

    TestUtils.assertEquals(message + ", different Optimisation.State", expected.getState(), actual.getState());

    if (expected.getState().isFeasible()) {
        TestUtils.assertEquals(message, expected, actual, context);
    }
}
 

开发者ID:optimatika,
项目名称:ojAlgo-finance,
代码行数:10,
代码来源:TestUtils.java

示例15: testFixedVariables

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * https://github.com/optimatika/ojAlgo-extensions/issues/1
 */
@Test
public void testFixedVariables() {

    ExpressionsBasedModel.addIntegration(SolverCPLEX.INTEGRATION);

    final ExpressionsBasedModel test = new ExpressionsBasedModel();
    test.addVariable(Variable.make("V1").level(0.5));
    test.addVariable(Variable.make("V2").lower(0).upper(5).weight(2));
    test.addVariable(Variable.make("V3").lower(0).upper(1).weight(1));
    final Expression expressions = test.addExpression("E1").lower(0).upper(2);
    expressions.set(1, 1).set(2, 1);

    final Optimisation.Result minResult = test.minimise();
    Assert.assertTrue(test.validate(minResult));
    Assert.assertEquals(Optimisation.State.OPTIMAL, minResult.getState());
    Assert.assertEquals(0.0, minResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.5, minResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, minResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, minResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);

    final Optimisation.Result maxResult = test.maximise();
    Assert.assertTrue(test.validate(maxResult));
    Assert.assertEquals(Optimisation.State.OPTIMAL, maxResult.getState());
    Assert.assertEquals(4.0, maxResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.5, maxResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(2.0, maxResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, maxResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:32,
代码来源:ProblemCPLEX.java

示例16: translate

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
State translate(final int status) {
    switch (status) {
    case Status.INFEASIBLE:
        return Optimisation.State.INFEASIBLE;
    case Status.ITERATION_LIMIT:
        return Optimisation.State.APPROXIMATE;
    case Status.CUTOFF:
        return Optimisation.State.APPROXIMATE;
    case Status.INF_OR_UNBD:
        return Optimisation.State.INVALID;
    case Status.INPROGRESS:
        return Optimisation.State.UNEXPLORED;
    case Status.INTERRUPTED:
        return Optimisation.State.UNEXPLORED;
    case Status.LOADED:
        return Optimisation.State.UNEXPLORED;
    case Status.NODE_LIMIT:
        return Optimisation.State.APPROXIMATE;
    case Status.NUMERIC:
        return Optimisation.State.APPROXIMATE;
    case Status.OPTIMAL:
        return Optimisation.State.OPTIMAL;
    case Status.SOLUTION_LIMIT:
        return Optimisation.State.APPROXIMATE;
    case Status.SUBOPTIMAL:
        return Optimisation.State.APPROXIMATE;
    case Status.TIME_LIMIT:
        return Optimisation.State.APPROXIMATE;
    case Status.UNBOUNDED:
        return Optimisation.State.UNBOUNDED;
    default:
        return Optimisation.State.FAILED;
    }

}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:36,
代码来源:SolverGurobi.java

示例17: testFixedVariables

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * https://github.com/optimatika/ojAlgo-extensions/issues/1 <br>
 * Reported as a problem with the CPLEX integration
 */
@Test
public void testFixedVariables() {

    ExpressionsBasedModel.addIntegration(SolverGurobi.INTEGRATION);

    final ExpressionsBasedModel test = new ExpressionsBasedModel();
    test.addVariable(Variable.make("V1").level(0.5));
    test.addVariable(Variable.make("V2").lower(0).upper(5).weight(2));
    test.addVariable(Variable.make("V3").lower(0).upper(1).weight(1));
    final Expression expressions = test.addExpression("E1").lower(0).upper(2);
    expressions.set(1, 1).set(2, 1);

    final Optimisation.Result minResult = test.minimise();
    Assert.assertTrue(test.validate(minResult));
    Assert.assertEquals(Optimisation.State.OPTIMAL, minResult.getState());
    Assert.assertEquals(0.0, minResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.5, minResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, minResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, minResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);

    final Optimisation.Result maxResult = test.maximise();
    Assert.assertTrue(test.validate(maxResult));
    Assert.assertEquals(Optimisation.State.OPTIMAL, maxResult.getState());
    Assert.assertEquals(4.0, maxResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.5, maxResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(2.0, maxResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, maxResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:33,
代码来源:ProblemGurobi.java

示例18: solve

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public Result solve(final Result kickStarter) {

        //  myOptimizationRequest.setInitialPoint(new double[] { 0.2, 0.2 });

        final OptimizationRequestHandler tmpHandler = myRequest instanceof LPOptimizationRequest ? new LPPrimalDualMethod() : null;

        if (myRequest instanceof LPOptimizationRequest) {
            ((LPOptimizationRequest) myRequest).setPresolvingDisabled(true);
        }

        DEFAULT.configure(myRequest, tmpHandler, myOptions);
        final Optional<Configurator> optional = myOptions.getConfigurator(Configurator.class);
        if (optional.isPresent()) {
            optional.get().configure(myRequest, tmpHandler, myOptions);
        }

        // myOptimizer.setOptimizationRequest(myOptimizationRequest);
        tmpHandler.setOptimizationRequest(myRequest);
        try {

            tmpHandler.optimize();
        } catch (final JOptimizerException exception) {

            exception.printStackTrace();
        }

        final OptimizationResponse response = tmpHandler.getOptimizationResponse();

        final State retState = Optimisation.State.OPTIMAL;
        // final double retValue = response.getValue();
        final Access1D<Double> retSolution = Access1D.wrap(response.getSolution());

        return new Optimisation.Result(retState, retSolution);
    }
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:35,
代码来源:SolverJOptimizer.java

示例19: testSimplyLowerAndUpperBounds

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
@Test
public void testSimplyLowerAndUpperBounds() {

    ExpressionsBasedModel.addIntegration(SolverJOptimizer.INTEGRATION);

    final ExpressionsBasedModel model = new ExpressionsBasedModel();
    model.addVariable(Variable.make("A").level(2).weight(3));
    model.addVariable(Variable.make("B").lower(1).upper(3).weight(2));
    model.addVariable(Variable.make("C").lower(0).upper(4).weight(1));
    model.addExpression("SUM").set(0, 1).set(1, 1).set(2, 1).level(6);

    final Optimisation.Result minResult = model.minimise();
    Assert.assertTrue(model.validate(minResult));
    Assert.assertTrue(minResult.getState().isOptimal());
    Assert.assertEquals(11, minResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(2, minResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(1, minResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(3, minResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);

    final Optimisation.Result maxResult = model.maximise();
    Assert.assertTrue(model.validate(maxResult));
    Assert.assertTrue(maxResult.getState().isOptimal());
    Assert.assertEquals(13, maxResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(2, maxResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(3, maxResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(1, maxResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:28,
代码来源:DesignJOptimizer.java

示例20: testFixedVariables

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Copied from ProblemCPLEX <br>
 * https://github.com/optimatika/ojAlgo-extensions/issues/1
 */
@Test
public void testFixedVariables() {

    ExpressionsBasedModel.addIntegration(SolverJOptimizer.INTEGRATION);

    final ExpressionsBasedModel test = new ExpressionsBasedModel();
    test.addVariable(Variable.make("1").level(0.5));
    test.addVariable(Variable.make("2").lower(0).upper(5).weight(2));
    test.addVariable(Variable.make("3").lower(0).upper(1).weight(1));
    final Expression expressions = test.addExpression("1").lower(0).upper(2);
    expressions.set(1, 1).set(2, 1);

    final Optimisation.Result minResult = test.minimise();
    Assert.assertTrue(test.validate(minResult));
    Assert.assertEquals(Optimisation.State.OPTIMAL, minResult.getState());
    Assert.assertEquals(0.0, minResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.5, minResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, minResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, minResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);

    final Optimisation.Result maxResult = test.maximise();
    Assert.assertTrue(test.validate(maxResult));
    Assert.assertEquals(Optimisation.State.OPTIMAL, maxResult.getState());
    Assert.assertEquals(4.0, maxResult.getValue(), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.5, maxResult.doubleValue(0), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(2.0, maxResult.doubleValue(1), PrimitiveMath.MACHINE_EPSILON);
    Assert.assertEquals(0.0, maxResult.doubleValue(2), PrimitiveMath.MACHINE_EPSILON);
}
 

开发者ID:optimatika,
项目名称:ojAlgo-extensions,
代码行数:33,
代码来源:DesignJOptimizer.java

示例21: MaximalSymbolicSteadyState

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public MaximalSymbolicSteadyState(List<Implicant> primeImplicants, Optimisation.Result result) throws Exception {
// Declare fields
arcSet = new ArrayList<Integer>();
Implicant implicant = primeImplicants.get(0);
int numberOfGenes = implicant.p.length;
this.symbolicState = new int[numberOfGenes];
this.inducedPartialState = new int[numberOfGenes];
for (int i = 0; i < numberOfGenes; i++) {
    this.symbolicState[i] = -1;
    this.symbolicState[i] = -1;
}
// Initialize fields
for (int a = 0; a < primeImplicants.size(); a++) {
    long index = (long) a;
    BigDecimal value = result.get(index);
    if (1 == value.intValue()) {
	implicant = primeImplicants.get(a);
	// Initialize partially the symbolic state
	for (int i = 0; i < numberOfGenes; i++) {
	    switch (implicant.p[i]) {
	    case 0:
		this.symbolicState[i] = 0;
		break;
	    case 1:
		this.symbolicState[i] = 1;
		break;
	    case -1:
		break;
	    default:
		throw new Exception("Illegal partial state (illegal value)");
	    }
	}
	// Initialize partially the induced partial state
	this.inducedPartialState[implicant.v] = implicant.c;
    } else {
	// Initialize partially the arc set
	this.arcSet.add(a);
    }
}
   }
 

开发者ID:biobioinfo,
项目名称:project,
代码行数:41,
代码来源:MaximalSymbolicSteadyState.java

示例22: solve

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public Result solve(final Result kickStarter) {

        // Must verify that it actually is an integer solution
        // The kickStarter may be user-supplied
        if ((kickStarter != null) && kickStarter.getState().isFeasible() && this.getIntegerModel().validate(kickStarter)) {
            this.markInteger(null, null, kickStarter);
        }

        this.resetIterationsCount();

        final BranchAndBoundNodeTask rootNodeTask = new BranchAndBoundNodeTask();

        final boolean normalExit = ForkJoinPool.commonPool().invoke(rootNodeTask);

        final Optimisation.Result bestSolutionFound = this.getBestResultSoFar();

        if (bestSolutionFound.getState().isFeasible()) {
            if (normalExit) {
                return new Optimisation.Result(State.OPTIMAL, bestSolutionFound);
            } else {
                return new Optimisation.Result(State.FEASIBLE, bestSolutionFound);
            }
        } else {
            if (normalExit) {
                return new Optimisation.Result(State.INFEASIBLE, bestSolutionFound);
            } else {
                return new Optimisation.Result(State.FAILED, bestSolutionFound);
            }
        }
    }
 

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

示例23: identifyNonIntegerVariable

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Should return the index of the (best) variable to branch on. Returning a negative index means an
 * integer solition has been found (no further branching).
 */
final int identifyNonIntegerVariable(final Optimisation.Result nodeResult, final NodeKey nodeKey) {

    int retVal = -1;

    double fraction;
    double compareFraction = ZERO;
    double maxFraction = ZERO;

    for (int i = 0; i < myIntegerIndices.length; i++) {

        fraction = nodeKey.getFraction(i, nodeResult.doubleValue(myIntegerIndices[i]));
        // [0, 0.5]

        if (!options.feasibility.isZero(fraction)) {

            if (this.isIntegerSolutionFound()) {
                // If an integer solution is already found
                // then scale the fraction by its significane

                compareFraction = fraction * this.getIntegerSignificance(i);

            } else {
                // If not yet found integer solution
                // then compare the remaining/reversed (larger) fraction

                compareFraction = ONE - fraction;
                // [0.5, 1.0]
            }

            if (compareFraction > maxFraction) {
                retVal = i;
                maxFraction = compareFraction;
            }
        }

    }

    return retVal;
}
 

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

示例24: solve

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public Result solve(final Result kickStarter) {

        // Must verify that it actually is an integer solution
        // The kickStarter may be user-supplied
        if ((kickStarter != null) && kickStarter.getState().isFeasible() && this.getIntegerModel().validate(kickStarter)) {
            this.markInteger(null, null, kickStarter);
        }

        this.resetIterationsCount();

        this.setup();

        //     final boolean tmpNormalExit = DaemonPoolExecutor.INSTANCE.invoke(tmpTask);

        //   this.add(new NodeKey(this.getModel()));

        Optimisation.Result retVal = this.getBestResultSoFar();

        if (retVal.getState().isFeasible()) {

            if (normal) {
                retVal = new Optimisation.Result(State.OPTIMAL, retVal);
            } else {
                retVal = new Optimisation.Result(State.FEASIBLE, retVal);
            }

        } else {

            if (normal) {
                retVal = new Optimisation.Result(State.INFEASIBLE, retVal);
            } else {
                retVal = new Optimisation.Result(State.FAILED, retVal);
            }
        }

        return retVal;
    }
 

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

示例25: doBuild

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
@Override
protected ConvexSolver doBuild(final Optimisation.Options options) {

    this.validate();

    if (this.hasInequalityConstraints()) {
        return new IterativeASS(this, options);
    } else if (this.hasEqualityConstraints()) {
        return new QPESolver(this, options);
    } else {
        return new UnconstrainedSolver(this, options);
    }
}
 

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

示例26: testRelaxedNodeP06

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * P6
 */
public void testRelaxedNodeP06() {

    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).lower(THREE);
    tmpModel.getVariable(1).lower(TWO);

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

    TestUtils.assertEquals(State.INFEASIBLE, tmpResult.getState());
}
 

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

示例27: testRelaxedNodeP10

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * P10
 */
public void testRelaxedNodeP10() {

    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).lower(ONE);

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

    TestUtils.assertEquals(State.INFEASIBLE, tmpResult.getState());
}
 

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

示例28: testRelaxedNodeP12

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * P12
 */
public void testRelaxedNodeP12() {

    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).lower(FIVE);

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

    TestUtils.assertEquals(State.INFEASIBLE, tmpResult.getState());
}
 

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

示例29: testVpm2FirstBranch

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public void testVpm2FirstBranch() {

        final File tmpFile = new File(MipLibCase.PATH + "vpm2.mps");
        final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
        final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();

        TestUtils.assertTrue(tmpModel.validate());

        final ExpressionsBasedModel tmpLowerBranchModel = tmpModel.relax(false);
        final ExpressionsBasedModel tmpUpperBranchModel = tmpModel.relax(false);

        tmpLowerBranchModel.getVariable(106).upper(BigMath.ZERO);
        tmpUpperBranchModel.getVariable(106).lower(BigMath.ONE);

        final Optimisation.Result tmpLowerResult = tmpLowerBranchModel.minimise();
        final Optimisation.Result tmpUpperResult = tmpUpperBranchModel.minimise();

        final State tmpLowerState = tmpLowerResult.getState();
        final State tmpUpperState = tmpUpperResult.getState();

        if (!tmpLowerState.isFeasible() && !tmpUpperState.isFeasible()) {
            TestUtils.fail("Both these branches cannot be infeasible!");
        }

        tmpLowerBranchModel.minimise();
        if (tmpLowerState.isFeasible() && !tmpLowerBranchModel.validate(MipLibCase.PRECISION)) {
            TestUtils.fail(MipLibCase.SOLUTION_NOT_VALID);
        }

        tmpUpperBranchModel.minimise();
        if (tmpUpperState.isFeasible() && !tmpUpperBranchModel.validate(MipLibCase.PRECISION)) {
            TestUtils.fail(MipLibCase.SOLUTION_NOT_VALID);
        }
    }
 

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

示例30: main

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
static public void main(final String[] args) throws Exception {

        final ExpressionsBasedModel model = P20150127a.getModel();

        // final Optimisation.Result result = model.solve(null);
        final Optimisation.Result result = model.minimise();
        if (!result.getState().isSuccess()) {
            throw new Exception("Model should be solvable (e.g. x=201, y=-10)?!");
        }

        final BigDecimal valX = result.get(0);
        final BigDecimal valY = result.get(1);
        final int intX = valX.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        final int intY = valY.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();

        // model.options.debug(LinearSolver.class);

        System.out.println("x = " + valX + " ~ " + intX);
        System.out.println("y = " + valY + " ~ " + intY);

        model.validate();
        model.validate(result);

        final List<int[]> coefficients = P20150127a.getCoefficients();

        // Verify solution
        for (final int[] coeff : coefficients) {
            final int value = (coeff[0] * intX) + (coeff[1] * intY);
            final BigDecimal exact = valX.multiply(BigDecimal.valueOf(coeff[0])).add(valY.multiply(BigDecimal.valueOf(coeff[1])));
            if (value >= 0) {
                throw new Exception(coeff[0] + "*x + " + coeff[1] + "*y = " + value + " must be negative (exact: " + exact + ")");
            }
        }
    }
 

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

示例31: testBug1

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public static void testBug1() {
    final Variable[] objective = new Variable[] { new Variable("X").weight(ONE), new Variable("Y").weight(ZERO), new Variable("Z").weight(ZERO) };

    objective[1].setInteger(true);

    final ExpressionsBasedModel model = new ExpressionsBasedModel(objective);

    // c1: X =0
    final Expression c1 = model.addExpression("c1");
    c1.level(ZERO);
    c1.set(0, ONE);

    // c2: -X +5Y =0
    final Expression c2 = model.addExpression("c2");
    c2.level(ZERO);

    c2.set(0, new BigDecimal(-1));
    c2.set(1, ONE);

    // c3: X -Z =0
    final Expression c3 = model.addExpression("c3");
    c3.level(ZERO);
    // bugs with this constraint
    c3.set(0, ONE);
    c3.set(2, new BigDecimal(-1));
    // but not with this one ???
    //c3.setLinearFactor(0, new BigDecimal(-1));
    //c3.setLinearFactor(2, ONE);

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

    BasicLogger.debug(tmpResult.toString());
}
 

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

示例32: main

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
static public void main(final String[] args) throws Exception {
    final ExpressionsBasedModel model = P20150127b.getModel(true, true);

    // model.options.debug(LinearSolver.class);

    // Solve the model
    final Optimisation.Result result = model.minimise();

    // The rest of this code no longer applies, the above model is
    // unsolvable with the new constraints 1<=x<=20 and y<=-1.
    // However, ojAlgo still notices that "something is wrong"
    // (model.options.validate == true).
    if (result.getState().isSuccess()) {
        throw new Exception("Model should NOT be solvable due to constraints on x/y");
        /*
         * if (!result.getState().isSuccess()) throw new Exception(
         * "Model should be solvable (e.g. x=20, y=-1)?!"); // Get the solution BigDecimal valX =
         * result.get(0); BigDecimal valY = result.get(1); int intX = valX.setScale(0,
         * BigDecimal.ROUND_HALF_UP).intValue(); int intY = valY.setScale(0,
         * BigDecimal.ROUND_HALF_UP).intValue(); System.out.println("x = " + valX + " ~ " + intX);
         * System.out.println("y = " + valY + " ~ " + intY); // Verify solution for (int[] coeff :
         * coefficients) { int value = coeff[0] * intX + coeff[1] * intY; BigDecimal exact =
         * valX.multiply(BigDecimal.valueOf(coeff[0])).add(valY.multiply(BigDecimal.valueOf(coeff[1])));
         * if (value >= 0) throw new Exception(coeff[0] + "*x + " + coeff[1] + "*y = " + value +
         * " must be negative (exact: " + exact + ")"); } /*
         */
    }
}
 

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

示例33: testP20111010

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * If the relaxed problem was infeasible you got a NullPointerException instead of a result indicating
 * that the problem is infeasible.
 */
public void testP20111010() {

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

    final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);

    final Expression tmpC1 = tmpModel.addExpression("C1");
    for (int i = 0; i < tmpModel.countVariables(); i++) {
        tmpC1.set(i, ONE);
    }

    tmpC1.level(ONE);

    final Expression tmpC2 = tmpModel.addExpression("C2");
    for (int i = 0; i < tmpModel.countVariables(); i++) {
        tmpC2.set(i, ONE);
    }
    tmpC2.level(TWO);

    final Expression tmpC3 = tmpModel.addExpression("C3");
    for (int i = 0; i < tmpModel.countVariables(); i++) {
        tmpC3.set(i, ONE);
    }
    tmpC3.level(THREE);

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

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

    TestUtils.assertEquals(State.INFEASIBLE, tmpResult.getState());
}
 

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

示例34: testP20130225

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * The IP solver returns infeasible solutions, but the problem seems to actually be with the LP solver.
 * Don't know what the actual solution is. Just check that the solver terminates normally and that the
 * solution is in fact feasible/valid.
 */
public void testP20130225() {

    final ExpressionsBasedModel tmpIntegerModel = P20130225.makeModel();
    final ExpressionsBasedModel tmpRelaxedModel = tmpIntegerModel.relax(false);

    final Optimisation.Result tmpRelaxedResult = tmpRelaxedModel.minimise();
    TestUtils.assertEquals("Solution To Relaxed Problem Not Optimal!", Optimisation.State.OPTIMAL, tmpRelaxedResult.getState());
    TestUtils.assertTrue("Solution To Relaxed Problem Not Valid!", tmpRelaxedModel.validate(tmpRelaxedResult));

    final Optimisation.Result tmpIntegerResult = tmpIntegerModel.minimise();
    TestUtils.assertEquals("Integer Solution Not Optimal!", Optimisation.State.OPTIMAL, tmpIntegerResult.getState());
    TestUtils.assertTrue("Integer Solution Not Valid!", tmpIntegerModel.validate(tmpIntegerResult));
}
 

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

示例35: testP20150127full

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
public void testP20150127full() {

        final ExpressionsBasedModel tmpModel = P20150127a.getModel();

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

        // Model should be solvable (e.g. x=201, y=-10)?!
        TestUtils.assertStateNotLessThanFeasible(tmpResult);

        final BigDecimal tmpSolX = tmpResult.get(0);
        final BigDecimal tmpSolY = tmpResult.get(1);
        final int tmpIntX = tmpSolX.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        final int tmpIntY = tmpSolY.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();

        if (DEBUG) {
            BasicLogger.debug("x = " + tmpSolX + " ~ " + tmpIntX);
            BasicLogger.debug("y = " + tmpSolY + " ~ " + tmpIntY);
        }

        TestUtils.assertTrue("Solution not valid!", tmpModel.validate(tmpResult));

        // Verify solution
        for (final int[] tmpCoeff : P20150127a.getCoefficients()) {
            final int tmpValue = (tmpCoeff[0] * tmpIntX) + (tmpCoeff[1] * tmpIntY);
            final BigDecimal tmpExact = tmpSolX.multiply(BigDecimal.valueOf(tmpCoeff[0])).add(tmpSolY.multiply(BigDecimal.valueOf(tmpCoeff[1])));
            if (tmpValue >= 0) {
                TestUtils.fail(tmpCoeff[0] + "*x + " + tmpCoeff[1] + "*y = " + tmpValue + " must be negative (exact: " + tmpExact + ")");
            }
        }
    }
 

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

示例36: testInfeasibleCase

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Just make sure an obviously infeasible problem is recognised as such - this has been a problem in the
 * past
 */
public void testInfeasibleCase() {

    final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ONE).upper(TWO).weight(ONE),
            new Variable("X2").lower(ONE).upper(TWO).weight(TWO), new Variable("X3").lower(ONE).upper(TWO).weight(THREE) };

    final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);

    final Expression tmpExprQ = tmpModel.addExpression("Q1");
    for (int i = 0; i < tmpModel.countVariables(); i++) {
        for (int j = 0; j < tmpModel.countVariables(); j++) {
            tmpExprQ.set(i, i, Math.random());
        }
    } // May not be positive definite, but infeasibillity should be realised before that becomes a problem
    tmpExprQ.weight(TEN);

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

    final Expression tmpExprC1 = tmpModel.addExpression("C1");
    for (int i = 0; i < tmpModel.countVariables(); i++) {
        tmpExprC1.set(i, ONE);
    }
    tmpExprC1.upper(TWO);

    Optimisation.Result tmpResult = tmpModel.maximise();

    TestUtils.assertFalse(tmpResult.getState().isFeasible());

    tmpExprC1.upper(null);
    tmpExprC1.lower(SEVEN);

    tmpResult = tmpModel.maximise();

    TestUtils.assertFalse(tmpResult.getState().isFeasible());

    OptimisationConvexTests.assertDirectAndIterativeEquals(tmpModel, null);
}
 

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

示例37: testP20090202

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * "I just tested ojalgo v.26 and experienced nullpointer-exceptions when I tried to optimize any QP
 * without equality-constraints." This test case is the same as (same numbers)
 * {@linkplain #testP20091102a()} but with the equality constraints removed.
 */
@SuppressWarnings("unchecked")
public void testP20090202() {

    final MatrixStore<Double>[] tmpMtrxs = new MatrixStore[6];

    tmpMtrxs[0] = null;
    tmpMtrxs[1] = null;
    tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 },
            { 5.429710780966787, 23.181215288234903, 27.883770791602895 }, { 5.910932781021423, 27.883770791602895, 34.37266787775051 } });
    tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } });
    tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 },
            { -1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, -1.0 } });
    tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { 0.0 }, { 0.0 }, { 0.0 } });

    final ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs);

    final ConvexSolver tmpSolver = tmpBuilder.build();

    final Optimisation.Result tmpResult = tmpSolver.solve();

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

    final PhysicalStore<BigDecimal> tmpSolution = BigDenseStore.FACTORY.copy(RationalMatrix.FACTORY.columns(tmpResult));
    tmpSolution.modifyAll(new NumberContext(7, 6).getFunction(BigFunction.getSet()));
    for (final BigDecimal tmpBigDecimal : tmpSolution.asList()) {
        if ((tmpBigDecimal.compareTo(BigMath.ZERO) == -1) || (tmpBigDecimal.compareTo(BigMath.ONE) == 1)) {
            TestUtils.fail("!(0.0 <= " + tmpBigDecimal + " <= 1.0)");
        }
    }

    OptimisationConvexTests.assertDirectAndIterativeEquals(tmpBuilder, null);
}
 

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

示例38: testP20090924

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Infeasible problem, but solver reports optimal solution!
 */
@SuppressWarnings("unchecked")
public void testP20090924() {

    final MatrixStore<Double>[] tmpMtrxs = new MatrixStore[6];

    tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } });
    tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 0.7027946085029227 } });
    tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
            { 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0 },
            { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0 } });
    tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { -0.0 }, { 0.5 }, { 0.25 }, { 0.25 }, { 0.3 }, { -0.0 }, { 0.62 } });
    tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, { 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 },
            { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
            { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 },
            { 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0 },
            { 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 } });
    tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.17 }, { 0.52 }, { 0.3 }, { 0.3 }, { 0.3 }, { 0.15 }, { 1.0 }, { 0.31 },
            { -0.05960220972942152 }, { -0.1144024630877301 }, { -0.12289286964304823 }, { 0.0 }, { -0.02 }, { 0.0 } });

    final ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs);

    final ConvexSolver tmpSolver = tmpBuilder.build();

    final Optimisation.Result tmpResult = tmpSolver.solve();

    TestUtils.assertStateLessThanFeasible(tmpResult);

    OptimisationConvexTests.assertDirectAndIterativeEquals(tmpBuilder, null);
}
 

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

示例39: testP20091102a

点赞 2

import org.ojalgo.optimisation.Optimisation; //导入依赖的package包/类
/**
 * Fick state "failed" men det berodde bara på att antalet iterationer inte räckte för att hitta en
 * korrekt lösning. Ökade "iterationsLimit" så fungerade det. Felet uppstod inte varje gång, men om man
 * körde samma problem (det problem som är test caset) uppreapde gånger fick man till slut ett fel.
 */
@SuppressWarnings("unchecked")
public void testP20091102a() {

    final MatrixStore<Double>[] tmpMtrxs = new MatrixStore[6];

    tmpMtrxs[0] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 1.0, 1.0 } });
    tmpMtrxs[1] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 } });
    tmpMtrxs[2] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.400491304172128, 5.429710780966787, 5.910932781021423 },
            { 5.429710780966787, 23.181215288234903, 27.883770791602895 }, { 5.910932781021423, 27.883770791602895, 34.37266787775051 } });
    tmpMtrxs[3] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.053 }, { 0.0755 }, { 0.0788 } });
    tmpMtrxs[4] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { -0.053, -0.0755, -0.0788 },
            { -1.0, 0.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, -1.0 } });
    tmpMtrxs[5] = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.0 }, { 1.0 }, { 1.0 }, { -0.06 }, { 0.0 }, { 0.0 }, { 0.0 } });

    // Solve the same problem several times
    for (int i = 0; i < 20; i++) {

        final ConvexSolver.Builder tmpBuilder = new ConvexSolver.Builder(tmpMtrxs);

        final ConvexSolver tmpSolver = tmpBuilder.build();

        final Optimisation.Result tmpResult = tmpSolver.solve();

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

        TestUtils.assertEquals(PrimitiveMatrix.FACTORY.rows(new double[][] { { 0.68888888888888888 }, { 0.311111111111111111 }, { 0.0 } }),
                RationalMatrix.FACTORY.columns(tmpResult));
    }
}
 

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


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)