use of org.ojalgo.access.Mutate1D in project ojAlgo by optimatika.
the class ColumnsSupplier method supplyTo.
public void supplyTo(final ElementsConsumer<N> receiver) {
receiver.reset();
final int limit = myColumns.size();
for (int j = 0; j < limit; j++) {
final long col = j;
myColumns.get(j).supplyNonZerosTo(new Mutate1D() {
public void add(final long index, final double addend) {
receiver.add(index, col, addend);
}
public void add(final long index, final Number addend) {
receiver.add(index, col, addend);
}
public long count() {
return receiver.countRows();
}
public void set(final long index, final double value) {
receiver.set(index, col, value);
}
public void set(final long index, final Number value) {
receiver.set(index, col, value);
}
});
}
final int tmpLimit = myColumns.size();
for (int j = 0; j < tmpLimit; j++) {
receiver.fillColumn(j, myColumns.get(j));
}
}
use of org.ojalgo.access.Mutate1D in project ojAlgo by optimatika.
the class SimplexSolver method build.
static SimplexTableau build(final ConvexSolver.Builder convex) {
final int numbVars = convex.countVariables();
final int numbEqus = convex.countEqualityConstraints();
final int numbInes = convex.countInequalityConstraints();
final SimplexTableau retVal = SimplexTableau.make(numbEqus + numbInes, numbVars + numbVars, numbInes);
final Mutate1D obj = retVal.objective();
final MatrixStore<Double> convexC = convex.getC();
for (int v = 0; v < numbVars; v++) {
final double val = convexC.doubleValue(v);
obj.set(v, -val);
obj.set(numbVars + v, val);
}
final Mutate2D constrBody = retVal.constraintsBody();
final Mutate1D constrRHS = retVal.constraintsRHS();
final MatrixStore<Double> convexAE = convex.getAE();
final MatrixStore<Double> convexBE = convex.getBE();
for (int i = 0; i < numbEqus; i++) {
final double rhs = convexBE.doubleValue(i);
final boolean neg = NumberContext.compare(rhs, ZERO) < 0;
for (int j = 0; j < numbVars; j++) {
final double val = convexAE.doubleValue(i, j);
constrBody.set(i, j, neg ? -val : val);
constrBody.set(i, numbVars + j, neg ? val : -val);
}
constrRHS.set(i, neg ? -rhs : rhs);
}
final RowsSupplier<Double> convexAI = convex.getAI();
final MatrixStore<Double> convexBI = convex.getBI();
for (int i = 0; i < numbInes; i++) {
final int r = i;
final SparseArray<Double> row = convexAI.getRow(r);
final double rhs = convexBI.doubleValue(r);
final boolean neg = NumberContext.compare(rhs, ZERO) < 0;
row.nonzeros().forEach(nz -> constrBody.set(numbEqus + r, nz.index(), neg ? -nz.doubleValue() : nz.doubleValue()));
row.nonzeros().forEach(nz -> constrBody.set(numbEqus + r, numbVars + nz.index(), neg ? nz.doubleValue() : -nz.doubleValue()));
constrBody.set(numbEqus + r, numbVars + numbVars + r, neg ? NEG : ONE);
constrRHS.set(numbEqus + i, neg ? -rhs : rhs);
}
return retVal;
}
use of org.ojalgo.access.Mutate1D in project ojAlgo by optimatika.
the class RowsSupplier method supplyTo.
public void supplyTo(final ElementsConsumer<N> receiver) {
receiver.reset();
final int limit = myRows.size();
for (int i = 0; i < limit; i++) {
final long row = i;
myRows.get(i).supplyNonZerosTo(new Mutate1D() {
public void add(final long index, final double addend) {
receiver.add(row, index, addend);
}
public void add(final long index, final Number addend) {
receiver.add(row, index, addend);
}
public long count() {
return receiver.countColumns();
}
public void set(final long index, final double value) {
receiver.set(row, index, value);
}
public void set(final long index, final Number value) {
receiver.set(row, index, value);
}
});
}
}
Aggregations