private BigRational multiplyBlockRow(BigRational[][] array, int index, int starting_col) throws UndefinedMultiplyException { BigRational result = BigRational.ZERO; int cols = array[0].length; for (int j = 0; j < cols; j++) { if (!array[index][j].isZero()) { if (basis.getNewValue(j + starting_col).isPositive()) { result = result.add((array[index][j].multiply(basis.getNewValue(j + starting_col)))); } else if (basis.getNewValue(j + starting_col).isUndefined()) { throw new UndefinedMultiplyException(); } } } return result; }
public void solve(BigRational[] rhs) throws BTFMatrixErrorException { if (cols + position.col > basis.getSize()) throw new BTFMatrixErrorException("Matrix exceeds end of vector when solving"); int block_starting_col = 0; int block_starting_row = 0; for (int i = 0; i < block_rows; i++) { block_starting_row = i * rows_in_blocks; for (int j = 0; j < block_cols; j++) { block_starting_col = j * cols_in_blocks; block_solve( matrix[i][j], rhs, position.row + block_starting_row, position.col + block_starting_col); } } }
private void block_multiply( BigRational[][] array, BigRational[] result, int starting_row, int starting_col) throws BTFMatrixErrorException { int rows = array.length; int cols = array[0].length; if (cols + position.col > basis.getSize()) throw new BTFMatrixErrorException("Matrix exceeds end of vector when multiplying"); for (int i = 0; i < rows; i++) { try { result[starting_row + i] = result[starting_row + i].add(multiplyBlockRow(array, i, starting_col)); } catch (UndefinedMultiplyException e) { result[starting_row + i] = new BigRational(-1); result[starting_row + i].makeUndefined(); } } }
private void block_solve( BigRational[][] array, BigRational[] rhs, int starting_row, int starting_col) throws BTFMatrixErrorException { int rows = array.length; int cols = array[0].length; if (starting_col + cols > basis.getSize()) throw new BTFMatrixErrorException( "Incompatible matrix and vector size when multiplying block"); for (int i = 0; i < rows; i++) { try { rhs[starting_row + i] = rhs[starting_row + i].add(multiplyBlockRow(array, i, starting_col).negate()); } catch (UndefinedMultiplyException e) { rhs[starting_row + i] = new BigRational(-1); rhs[starting_row + i].makeUndefined(); } } }