use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class ActiveSetSolver method shrink.
private final void shrink() {
final int[] incl = myActivator.getIncluded();
final PrimitiveDenseStore soluL = this.getSolutionL();
final int numbEqus = this.countEqualityConstraints();
int toExclude = incl[0];
double maxWeight = ZERO;
for (int i = 0; i < incl.length; i++) {
final double tmpValue = soluL.doubleValue(numbEqus + incl[i]);
final double tmpWeight = PrimitiveFunction.ABS.invoke(tmpValue) * PrimitiveFunction.MAX.invoke(-tmpValue, ONE);
if (tmpWeight > maxWeight) {
maxWeight = tmpWeight;
toExclude = incl[i];
}
}
this.exclude(toExclude);
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class IterativeASS method performIteration.
@Override
protected void performIteration() {
if (this.isDebug()) {
this.log("\nPerformIteration {}", 1 + this.countIterations());
this.log(this.toActivatorString());
}
final int toInclude = this.getConstraintToInclude();
this.setConstraintToInclude(-1);
final int[] incl = this.getIncluded();
final int[] excl = this.getExcluded();
boolean solved = false;
if (toInclude >= 0) {
final int constrIndex = this.countEqualityConstraints() + toInclude;
final SparseArray<Double> constrBody = this.getMatrixAI(toInclude);
final double constrRHS = this.getMatrixBI(toInclude);
this.addConstraint(constrIndex, constrBody, constrRHS);
}
final PrimitiveDenseStore iterX = this.getIterationX();
if ((this.countIterationConstraints() < this.countVariables()) && (solved = this.isSolvableQ())) {
if (this.countIterationConstraints() == 0L) {
// Unconstrained - can happen when there are no equality constraints and all inequalities are inactive
iterX.fillMatching(this.getInvQC());
} else {
// Actual/normal optimisation problem
final double tmpRelativeError = myS.resolve(this.getSolutionL());
if (this.isDebug()) {
this.log("Relative error {} in solution for L={}", tmpRelativeError, this.getIterationL(incl));
}
final ElementsSupplier<Double> tmpRHS = this.getIterationL(incl).premultiply(this.getIterationA().transpose()).operateOnMatching(this.getIterationC(), SUBTRACT);
this.getSolutionQ(tmpRHS, iterX);
}
}
if (!solved) {
// The above failed, try solving the full KKT system instaed
final PrimitiveDenseStore tmpXL = PrimitiveDenseStore.FACTORY.makeZero(this.countVariables() + this.countIterationConstraints(), 1L);
if (solved = this.solveFullKKT(tmpXL)) {
iterX.fillMatching(tmpXL.logical().limits(this.countVariables(), 1).get());
for (int i = 0; i < this.countEqualityConstraints(); i++) {
this.getSolutionL().set(i, tmpXL.doubleValue(this.countVariables() + i));
}
final int tmpLengthIncluded = incl.length;
for (int i = 0; i < tmpLengthIncluded; i++) {
this.getSolutionL().set(this.countEqualityConstraints() + incl[i], tmpXL.doubleValue(this.countVariables() + this.countEqualityConstraints() + i));
}
}
}
this.handleIterationResults(solved, iterX, incl, excl);
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class SimplexSolver method extractSolution.
/**
* Extract solution MatrixStore from the tableau
*/
@Override
protected PhysicalStore<Double> extractSolution() {
final int colRHS = myTableau.countConstraints() + myTableau.countVariables();
final PrimitiveDenseStore solution = PrimitiveDenseStore.FACTORY.makeZero(myTableau.countVariables(), 1);
final int numberOfConstraints = myTableau.countConstraints();
for (int row = 0; row < numberOfConstraints; row++) {
final int variableIndex = myTableau.getBasis(row);
if (variableIndex >= 0) {
solution.set(variableIndex, myTableau.doubleValue(row, colRHS));
}
}
return solution;
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class Quaternion method toMultiplicationVector.
public MatrixStore<Double> toMultiplicationVector() {
final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(4L, 1L);
retVal.set(0L, myScalar);
retVal.set(1L, i);
retVal.set(2L, j);
retVal.set(3L, k);
return retVal;
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class Quaternion method vector.
public PhysicalStore<Double> vector() {
final PrimitiveDenseStore retVal = PrimitiveDenseStore.FACTORY.makeZero(3L, 1L);
retVal.set(0L, i);
retVal.set(1L, j);
retVal.set(2L, k);
return retVal;
}
Aggregations