List of usage examples for org.apache.commons.math3.linear FieldMatrix getRowMatrix
FieldMatrix<T> getRowMatrix(int row) throws OutOfRangeException;
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);// w ww . ja va 2 s. c om 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]); }