本文整理汇总了Java中org.ojalgo.ProgrammingError类的典型用法代码示例。如果您正苦于以下问题:Java ProgrammingError类的具体用法?Java ProgrammingError怎么用?Java ProgrammingError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProgrammingError类属于org.ojalgo包,在下文中一共展示了ProgrammingError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public static CalendarDate from(final TemporalAccessor temporal) {
ProgrammingError.throwIfNull(temporal, "temporal");
if (temporal instanceof CalendarDate) {
return (CalendarDate) temporal;
} else if (temporal instanceof Instant) {
return new CalendarDate(((Instant) temporal).toEpochMilli());
} else {
try {
final long tmpSeconds = temporal.getLong(ChronoField.INSTANT_SECONDS);
final int tmpMillisOfSecond = temporal.get(ChronoField.MILLI_OF_SECOND);
return new CalendarDate((tmpSeconds * MILLIS_PER_SECOND) + tmpMillisOfSecond);
} catch (final DateTimeException ex) {
throw new DateTimeException("Unable to obtain CalendarDate from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName(),
ex);
}
}
}
示例2: countVariables
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
@Override
public int countVariables() {
int retVal = -1;
if (this.getAE() != null) {
retVal = (int) this.getAE().countColumns();
} else if (this.getAI() != null) {
retVal = (int) this.getAI().countColumns();
} else if (this.getQ() != null) {
retVal = (int) this.getQ().countRows();
} else if (this.getC() != null) {
retVal = (int) this.getC().countRows();
} else {
throw new ProgrammingError("Cannot deduce the number of variables!");
}
return retVal;
}
示例3: objective
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public Builder objective(final MatrixStore<Double> mtrxQ, final MatrixStore<Double> mtrxC) {
ProgrammingError.throwIfNull(mtrxQ);
if (mtrxQ == null) {
throw new IllegalArgumentException();
}
if (mtrxQ instanceof PhysicalStore) {
myQ = (PhysicalStore<Double>) mtrxQ;
} else {
myQ = mtrxQ.copy();
}
myC = mtrxC != null ? mtrxC : MatrixStore.PRIMITIVE.makeZero((int) mtrxQ.countRows(), 1).get();
return this;
}
示例4: addSpecialOrderedSet
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
/**
* Creates a special ordered set (SOS) presolver instance and links that to the supplied expression.
* When/if the presolver concludes that the SOS "constraints" are not possible the linked expression is
* marked as infeasible.
*/
public void addSpecialOrderedSet(final Collection<Variable> orderedSet, final int type, final Expression linkedTo) {
if (type <= 0) {
throw new ProgrammingError("Invalid SOS type!");
}
if (!linkedTo.isConstraint()) {
throw new ProgrammingError("The linked to expression needs to be a constraint!");
}
final IntIndex[] sequence = new IntIndex[orderedSet.size()];
int index = 0;
for (final Variable variable : orderedSet) {
if ((variable == null) || (variable.getIndex() == null)) {
throw new ProgrammingError("Variables must be already inserted in the model!");
} else {
sequence[index++] = variable.getIndex();
}
}
ExpressionsBasedModel.addPresolver(new SpecialOrderedSet(sequence, type, linkedTo));
}
示例5: getEigenvalues
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
/**
* @param realParts An array that will receive the real parts of the eigenvalues
* @param imaginaryParts An optional array that, if present, will receive the imaginary parts of the
* eigenvalues
*/
default void getEigenvalues(final double[] realParts, final Optional<double[]> imaginaryParts) {
ProgrammingError.throwIfNull(realParts, imaginaryParts);
final Array1D<ComplexNumber> values = this.getEigenvalues();
final int length = realParts.length;
if (imaginaryParts.isPresent()) {
final double[] imagParts = imaginaryParts.get();
for (int i = 0; i < length; i++) {
final ComplexNumber value = values.get(i);
realParts[i] = value.getReal();
imagParts[i] = value.getImaginary();
}
} else {
for (int i = 0; i < length; i++) {
realParts[i] = values.doubleValue(i);
}
}
}
示例6: divide
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
final void divide(final int first, final int limit, final int threshold, final int workers) {
final int count = limit - first;
if ((count > threshold) && (workers > 1)) {
final int split = first + (count / 2);
final int nextWorkers = workers / 2;
final Future<?> firstPart = DaemonPoolExecutor.INSTANCE.submit(() -> this.divide(first, split, threshold, nextWorkers));
final Future<?> secondPart = DaemonPoolExecutor.INSTANCE.submit(() -> this.divide(split, limit, threshold, nextWorkers));
try {
firstPart.get();
secondPart.get();
} catch (final InterruptedException | ExecutionException exception) {
exception.printStackTrace();
throw new ProgrammingError(exception);
}
} else {
this.conquer(first, limit);
}
}
示例7: compute
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
@Override
public Iterator<double[]> compute(final Partition partition, final TaskContext context) {
ProgrammingError.throwIfNull(partition, context);
if (partition instanceof Partition2D) {
return this.compute((Partition2D) partition, context);
} else {
throw new IllegalArgumentException();
}
}
示例8: compute
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
@Override
public Iterator<MatrixStore<N>> compute(final Partition partition, final TaskContext context) {
ProgrammingError.throwIfNull(partition, context);
if (partition instanceof Partition2D) {
return this.compute((Partition2D) partition, context);
} else {
throw new IllegalArgumentException();
}
}
示例9: mix
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public double mix(final long index, final BinaryFunction<N> mixer, final double addend) {
ProgrammingError.throwIfNull(mixer);
if (index >= myActualCount) {
throw new ArrayIndexOutOfBoundsException();
} else {
synchronized (myStorage) {
final double oldValue = myStorage.doubleValue(index);
final double newValue = mixer.invoke(oldValue, addend);
myStorage.set(index, newValue);
return newValue;
}
}
}
示例10: mix
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public double mix(final long[] reference, final BinaryFunction<N> mixer, final double addend) {
ProgrammingError.throwIfNull(mixer);
synchronized (myDelegate) {
final double oldValue = this.doubleValue(reference);
final double newValue = mixer.invoke(oldValue, addend);
this.set(reference, newValue);
return newValue;
}
}
示例11: mix
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public double mix(final long key, final BinaryFunction<N> mixer, final double addend) {
ProgrammingError.throwIfNull(mixer);
synchronized (myStorage) {
final int tmpIndex = myStorage.index(key);
final double oldValue = tmpIndex >= 0 ? myStorage.doubleValueInternally(tmpIndex) : PrimitiveMath.NaN;
final double newValue = tmpIndex >= 0 ? mixer.invoke(oldValue, addend) : addend;
myStorage.put(key, tmpIndex, newValue);
return newValue;
}
}
示例12: mix
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public double mix(final long index, final BinaryFunction<N> mixer, final double addend) {
ProgrammingError.throwIfNull(mixer);
synchronized (myDelegate) {
final double oldValue = this.doubleValue(index);
final double newValue = mixer.invoke(oldValue, addend);
this.set(index, newValue);
return newValue;
}
}
示例13: mix
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
public double mix(final long row, final long col, final BinaryFunction<N> mixer, final double addend) {
ProgrammingError.throwIfNull(mixer);
synchronized (myDelegate) {
final double oldValue = this.doubleValue(row, col);
final double newValue = mixer.invoke(oldValue, addend);
this.set(row, col, newValue);
return newValue;
}
}
示例14: andThen
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
default NullaryFunction<N> andThen(final UnaryFunction<N> after) {
ProgrammingError.throwIfNull(after);
return new NullaryFunction<N>() {
public double doubleValue() {
return after.invoke(NullaryFunction.this.doubleValue());
}
public N invoke() {
return after.invoke(NullaryFunction.this.invoke());
}
};
}
示例15: buildModel
import org.ojalgo.ProgrammingError; //导入依赖的package包/类
static ExpressionsBasedModel buildModel(final BasicMatrix covariances, final BasicMatrix returns, final BigDecimal riskAversion) {
ProgrammingError.throwIfNotSquare(covariances);
ProgrammingError.throwIfNotEqualRowDimensions(covariances, returns);
final int numberOfVariables = (int) returns.countRows();
final Variable[] tmpVariables = new Variable[numberOfVariables];
for (int i = 0; i < numberOfVariables; i++) {
tmpVariables[i] = Variable.make("Asset_" + Integer.toString(i)).lower(ZERO).upper(ONE).weight(-returns.doubleValue(i));
}
final ExpressionsBasedModel retVal = new ExpressionsBasedModel(tmpVariables);
final Expression tmp100P = retVal.addExpression("Balance");
for (int i = 0; i < numberOfVariables; i++) {
tmp100P.set(i, ONE);
}
tmp100P.level(ONE);
final Expression tmpVar = retVal.addExpression("Variance");
for (int i = 0; i < numberOfVariables; i++) {
for (int j = 0; j < numberOfVariables; j++) {
tmpVar.set(i, j, covariances.doubleValue(i, j));
}
}
tmpVar.weight(BigFunction.DIVIDE.invoke(riskAversion, TWO));
return retVal;
}