use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class LinearDesignTestCases method testP20130409b.
/**
* A specific node of {@linkplain org.ojalgo.optimisation.integer.IntegerProblems#testP20130409b}. Based
* on some changes in ExpressionBasedModel and/or IntegerSolver some nodes started to fail as UNBOUNDED.
* Which seems unreasonable. Must be a problem with either ExpressionBasedModel or LinearSolver. Test case
* sent in by the user / problem reporter
* <a href="http://bugzilla.optimatika.se/show_bug.cgi?id=178">BugZilla</a>
*/
@Test
public void testP20130409b() {
final Variable x1 = Variable.make("x1");
final Variable x2013 = Variable.make("x2013");
final Variable x2014 = Variable.make("x2014");
final Variable x2015 = Variable.make("x2015");
// x2013.setInteger(true);
// x2014.setInteger(true);
// x2015.setInteger(true);
x2013.lower(BigDecimal.valueOf(1245L));
x2014.lower(BigDecimal.valueOf(1269L));
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel();
tmpModel.addVariable(x1);
tmpModel.addVariable(x2013);
tmpModel.addVariable(x2014);
tmpModel.addVariable(x2015);
final Expression obj = tmpModel.addExpression("obj");
obj.set(x1, 1);
obj.weight(BigDecimal.valueOf(1));
final Expression c1 = tmpModel.addExpression("c1");
c1.set(x1, 1);
c1.lower(BigDecimal.valueOf(0));
final Expression c2 = tmpModel.addExpression("c2");
c2.set(x2014, -5000);
c2.set(x2013, 5100);
c2.set(x1, -1);
c2.upper(BigDecimal.valueOf(0));
final Expression c3 = tmpModel.addExpression("c3");
c3.set(x2014, -5000);
c3.set(x2013, 5100);
c3.set(x1, 1);
c3.lower(BigDecimal.valueOf(0));
final Expression c4 = tmpModel.addExpression("c4");
c4.set(x2014, 150);
c4.set(x2013, 5100);
c4.set(x2015, -5000);
c4.set(x1, -1);
c4.upper(BigDecimal.valueOf(0));
final Expression c5 = tmpModel.addExpression("c5");
c5.set(x2014, 150);
c5.set(x2013, 5100);
c5.set(x2015, -5000);
c5.set(x1, 1);
c5.lower(BigDecimal.valueOf(0));
final Expression c6 = tmpModel.addExpression("c6");
c6.set(x2015, 5000);
c6.set(x2014, 5000);
c6.set(x2013, 5000);
c6.level(BigDecimal.valueOf(19105000));
final BigArray tmpExpSol = BigArray.wrap(new BigDecimal[] { BigDecimal.valueOf(4849.999999997941), BigDecimal.valueOf(1245), BigDecimal.valueOf(1269), BigDecimal.valueOf(1307) });
TestUtils.assertTrue("Expected Solution Not Valid", tmpModel.validate(tmpExpSol));
// tmpModel.options.debug(LinearSolver.class);
// tmpModel.options.problem = NumberContext.getGeneral(8);
final Result tmpResult = tmpModel.minimise();
// BasicLogger.debug(tmpResult.toString());
TestUtils.assertEquals("Solution Not Correct", tmpExpSol, tmpResult, new NumberContext(8, 8));
TestUtils.assertTrue("Solver State Not Optimal", tmpResult.getState().isOptimal());
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class DecompositionProblems method testP20110223.
/**
* Peter Abeles reported a problem with ojAlgo his benchmark's invert test. This test case is an attempt
* to recreate the problem. ... The problem turned out to be a pure bug related to creating the inverse
* (applied the pivot row order, to the identity matrix, incorrectly).
*/
@Test
public void testP20110223() {
final NumberContext tmpEqualsNumberContext = new NumberContext(7, 11);
final int tmpDim = 99;
final PhysicalStore<Double> tmpRandom = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
final PhysicalStore<Double> tmpIdentity = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim);
final LU<Double> tmpRefDecomps = new RawLU();
tmpRefDecomps.decompose(tmpRandom);
final MatrixStore<Double> tmpExpected = tmpRefDecomps.getInverse();
final LU<Double> tmpTestDecomp = LU.PRIMITIVE.make();
tmpTestDecomp.decompose(tmpRandom);
MatrixStore<Double> tmpActual = tmpTestDecomp.getInverse();
TestUtils.assertEquals(tmpExpected, tmpActual, tmpEqualsNumberContext);
final MatrixStore<Double> left = tmpActual;
TestUtils.assertEquals(tmpIdentity, left.multiply(tmpRandom), tmpEqualsNumberContext);
TestUtils.assertEquals(tmpIdentity, tmpRandom.multiply(tmpActual), tmpEqualsNumberContext);
tmpTestDecomp.decompose(tmpRandom);
tmpActual = tmpTestDecomp.getInverse();
TestUtils.assertEquals(tmpExpected, tmpActual, tmpEqualsNumberContext);
final MatrixStore<Double> left1 = tmpActual;
TestUtils.assertEquals(tmpIdentity, left1.multiply(tmpRandom), tmpEqualsNumberContext);
TestUtils.assertEquals(tmpIdentity, tmpRandom.multiply(tmpActual), tmpEqualsNumberContext);
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class DecompositionProblems method testP20110126.
@Test
public void testP20110126() {
final int tmpDim = 5;
final PhysicalStore<Double> tmpA = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
final PhysicalStore<Double> tmpI = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim);
final LU<Double> tmpDecomp = LU.PRIMITIVE.make();
tmpDecomp.decompose(tmpA);
TestUtils.assertEquals(tmpA, tmpDecomp, new NumberContext(7, 6));
final MatrixStore<Double> tmpExpected = tmpDecomp.getSolution(tmpI);
tmpDecomp.decompose(tmpA);
final MatrixStore<Double> tmpActual = tmpDecomp.getInverse();
TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class DecompositionProblems method testP20091012.
/**
* Fat matrices were not QR-decomposed correctly ("R" was not created correctly).
*/
@Test
public void testP20091012() {
final PhysicalStore<Double> tmpA = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(5, 9));
final QR<Double> tmpQR = QR.PRIMITIVE.make(tmpA);
tmpQR.decompose(tmpA);
TestUtils.assertEquals(tmpA, tmpQR, new NumberContext(7, 6));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class DegenerateLUCase method testDensePrimitive.
@Test
public void testDensePrimitive() {
final NumberContext tmpEvalContext = new NumberContext(7, 4);
final BasicMatrix tmpMtrxA = RationalMatrix.FACTORY.makeZero(SimpleEquationCase.getBody().countRows(), (int) SimpleEquationCase.getBody().countColumns()).mergeColumns(SimpleEquationCase.getBody()).mergeColumns(SimpleEquationCase.getBody());
final LU<Double> tmpDoubleDecomp = LU.PRIMITIVE.make();
tmpDoubleDecomp.decompose(PrimitiveDenseStore.FACTORY.copy(tmpMtrxA));
// System.out.println("A: " + tmpMtrxA.enforce(tmpEvalContext));
// System.out.println("P: " + new PrimitiveMatrix(tmpDoubleDecomp.getP()).enforce(tmpEvalContext));
// System.out.println("L: " + new PrimitiveMatrix(tmpDoubleDecomp.getL()).enforce(tmpEvalContext));
// System.out.println("PL: " + new PrimitiveMatrix(tmpDoubleDecomp.getP().multiplyRight(tmpDoubleDecomp.getL())).enforce(tmpEvalContext));
// System.out.println("D: " + new PrimitiveMatrix(tmpDoubleDecomp.getD()).enforce(tmpEvalContext));
// System.out.println("U: " + new PrimitiveMatrix(tmpDoubleDecomp.getU()).enforce(tmpEvalContext));
// System.out.println("DU: " + new PrimitiveMatrix(tmpDoubleDecomp.getD().multiplyRight(tmpDoubleDecomp.getU())).enforce(tmpEvalContext));
TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(tmpMtrxA), tmpDoubleDecomp, tmpEvalContext);
}
Aggregations