Search in sources :

Example 1 with BigArray

use of org.ojalgo.array.BigArray in project ojAlgo by optimatika.

the class BigDenseStore method divideAndCopyColumn.

public void divideAndCopyColumn(final int row, final int column, final BasicArray<BigDecimal> destination) {
    final BigDecimal[] tmpData = data;
    final int tmpRowDim = myRowDim;
    final BigDecimal[] tmpDestination = ((BigArray) destination).data;
    int tmpIndex = row + (column * tmpRowDim);
    final BigDecimal tmpDenominator = tmpData[tmpIndex];
    for (int i = row + 1; i < tmpRowDim; i++) {
        tmpIndex++;
        tmpDestination[i] = tmpData[tmpIndex] = BigFunction.DIVIDE.invoke(tmpData[tmpIndex], tmpDenominator);
    }
}
Also used : BigArray(org.ojalgo.array.BigArray) BigDecimal(java.math.BigDecimal)

Example 2 with BigArray

use of org.ojalgo.array.BigArray in project ojAlgo by optimatika.

the class BigDenseStore method applyCholesky.

public void applyCholesky(final int iterationPoint, final BasicArray<BigDecimal> multipliers) {
    final BigDecimal[] tmpData = data;
    final BigDecimal[] tmpColumn = ((BigArray) multipliers).data;
    if ((myColDim - iterationPoint - 1) > ApplyCholesky.THRESHOLD) {
        final DivideAndConquer tmpConquerer = new DivideAndConquer() {

            @Override
            protected void conquer(final int aFirst, final int aLimit) {
                ApplyCholesky.invoke(tmpData, myRowDim, aFirst, aLimit, tmpColumn);
            }
        };
        tmpConquerer.invoke(iterationPoint + 1, myColDim, ApplyCholesky.THRESHOLD);
    } else {
        ApplyCholesky.invoke(tmpData, myRowDim, iterationPoint + 1, myColDim, tmpColumn);
    }
}
Also used : BigArray(org.ojalgo.array.BigArray) DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) BigDecimal(java.math.BigDecimal)

Example 3 with BigArray

use of org.ojalgo.array.BigArray in project ojAlgo by optimatika.

the class BigDenseStore method applyLU.

public void applyLU(final int iterationPoint, final BasicArray<BigDecimal> multipliers) {
    final BigDecimal[] tmpData = data;
    final BigDecimal[] tmpColumn = ((BigArray) multipliers).data;
    if ((myColDim - iterationPoint - 1) > ApplyLU.THRESHOLD) {
        final DivideAndConquer tmpConquerer = new DivideAndConquer() {

            @Override
            protected void conquer(final int aFirst, final int aLimit) {
                ApplyLU.invoke(tmpData, myRowDim, aFirst, aLimit, tmpColumn, iterationPoint);
            }
        };
        tmpConquerer.invoke(iterationPoint + 1, myColDim, ApplyLU.THRESHOLD);
    } else {
        ApplyLU.invoke(tmpData, myRowDim, iterationPoint + 1, myColDim, tmpColumn, iterationPoint);
    }
}
Also used : BigArray(org.ojalgo.array.BigArray) DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) BigDecimal(java.math.BigDecimal)

Example 4 with BigArray

use of org.ojalgo.array.BigArray in project ojAlgo by optimatika.

the class LinearProblems method testP20180314_70.

/**
 * https://github.com/optimatika/ojAlgo/issues/70
 */
@Test
public void testP20180314_70() {
    Variable x = Variable.make("x").lower(0).weight(-2);
    Variable y = Variable.make("y").lower(0).weight(-2);
    ExpressionsBasedModel model = new ExpressionsBasedModel();
    model.addVariable(x);
    model.addVariable(y);
    model.addExpression().set(x, 3).set(y, 0).lower(2);
    model.addExpression().set(x, 1).set(y, 2).lower(-5);
    model.addExpression().set(x, 3).set(y, 1).upper(2);
    final BigArray expected = BigArray.wrap(BigMath.TWO.multiply(BigMath.THIRD), BigMath.ZERO);
    TestUtils.assertTrue(model.validate(expected));
    Optimisation.Result solution = model.maximise();
    TestUtils.assertTrue(model.validate(solution));
    TestUtils.assertStateNotLessThanOptimal(solution);
}
Also used : BigArray(org.ojalgo.array.BigArray) Variable(org.ojalgo.optimisation.Variable) Result(org.ojalgo.optimisation.Optimisation.Result) Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 5 with BigArray

use of org.ojalgo.array.BigArray in project ojAlgo by optimatika.

the class LinearProblems method testP20180310_61.

/**
 * https://github.com/optimatika/ojAlgo/issues/61
 */
@Test
public void testP20180310_61() {
    final Variable x = Variable.make("x").lower(0);
    final Variable y = Variable.make("y").lower(0);
    final ExpressionsBasedModel model = new ExpressionsBasedModel();
    model.addVariable(x);
    model.addVariable(y);
    model.addExpression("first").set(x, 2).set(y, 3).upper(1);
    model.addExpression("second").set(x, -2).set(y, 3).lower(1);
    final BigArray expected = BigArray.wrap(BigMath.ZERO, BigMath.THIRD);
    final Optimisation.Result result = model.maximise();
    TestUtils.assertEquals(expected, result);
    TestUtils.assertStateNotLessThanOptimal(result);
}
Also used : BigArray(org.ojalgo.array.BigArray) Variable(org.ojalgo.optimisation.Variable) Result(org.ojalgo.optimisation.Optimisation.Result) Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Aggregations

BigArray (org.ojalgo.array.BigArray)10 Test (org.junit.jupiter.api.Test)6 ExpressionsBasedModel (org.ojalgo.optimisation.ExpressionsBasedModel)6 Result (org.ojalgo.optimisation.Optimisation.Result)6 Variable (org.ojalgo.optimisation.Variable)6 BigDecimal (java.math.BigDecimal)5 DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)3 Expression (org.ojalgo.optimisation.Expression)3 Optimisation (org.ojalgo.optimisation.Optimisation)3 NumberContext (org.ojalgo.type.context.NumberContext)3