本文整理汇总了Java中org.ojalgo.TestUtils.assertTrue方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.assertTrue方法的具体用法?Java TestUtils.assertTrue怎么用?Java TestUtils.assertTrue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ojalgo.TestUtils
的用法示例。
在下文中一共展示了TestUtils.assertTrue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMPSadlittle
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
* Defines a problem of 57 rows and 97 columns. Seems to be the same model as adlittle at netlib. Netlib
* also provides the solution.
* <a href="http://www-new.mcs.anl.gov/otc/Guide/TestProblems/LPtest/netlib/adlittle.html" >
* [email protected]</a> Found this info somewhere on the net: "With 56 constraints and 97 variables
* adlittle is one of its smaller members. While being in fact feasible, adlittle suffers from
* ill--posedness. Perturbing the right hand side of the equality constraints by subtracting a tiny
* multiple of the 96th column of the equation matrix renders the linear program infeasible. Running this
* problem through CPLEX and lp_solve does again return a solution without any warnings." FAIL: Hittar
* bara en lösning 0.0, oavsett om jag minimerrar eller maximerar. 2010-04-19 lp_solve => 225494.96316238
*/
public void testMPSadlittle() {
final File tmpFile = new File(PATH + "adlittle.mps");
final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
//tmpModel.options.debug(LinearSolver.class);
TestUtils.assertTrue(tmpModel.validate());
final BigDecimal tmpExpVal = new BigDecimal("225494.96316238446"); // Stated to be .22549496316e+6
final double tmpActVal = tmpModel.minimise().getValue();
TestUtils.assertEquals(tmpExpVal.doubleValue(), tmpActVal, PRECISION);
if (!tmpModel.validate(PRECISION)) {
TestUtils.fail(SOLUTION_NOT_VALID);
}
}
示例2: testMPSafiro
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
* Defines a problem of 28 rows and 32 columns. Seems to be the same model as afiro at netlib. Netlib also
* provides the solution.
* <a href="http://www-new.mcs.anl.gov/otc/Guide/TestProblems/LPtest/netlib/afiro.html">[email protected]</a>
* OK! 2010-04-19 lp_solve => -464.75314286
*/
public void testMPSafiro() {
final File tmpFile = new File(PATH + "afiro.mps");
final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
TestUtils.assertTrue(tmpModel.validate());
final BigDecimal tmpExpVal = new BigDecimal("-.46475314286e+3");
final double tmpActVal = tmpModel.minimise().getValue();
TestUtils.assertEquals(tmpExpVal.doubleValue(), tmpActVal, PRECISION);
if (!tmpModel.validate(PRECISION)) {
TestUtils.fail(SOLUTION_NOT_VALID);
}
}
示例3: testP20160608
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
* <a href="https://github.com/optimatika/ojAlgo/issues/23">GitHub Issue 23</a> The problem was that since
* the model allows shorting the pure profit maximisation is unbounded (initial LP). The algorithm did not
* handle the case where "target" could be >= the max possible when shorting not allowed (bounded LP).
*/
public void testP20160608() {
final BasicMatrix.Factory<PrimitiveMatrix> matrixFactory = PrimitiveMatrix.FACTORY;
final PrimitiveMatrix cov = matrixFactory.rows(new double[][] { { 0.01, 0.0018, 0.0011 }, { 0.0018, 0.0109, 0.0026 }, { 0.0011, 0.0026, 0.0199 } });
final PrimitiveMatrix ret = matrixFactory.columns(new double[] { 0.0427, 0.0015, 0.0285 });
final MarketEquilibrium marketEquilibrium = new MarketEquilibrium(cov);
final MarkowitzModel markowitz = new MarkowitzModel(marketEquilibrium, ret);
markowitz.setShortingAllowed(true);
markowitz.setTargetReturn(BigDecimal.valueOf(0.0427));
List<BigDecimal> tmpWeights = markowitz.getWeights();
TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
final NumberContext tmpTestPrecision = StandardType.PERCENT.newPrecision(4);
// Solution reachable without shorting, but since it is allowed the optimal solution is different
TestUtils.assertEquals(0.82745, tmpWeights.get(0).doubleValue(), tmpTestPrecision); // 0.82745
TestUtils.assertEquals(-0.09075, tmpWeights.get(1).doubleValue(), tmpTestPrecision); // -0.09075
TestUtils.assertEquals(0.26329, tmpWeights.get(2).doubleValue(), tmpTestPrecision); // 0.26329
TestUtils.assertEquals(0.0427, markowitz.getMeanReturn(), tmpTestPrecision);
TestUtils.assertEquals(0.0084, markowitz.getReturnVariance(), tmpTestPrecision);
// Also verify that it's posible to reach 10% return by shorting
markowitz.setTargetReturn(BigDecimal.valueOf(0.1));
TestUtils.assertEquals(0.1, markowitz.getMeanReturn(), tmpTestPrecision);
TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
// Min risk portfolio, very high risk aversion means minimum risk.
markowitz.setTargetReturn(null);
markowitz.setRiskAversion(new BigDecimal(1000000));
tmpWeights = markowitz.getWeights();
TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
TestUtils.assertEquals(0.4411, tmpWeights.get(0).doubleValue(), tmpTestPrecision); // 0.4411
TestUtils.assertEquals(0.3656, tmpWeights.get(1).doubleValue(), tmpTestPrecision); // 0.3656
TestUtils.assertEquals(0.1933, tmpWeights.get(2).doubleValue(), tmpTestPrecision); // 0.1933
}
示例4: testP20170508
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testP20170508() {
Builder<PrimitiveMatrix> tmpBuilder = PrimitiveMatrix.FACTORY.getBuilder(2, 2);
tmpBuilder.add(0, 0, 0.040000);
tmpBuilder.add(0, 1, 0.1000);
tmpBuilder.add(1, 0, 0.1000);
tmpBuilder.add(1, 1, 0.250000);
final BasicMatrix covariances = tmpBuilder.build();
tmpBuilder = PrimitiveMatrix.FACTORY.getBuilder(2);
tmpBuilder.add(0, 0.20000);
tmpBuilder.add(1, 0.40000);
final BasicMatrix returns = tmpBuilder.build();
final MarketEquilibrium marketEq = new MarketEquilibrium(covariances);
final MarkowitzModel markowitzModel = new MarkowitzModel(marketEq, returns);
for (int r = 0; r <= 10; r++) {
final BigDecimal targetReturn = StandardType.PERCENT.enforce(new BigDecimal(0.2 + (0.02 * r)));
markowitzModel.setTargetReturn(targetReturn);
markowitzModel.optimiser().validate(false);
markowitzModel.optimiser().debug(false);
final List<BigDecimal> tmpWeights = markowitzModel.getWeights();
if (DEBUG) {
BasicLogger.debug("{} => {} {}", targetReturn, markowitzModel.optimiser().getState(), markowitzModel.toSimplePortfolio());
}
TestUtils.assertTrue("Optimiser completed normally", markowitzModel.optimiser().getState().isOptimal());
TestUtils.assertTrue("Weights sum to 100%",
tmpWeights.get(0).add(tmpWeights.get(1)).setScale(2, RoundingMode.HALF_EVEN).compareTo(BigMath.ONE) == 0);
TestUtils.assertEquals("Return is close to target", targetReturn, markowitzModel.getMeanReturn(), StandardType.PERCENT.newPrecision(2).newScale(2));
}
}
示例5: _testHanging
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void _testHanging() throws Exception {
final MarkowitzModel markowitzModel = GitHubIssue24.buildMarkowitzModel(2.5E-5, false, false, false);
final double tmpMeanReturn = markowitzModel.getMeanReturn();
if (DEBUG) {
BasicLogger.debug(tmpMeanReturn);
}
TestUtils.assertTrue(markowitzModel.optimiser().getState().isOptimal()); // Won't reach here...
}
示例6: testOriginallyHangingButNowCleaned
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testOriginallyHangingButNowCleaned() throws Exception {
final MarkowitzModel markowitzModel = GitHubIssue24.buildMarkowitzModel(2.5E-5, true, false, false);
final double tmpMeanReturn = markowitzModel.getMeanReturn();
if (DEBUG) {
BasicLogger.debug(tmpMeanReturn);
}
TestUtils.assertTrue(markowitzModel.optimiser().getState().isOptimal()); // Won't reach here...
}
示例7: testSuccess
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testSuccess() throws Exception {
final MarkowitzModel markowitzModel = GitHubIssue24.buildMarkowitzModel(0.015, false, false, false);
final double tmpMeanReturn = markowitzModel.getMeanReturn();
if (DEBUG) {
BasicLogger.debug(tmpMeanReturn);
}
final State tmpOptimisationState = markowitzModel.optimiser().getState();
TestUtils.assertTrue(tmpOptimisationState.isOptimal());
}
示例8: doTestCleaning
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
private static void doTestCleaning(final double[][] original) {
final NumberContext tmpEvalCntx = NumberContext.getGeneral(6, 12);
final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(original);
final SingularValue<Double> tmpSVD = SingularValue.make(tmpOriginal);
tmpSVD.decompose(tmpOriginal);
final double tmpRefCond = tmpSVD.getCondition();
final int tmpRefRank = tmpSVD.getRank();
final double tmpRefNorm = tmpSVD.getFrobeniusNorm();
final PrimitiveMatrix tmpCorrelations = FinanceUtils.toCorrelations(tmpOriginal, true);
final PrimitiveMatrix tmpVolatilities = FinanceUtils.toVolatilities(tmpOriginal, true);
final PrimitiveMatrix tmpCovariances = FinanceUtils.toCovariances(tmpVolatilities, tmpCorrelations);
tmpSVD.decompose(PrimitiveDenseStore.FACTORY.copy(tmpCovariances));
final double tmpNewCond = tmpSVD.getCondition();
final int tmpNewRank = tmpSVD.getRank();
final double tmpNewNorm = tmpSVD.getFrobeniusNorm();
TestUtils.assertTrue("Improved the condition", tmpNewCond <= tmpRefCond);
TestUtils.assertTrue("Improved the rank", tmpNewRank >= tmpRefRank);
TestUtils.assertEquals("Full rank", original.length, tmpNewRank);
TestUtils.assertEquals("Roughly the same frob norm", tmpRefNorm, tmpNewNorm, tmpEvalCntx);
if (DEBUG) {
BasicLogger.debug("Original", tmpOriginal);
BasicLogger.debug("Cleaned", tmpCovariances);
BasicLogger.debug("Difference", tmpOriginal.subtract(PrimitiveDenseStore.FACTORY.copy(tmpCovariances)), tmpEvalCntx);
}
}
示例9: doTest
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
@Override
void doTest(final BasicArray<Double> array) {
for (int i = 0; i < INDICES.length; i++) {
array.set(INDICES[i], 1.0);
}
final AggregatorFunction<Double> tmpVisitor = Aggregator.SUM.getFunction(PrimitiveAggregator.getSet());
array.visitAll(tmpVisitor);
TestUtils.assertTrue(1 <= tmpVisitor.intValue());
TestUtils.assertTrue(INDICES.length >= tmpVisitor.intValue());
}
示例10: doTest
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
@Override
void doTest(final BasicArray<Double> array) {
for (int i = 0; i < INDICES.length; i++) {
array.set(INDICES[i], 1.0);
}
final AggregatorFunction<Double> tmpVisitor = Aggregator.CARDINALITY.getFunction(PrimitiveAggregator.getSet());
array.visitAll(tmpVisitor);
TestUtils.assertTrue(1 <= tmpVisitor.intValue());
TestUtils.assertTrue(INDICES.length >= tmpVisitor.intValue());
}
示例11: test2
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void test2() {
this.setupModel();
vars[0].lower(BigMath.ZERO).upper(BigMath.HUNDRED);
vars[1].level(new BigDecimal(5.0));
final MatrixStore<Double> solution = this.solveLinear();
TestUtils.assertTrue(solution != null);
}
示例12: testData
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
@Override
public void testData() {
// 3x5
final ComplexMatrix tmpProblematic = P20050827Case.getProblematic();
TestUtils.assertEquals(3, tmpProblematic.countRows());
TestUtils.assertEquals(5, tmpProblematic.countColumns());
// 5x5
final ComplexMatrix tmpBig = tmpProblematic.conjugate().multiply(tmpProblematic);
TestUtils.assertEquals(5, tmpBig.countRows());
TestUtils.assertEquals(5, tmpBig.countColumns());
// 3x3
final ComplexMatrix tmpSmall = tmpProblematic.multiply(tmpProblematic.conjugate());
TestUtils.assertEquals(3, tmpSmall.countRows());
TestUtils.assertEquals(3, tmpSmall.countColumns());
final Scalar<ComplexNumber> tmpBigTrace = tmpBig.getTrace();
final Scalar<ComplexNumber> tmpSmallTrace = tmpSmall.getTrace();
for (int ij = 0; ij < 3; ij++) {
TestUtils.assertTrue(tmpSmall.toScalar(ij, ij).toString(), tmpSmall.get(ij, ij).isReal());
}
for (int ij = 0; ij < 5; ij++) {
TestUtils.assertTrue(tmpBig.toScalar(ij, ij).toString(), tmpBig.get(ij, ij).isReal());
}
TestUtils.assertEquals("Scalar<?> != Scalar<?>", tmpBigTrace.get(), tmpSmallTrace.get(), EVALUATION);
}
示例13: testVpm2FirstBranch
import org.ojalgo.TestUtils; //导入方法依赖的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);
}
}
示例14: _testQR
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void _testQR() {
final MatrixStore<Double> tmpProblematic = ExtremeElementsCase.getVerySmall();
final QR<BigDecimal> tmpBig = QR.BIG.make();
final QR<ComplexNumber> tmpComplex = QR.COMPLEX.make();
final QR<Double> tmpPrimitive = QR.PRIMITIVE.make();
final QR<Double> tmpJama = new RawQR();
TestUtils.assertTrue("Big.compute()", tmpBig.decompose(MatrixStore.BIG.makeWrapper(tmpProblematic)));
TestUtils.assertTrue("Complex.compute()", tmpComplex.decompose(MatrixStore.COMPLEX.makeWrapper(tmpProblematic)));
TestUtils.assertTrue("Primitive.compute()", tmpPrimitive.decompose(tmpProblematic));
TestUtils.assertTrue("Jama.compute()", tmpJama.decompose(tmpProblematic));
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Big Q", tmpBig.getQ());
BasicLogger.debug("Complex Q", tmpComplex.getQ());
BasicLogger.debug("Primitive Q", tmpPrimitive.getQ());
BasicLogger.debug("Jama Q", tmpJama.getQ());
}
TestUtils.assertEquals("QR.reconstruct() Big", tmpProblematic, tmpBig.reconstruct(), PRECISION);
TestUtils.assertEquals("QR.reconstruct() Complex", tmpProblematic, tmpComplex.reconstruct(), PRECISION);
TestUtils.assertEquals("QR.reconstruct() Primitive", tmpProblematic, tmpPrimitive.reconstruct(), PRECISION);
TestUtils.assertEquals("QR.reconstruct() Jama", tmpProblematic, tmpJama.reconstruct(), PRECISION);
final SingularValue<Double> tmpSVD = new RawSingularValue();
tmpSVD.decompose(tmpProblematic);
TestUtils.assertEquals("rank() SVD vs Big", tmpSVD.getRank(), tmpBig.getRank());
TestUtils.assertEquals("rank() SVD vs Complex", tmpSVD.getRank(), tmpComplex.getRank());
TestUtils.assertEquals("rank() SVD vs Primitive", tmpSVD.getRank(), tmpPrimitive.getRank());
TestUtils.assertEquals("rank() SVD vs Jama", tmpSVD.getRank(), tmpJama.getRank());
}
示例15: testEmptySet
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testEmptySet() {
final Primitive64Array tmpSamples = Primitive64Array.wrap(new double[] { });
final SampleSet tmpSampleSet = SampleSet.wrap(tmpSamples);
try {
// The key thing is that all methods return something
// 0.0, NaN, Inf... doesn't really matter...
TestUtils.assertEquals(0.0, tmpSampleSet.getFirst());
TestUtils.assertEquals(0.0, tmpSampleSet.getInterquartileRange());
TestUtils.assertEquals(0.0, tmpSampleSet.getLargest());
TestUtils.assertEquals(0.0, tmpSampleSet.getLast());
TestUtils.assertEquals(0.0, tmpSampleSet.getMaximum());
TestUtils.assertEquals(Double.NaN, tmpSampleSet.getMean());
TestUtils.assertEquals(0.0, tmpSampleSet.getMedian());
TestUtils.assertEquals(0.0, tmpSampleSet.getMinimum());
TestUtils.assertEquals(0.0, tmpSampleSet.getQuartile1());
TestUtils.assertEquals(0.0, tmpSampleSet.getQuartile2());
TestUtils.assertEquals(0.0, tmpSampleSet.getQuartile3());
TestUtils.assertTrue(Double.isInfinite(tmpSampleSet.getSmallest()));
TestUtils.assertEquals(0.0, tmpSampleSet.getStandardDeviation());
TestUtils.assertEquals(0.0, tmpSampleSet.getSumOfSquares());
TestUtils.assertEquals(0.0, tmpSampleSet.getVariance());
} catch (final Exception exception) {
// Important NOT to throw an exception!
TestUtils.fail(exception.getMessage());
}
}