use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class IntegerProblems method testP20130409a.
/**
* apete's implementation of the original problem description.
* <a href="http://bugzilla.optimatika.se/show_bug.cgi?id=178">BugZilla</a>
*/
@Test
public void testP20130409a() {
final Variable[] tmpVariables = new Variable[] { new Variable("x1").lower(BigMath.ZERO).weight(BigMath.ONE), new Variable("x2013").lower(BigMath.ZERO).integer(true), new Variable("x2014").lower(BigMath.ZERO).integer(true) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Expression tmpExpr1 = tmpModel.addExpression("Expr1");
tmpExpr1.set(0, -1);
tmpExpr1.set(1, 5100);
tmpExpr1.set(2, -5000);
tmpExpr1.upper(BigMath.ZERO);
final Expression tmpExpr2 = tmpModel.addExpression("Expr2");
tmpExpr2.set(0, 1);
tmpExpr2.set(1, 5100);
tmpExpr2.set(2, -5000);
tmpExpr2.lower(BigMath.ZERO);
final Expression tmpExpr3 = tmpModel.addExpression("Expr3");
tmpExpr3.set(1, 5000);
tmpExpr3.set(2, 5000);
tmpExpr3.level(new BigDecimal(19105000));
final BigArray tmpExpSol = BigArray.wrap(new BigDecimal[] { BigDecimal.valueOf(4200.000000000075), BigDecimal.valueOf(1892), BigDecimal.valueOf(1929) });
TestUtils.assertTrue("Expected Solution Not Valid", tmpModel.validate(tmpExpSol));
// tmpModel.options.debug(GenericSolver.class);
// tmpModel.options.problem = NumberContext.getGeneral(12);
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 IntegerProblems method testP20130409b.
/**
* 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);
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(IntegerSolver.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 QRTest method testDiagonalCase.
@Test
public void testDiagonalCase() {
final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0, 3.0, 2.0, 1.0 }, { 0.0, 3.0, 2.0, 1.0 }, { 0.0, 0.0, 2.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 } });
final QR<Double> tmpDecomp = QR.PRIMITIVE.make();
tmpDecomp.decompose(tmpOriginalMatrix);
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Should be I", tmpDecomp.getQ());
BasicLogger.debug("Should be A", tmpDecomp.getR());
}
TestUtils.assertEquals(tmpOriginalMatrix, tmpDecomp, new NumberContext(7, 6));
// TODO See if possible to fix so that Q == I when the original A is already triangular
// TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.makeEye(4, 4), tmpDecomp.getQ(), new NumberContext(7, 6));
// TestUtils.assertEquals(tmpOriginalMatrix, tmpDecomp.getR(), new NumberContext(7, 6));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class QRTest method testHermitian.
@Test
public void testHermitian() {
final int tmpLim = DIMENSION - 1;
final MatrixStore<ComplexNumber> tmpOriginal = QRTest.makeHermitianMatrix();
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Original", tmpOriginal);
}
final QR<ComplexNumber> tmpDecomposition = QR.COMPLEX.make();
tmpDecomposition.decompose(tmpOriginal);
final MatrixStore<ComplexNumber> tmpDecompQ = tmpDecomposition.getQ();
final MatrixStore<ComplexNumber> tmpDecompR = tmpDecomposition.getR();
final DecompositionStore<ComplexNumber> tmpInPlace = ComplexDenseStore.FACTORY.copy(tmpOriginal);
final DecompositionStore<ComplexNumber> tmpNowQ = ComplexDenseStore.FACTORY.makeEye(DIMENSION, DIMENSION);
final DecompositionStore<ComplexNumber> tmpNowR = ComplexDenseStore.FACTORY.copy(tmpOriginal);
final DecompositionStore<ComplexNumber> tmpForwardQ = ComplexDenseStore.FACTORY.makeEye(DIMENSION, DIMENSION);
final DecompositionStore<ComplexNumber> tmpForwardR = ComplexDenseStore.FACTORY.copy(tmpOriginal);
final DecompositionStore<ComplexNumber> tmpReverseQ = ComplexDenseStore.FACTORY.makeEye(DIMENSION, DIMENSION);
final Householder.Complex[] tmpHouseholders = new Householder.Complex[tmpLim];
for (int ij = 0; ij < tmpLim; ij++) {
final Householder.Complex tmpVector = new Householder.Complex(DIMENSION);
if (tmpInPlace.generateApplyAndCopyHouseholderColumn(ij, ij, tmpVector)) {
tmpInPlace.transformLeft(tmpVector, ij + 1);
tmpNowQ.transformRight(tmpVector, 0);
tmpNowR.transformLeft(tmpVector, ij);
}
tmpHouseholders[ij] = tmpVector;
}
for (int h = 0; h < tmpHouseholders.length; h++) {
final Householder.Complex tmpVector = tmpHouseholders[h];
tmpForwardQ.transformRight(tmpVector, 0);
tmpForwardR.transformLeft(tmpVector, h);
}
for (int h = tmpHouseholders.length - 1; h >= 0; h--) {
final Householder.Complex tmpVector = tmpHouseholders[h];
tmpReverseQ.transformLeft(tmpVector, 0);
}
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug();
BasicLogger.debug("Decomp Q", tmpDecompQ);
BasicLogger.debug("Now Q", tmpNowQ);
BasicLogger.debug("Forward Q", tmpForwardQ);
BasicLogger.debug("Reverse Q", tmpReverseQ);
BasicLogger.debug();
BasicLogger.debug("Decomp R", tmpDecompR);
BasicLogger.debug("Now R", tmpNowR);
BasicLogger.debug("Forward R", tmpForwardR);
}
TestUtils.assertEquals(tmpOriginal, tmpDecomposition, new NumberContext(7, 6));
TestUtils.assertEquals(tmpDecompQ, tmpNowQ, new NumberContext(7, 6));
TestUtils.assertEquals(tmpDecompQ, tmpForwardQ, new NumberContext(7, 6));
TestUtils.assertEquals(tmpDecompQ, tmpReverseQ, new NumberContext(7, 6));
TestUtils.assertEquals(tmpDecompR, tmpNowR, new NumberContext(7, 6));
TestUtils.assertEquals(tmpDecompR, tmpForwardR, new NumberContext(7, 6));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class SchurTest method testP20061119Case.
@Test
public void testP20061119Case() {
final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.copy(P20061119Case.getProblematic());
final ComplexNumber tmp00 = ComplexNumber.valueOf(26.14421883828456);
final ComplexNumber tmp11 = ComplexNumber.of(2.727890580857718, 3.6223578444417908);
final ComplexNumber tmp22 = tmp11.conjugate();
final ComplexNumber tmp33 = ComplexNumber.ZERO;
final ComplexNumber tmp44 = tmp33;
final Array1D<ComplexNumber> tmpExpectedDiagonal = Array1D.COMPLEX.copy(new ComplexNumber[] { tmp00, tmp11, tmp22, tmp33, tmp44 });
SchurTest.doTest(tmpOriginalMatrix, tmpExpectedDiagonal, new NumberContext(7, 6));
}
Aggregations