本文整理汇总了Java中org.ojalgo.TestUtils类的典型用法代码示例。如果您正苦于以下问题:Java TestUtils类的具体用法?Java TestUtils怎么用?Java TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestUtils类属于org.ojalgo包,在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStratCombPortfolioMixer
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void testStratCombPortfolioMixer() {
final FinancePortfolio tmpTarget = new SimplePortfolio(THIRD, THIRD, THIRD).normalise();
final FinancePortfolio tmpStrat1 = new SimplePortfolio(HALF, HALF, ZERO);
final FinancePortfolio tmpStrat2 = new SimplePortfolio(HALF, ZERO, HALF);
final FinancePortfolio tmpStrat3 = new SimplePortfolio(ZERO, HALF, HALF);
final PortfolioMixer tmpMixer = new PortfolioMixer(tmpTarget, tmpStrat1, tmpStrat2, tmpStrat3);
final int tmpExpectedNumberOfStrategies = 2;
final List<BigDecimal> tmpStrategyWeights = tmpMixer.mix(tmpExpectedNumberOfStrategies);
int tmpUseCount = 0;
double tmpTotalWeight = 0D;
for (final BigDecimal tmpWeight : tmpStrategyWeights) {
if (tmpWeight.signum() != 0) {
tmpUseCount++;
tmpTotalWeight += tmpWeight.doubleValue();
}
}
TestUtils.assertEquals(tmpExpectedNumberOfStrategies, tmpUseCount);
TestUtils.assertEquals(PrimitiveMath.ONE, tmpTotalWeight, 1E-14 / PrimitiveMath.THREE);
}
示例2: testDoubleKeys
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void testDoubleKeys() {
final int dim = 1000;
final Uniform tmpUniform = new Uniform(0, Double.MAX_VALUE);
final double[] keys = new double[dim];
final long[] indices = new long[dim];
for (int i = 0; i < dim; i++) {
keys[i] = tmpUniform.doubleValue();
indices[i] = Double.doubleToLongBits(keys[i]);
}
Arrays.sort(keys);
Arrays.sort(indices);
for (int i = 0; i < dim; i++) {
TestUtils.assertEquals(keys[i], Double.longBitsToDouble(indices[i]));
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: doSortTest
import org.ojalgo.TestUtils; //导入依赖的package包/类
private void doSortTest(final double[][] rows) {
final Array1D<Double> tmpExpexted = Array1D.PRIMITIVE64.copy(rows[0]);
final boolean tmpAscending = tmpExpexted.doubleValue(tmpExpexted.count() - 1L) > tmpExpexted.doubleValue(0L);
final Array2D<Double> tmpAll = Array2D.PRIMITIVE64.rows(rows);
for (int i = 0; i < tmpAll.countRows(); i++) {
final Array1D<Double> tmpSlice = tmpAll.sliceRow(i, 0);
final Array1D<Double> tmpCopy = tmpSlice.copy(); // Will result in a different (Java's built-in) sorting algorthm
if (tmpAscending) {
tmpSlice.sortAscending();
tmpCopy.sortAscending();
} else {
tmpSlice.sortDescending();
tmpCopy.sortDescending();
}
TestUtils.assertEquals(tmpExpexted, tmpSlice);
TestUtils.assertEquals(tmpExpexted, tmpCopy);
}
}
示例6: compare
import org.ojalgo.TestUtils; //导入依赖的package包/类
static void compare(final String id, final double arg0, final double arg1) {
if (arg0 == arg1) {
if (NumberContext.compare(arg0, arg1) == 0) {
;
} else {
TestUtils.fail();
}
} else {
if (NumberContext.compare(arg0, arg1) == 0) {
TestUtils.fail();
} else {
TestUtils.fail();
}
}
}
示例7: _testCosAndBackAgain
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void _testCosAndBackAgain() {
final double[] tmpArguments = new double[] { PrimitiveMath.NEG, PrimitiveMath.ZERO, PrimitiveMath.ONE };
for (int s = 0; s < tmpArguments.length; s++) {
for (int i = 0; i < tmpArguments.length; i++) {
for (int j = 0; j < tmpArguments.length; j++) {
for (int k = 0; k < tmpArguments.length; k++) {
final Quaternion tmpOriginal = Quaternion.of(tmpArguments[s], tmpArguments[i], tmpArguments[j], tmpArguments[k]);
final Quaternion tmpOp = QuaternionFunction.COS.invoke(tmpOriginal);
final Quaternion tmpInv = QuaternionFunction.ACOS.invoke(tmpOriginal);
final Quaternion tmpInvOp = QuaternionFunction.ACOS.invoke(tmpOp);
final Quaternion tmpOpInv = QuaternionFunction.COS.invoke(tmpInv);
TestUtils.assertEquals(tmpOriginal, tmpInvOp);
TestUtils.assertEquals(tmpOriginal, tmpOpInv);
}
}
}
}
}
示例8: _testGetEigenvalues
import org.ojalgo.TestUtils; //导入依赖的package包/类
/**
* @see org.ojalgo.matrix.BasicMatrix#getEigenvalues()
*/
public void _testGetEigenvalues() {
if (myBigAA.isSquare()) {
final List<ComplexNumber> tmpExpStore = myPrimitiveAA.getEigenvalues();
List<ComplexNumber> tmpActStore;
if (MatrixUtils.isHermitian(PrimitiveDenseStore.FACTORY.copy(myBigAA))) {
tmpActStore = myBigAA.getEigenvalues();
for (int i = 0; i < tmpExpStore.size(); i++) {
TestUtils.assertEquals("Scalar<?> != Scalar<?>", tmpExpStore.get(i), tmpActStore.get(i), EVALUATION);
}
tmpActStore = myComplexAA.getEigenvalues();
for (int i = 0; i < tmpExpStore.size(); i++) {
TestUtils.assertEquals("Scalar<?> != Scalar<?>", tmpExpStore.get(i), tmpActStore.get(i), EVALUATION);
}
}
}
}
示例9: testSolveIdentity
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void testSolveIdentity() {
final Access2D<?> tmpIdentity = MatrixStore.PRIMITIVE.makeIdentity(9).get();
final Access2D<?> tmpRandom = PrimitiveDenseStore.FACTORY.makeFilled(9, 1, new Uniform());
final List<MatrixDecomposition<Double>> tmpAllDecomps = MatrixDecompositionTests.getAllPrimitive();
for (final MatrixDecomposition<Double> tmpDecomp : tmpAllDecomps) {
if (tmpDecomp instanceof SolverTask) {
final SolverTask<Double> tmpSolverTask = (SolverTask<Double>) tmpDecomp;
try {
TestUtils.assertEquals(tmpDecomp.getClass().toString(), tmpRandom, tmpSolverTask.solve(tmpIdentity, tmpRandom));
} catch (final RecoverableCondition xcptn) {
TestUtils.fail(tmpDecomp.getClass().toString() + " " + xcptn.getMessage());
}
}
}
}
示例10: testRandomSymmetricValuesOnly
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void testRandomSymmetricValuesOnly() {
final NumberContext evaluationContext = NumberContext.getGeneral(MathContext.DECIMAL32);
for (int dim = 1; dim < 10; dim++) {
final PrimitiveDenseStore matrix = MatrixUtils.makeSPD(dim);
for (final Eigenvalue<Double> decomp : MatrixDecompositionTests.getEigenvaluePrimitiveSymmetric()) {
decomp.decompose(matrix);
TestUtils.assertEquals(matrix, decomp, evaluationContext);
final Array1D<ComplexNumber> expected = decomp.getEigenvalues();
decomp.computeValuesOnly(matrix);
final Array1D<ComplexNumber> actual = decomp.getEigenvalues();
TestUtils.assertEquals(expected, actual, evaluationContext);
}
}
}
示例11: _testTanhAndBackAgain
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void _testTanhAndBackAgain() {
final double[] tmpArguments = new double[] { PrimitiveMath.NEG, PrimitiveMath.ZERO, PrimitiveMath.ONE };
for (int s = 0; s < tmpArguments.length; s++) {
for (int i = 0; i < tmpArguments.length; i++) {
for (int j = 0; j < tmpArguments.length; j++) {
for (int k = 0; k < tmpArguments.length; k++) {
final Quaternion tmpOriginal = Quaternion.of(tmpArguments[s], tmpArguments[i], tmpArguments[j], tmpArguments[k]);
final Quaternion tmpOp = QuaternionFunction.TANH.invoke(tmpOriginal);
final Quaternion tmpInv = QuaternionFunction.ATANH.invoke(tmpOriginal);
final Quaternion tmpInvOp = QuaternionFunction.ATANH.invoke(tmpOp);
final Quaternion tmpOpInv = QuaternionFunction.TANH.invoke(tmpInv);
TestUtils.assertEquals(tmpOriginal, tmpInvOp);
TestUtils.assertEquals(tmpOriginal, tmpOpInv);
}
}
}
}
}
示例12: testRelaxedNodeP11
import org.ojalgo.TestUtils; //导入依赖的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);
}
示例13: _testFullMIP
import org.ojalgo.TestUtils; //导入依赖的package包/类
public void _testFullMIP() {
final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
// tmpModel.options.debug_stream = BasicLogger.DEBUG;
// tmpModel.options.debug_solver = IntegerSolver.class;
// tmpModel.options.validate = true;
final Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
for (final Variable tmpVariable : tmpModel.getVariables()) {
TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(),
1E-14 / PrimitiveMath.THREE);
}
}
示例14: testDensePrimitive
import org.ojalgo.TestUtils; //导入依赖的package包/类
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);
}
示例15: testP20091102b
import org.ojalgo.TestUtils; //导入依赖的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);
}