Example usage for org.apache.commons.math3.linear FieldMatrix getColumnVector

List of usage examples for org.apache.commons.math3.linear FieldMatrix getColumnVector

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear FieldMatrix getColumnVector.

Prototype

FieldVector<T> getColumnVector(int column) throws OutOfRangeException;

Source Link

Document

Returns the entries in column number column as a vector.

Usage

From source file:controller.VisLP.java

private static Point2D[] getFeasibleIntersections(FieldMatrix<BigFraction> cons) {
    FieldMatrix<BigFraction> N = cons.getSubMatrix(0, cons.getRowDimension() - 1, 0,
            cons.getColumnDimension() - 2);
    FieldVector<BigFraction> b = cons.getColumnVector(cons.getColumnDimension() - 1);

    HashSet<Point2D> points = new HashSet<Point2D>();
    unb = new ArrayList<Point2D>();

    /* Find all intersections */
    for (int i = 0; i < N.getRowDimension(); i++) {
        for (int j = 0; j < N.getRowDimension(); j++) {
            if (i == j)
                continue;

            FieldMatrix<BigFraction> line1 = N.getRowMatrix(i);
            FieldMatrix<BigFraction> line2 = N.getRowMatrix(j);

            BigFraction[] bval = new BigFraction[] { b.getEntry(i), b.getEntry(j) };
            FieldVector<BigFraction> bsys = new ArrayFieldVector<BigFraction>(bval);
            FieldMatrix<BigFraction> sys = LP.addBlock(line1, line2, LP.UNDER);

            try {
                FieldVector<BigFraction> point = new FieldLUDecomposition<BigFraction>(sys).getSolver()
                        .getInverse().operate(bsys);
                double x = point.getEntry(0).doubleValue();
                double y = point.getEntry(1).doubleValue();
                Point2D p2d = new Point2D.Double(x, y);

                /* Only add feasible points */
                if (feasible(p2d, N, b)) {
                    if (i >= N.getRowDimension() - 1)
                        unb.add(p2d);//from  ww  w.j  a v  a  2 s . co m
                    points.add(p2d);
                }
            } catch (IllegalArgumentException e) {
                /* 
                 * Two lines that don't intersect forms an invertible
                 * matrix. Skip these points.
                 */
            }
        }
    }
    return points.toArray(new Point2D[0]);
}