Package net.algart.math.patterns

Examples of net.algart.math.patterns.Pattern


        }
        if (p.isSurelyInteger()) {
            System.out.println("It is integer");
        }
        if (p.pointCount() < 1000) {
            Pattern samePoints = Patterns.newPattern(p.points());
            System.out.println("Pattern with same points: " + samePoints);
            if (samePoints instanceof UniformGridPattern && ((UniformGridPattern)samePoints).isActuallyRectangular()) {
                System.out.println("It is also rectangular");
            }
        }
View Full Code Here


            center[k] = Double.parseDouble(args[2 + k]);
        int minimalPointCountForDecomposition = Integer.parseInt(args[2 + center.length]);
        int numberOfIterations = args.length > 3 + center.length ? Integer.parseInt(args[3 + center.length]) : 1;
        System.out.println("Sphere with center " + Point.valueOf(center) + " and radius " + r);
        long t1 = System.nanoTime();
        Pattern p = Patterns.newSphereIntegerPattern(Point.valueOf(center), r);
        long t2 = System.nanoTime();
        System.out.printf(Locale.US, "Pattern created in %.3f ms: %s%n", (t2 - t1) * 1e-6, p);
        Set<Point> points = p.points();
        System.out.println(points.size() + " points");
        if (points.size() < 1000)
            System.out.println(new TreeSet<Point>(points));
        for (int iterationIndex = 1; iterationIndex <= numberOfIterations; iterationIndex++) {
            System.out.println();
            System.out.println("Iteration #" + iterationIndex);
            if (p instanceof UniformGridPattern && ((UniformGridPattern)p).isActuallyRectangular()) {
                System.out.println("It is rectangular");
            }
            if (p.isSurelySinglePoint()) {
                System.out.println("It is 1-point");
            }
            if (p.isSurelyOriginPoint()) {
                System.out.println("It is origin of coordinates");
            }
            if (p.isSurelyInteger()) {
                System.out.println("It is integer");
            }
            System.out.println("Minimal coordinates: " + p.coordMin());
            System.out.println("Maximal coordinates: " + p.coordMax());
            for (int k = 0; k < p.dimCount(); k++) {
                System.out.println("Range of coordinate #" + k + ": " + p.coordRange(k));
            }
            points = p.round().lowerSurface(iterationIndex % dimCount).points();
            System.out.println(points.size() + " left points along axis #" + iterationIndex % dimCount + ":");
            if (points.size() < 1000)
                System.out.println(new TreeSet<Point>(points));
            points = p.round().upperSurface(iterationIndex % dimCount).points();
            System.out.println(points.size() + " right points along axis #" + iterationIndex % dimCount + ":");
            if (points.size() < 1000)
                System.out.println(new TreeSet<Point>(points));
            points = p.round().surface().points();
            System.out.println(points.size() + " boundary:");
            if (points.size() < 1000)
                System.out.println(new TreeSet<Point>(points));
            t1 = System.nanoTime();
            List<Pattern> minkowskiDecomposition = p.minkowskiDecomposition(minimalPointCountForDecomposition);
            t2 = System.nanoTime();
            System.out.printf(Locale.US, "Minkowski decomposition to %d patterns (%.3f ms, %.3f ns / point):%n",
                minkowskiDecomposition.size(), (t2 - t1) * 1e-6, (t2 - t1) / (double)p.pointCount());
            for (Pattern q : minkowskiDecomposition) {
                System.out.println("    " + q);
            }
            System.out.println();

            t1 = System.nanoTime();
            List<List<Pattern>> allUnionDecompositions = p.allUnionDecompositions(minimalPointCountForDecomposition);
            t2 = System.nanoTime();
            for (int k = 0, n = allUnionDecompositions.size(); k < n; k++) {
                List<Pattern> unionDecomposition = allUnionDecompositions.get(k);
                System.out.printf(Locale.US, "Union decompositions #%d to %d patterns (%.3f ms, %.3f ns / point):%n",
                    k + 1, unionDecomposition.size(), (t2 - t1) * 1e-6, (t2 - t1) / (double) p.pointCount());
                for (Pattern q : unionDecomposition) {
                    System.out.println("    " + q
                        + (!q.hasMinkowskiDecomposition() ? " " + new TreeSet<IPoint>(q.roundedPoints()) : ""));
                }
                t1 = System.nanoTime();
                long totalPatternCount = 0, totalPointCount = 0;
                for (Pattern q : allUnionDecompositions.get(0)) {
                    List<Pattern> mink = q.minkowskiDecomposition(minimalPointCountForDecomposition);
                    totalPatternCount += mink.size();
                    for (Pattern s : mink)
                        totalPointCount += s.pointCount();
                }
                t2 = System.nanoTime();
                System.out.printf(Locale.US, "Minkowski decomposition of this union elements to %d patterns, "
                    + "%d total points (%.3f ms, %.3f ns / point)%n%n",
                    totalPatternCount, totalPointCount, (t2 - t1) * 1e-6, (t2 - t1) / (double)p.pointCount());
            }
        }
    }
View Full Code Here

* @version 1.2
* @since JDK 1.5
*/
public class LargePatternTest {
    public static void main(String[] args) {
        Pattern p1 = Patterns.newRectangularIntegerPattern(IPoint.valueOf(0, 0), IPoint.valueOf(20, 20));
        Set<IPoint> points = new HashSet<IPoint>();
        for (int k = 0; k < 1000; k++) {
            points.add(IPoint.valueOf(k, k));
            points.add(IPoint.valueOf(2000000000 + k, k));
            points.add(IPoint.valueOf(k, 2000000000 + k));
        }
        Pattern p2 = Patterns.newIntegerPattern(points);
        Pattern pSum = Patterns.newMinkowskiSum(p1, p2);
        System.out.println("Large sum: " + pSum + ", contains " + pSum.pointCount() + " points");
    }
View Full Code Here

            //     }
            // and if the checks "i < 0" lead to the same stable result (almost always true or, little better,
            // almost always false), then CPU can optimize this branching.
//            System.out.println("QUICK");
            final IPoint min = pattern.coordMin().toRoundedPoint();
            final Pattern shiftedPattern = pattern.shift(min.symmetric().toPoint()); // "normalized" coordinates >=0
            final Matrix<?> shiftedSrc = Matrices.asShifted(src, min.coordinates());
            Matrix<? extends UpdatablePArray> clone = Arrays.SMM.newMatrix(UpdatablePArray.class, src);
            Matrices.copy(arrayContext == null ? null : arrayContext.part(0.0, 0.05),
                clone, shiftedSrc);
            Matrix<? extends PArray> lazy = asProcessed(requiredType, clone, additionalMatrices, shiftedPattern);
            new Arrays.Copier(arrayContext == null ? null : arrayContext.part(0.05, 1.0),
                dest.array(), lazy.array(), 0, 1).process();
            // "1" allows to split into minimal number of ranges
            return;
        }
        boolean direct = sa instanceof DirectAccessible && ((DirectAccessible) sa).hasJavaArray();
        if (direct || !ENABLE_STREAMING) {
//            System.out.println("SIMPLE");
            Matrix<? extends PArray> lazy = asProcessed(requiredType, src, additionalMatrices, pattern);
            new Arrays.Copier(arrayContext, dest.array(), lazy.array(), 0, 1).process();
            // "1" allows to split into minimal number of ranges
            return;
        }
        assert bufSize < size;

        final IPoint min = pattern.coordMin().toRoundedPoint();
        final Pattern shiftedPattern = pattern.shift(min.symmetric().toPoint()); // "normalized" coordinates >=0
        final Matrix<? extends PArray> shiftedSrc = Matrices.asShifted(src, min.coordinates()).cast(PArray.class);

        final long[] dimensions = src.dimensions();
        final long lSize = Arrays.longMul(dimensions, 0, dimensions.length - 1);
        final long lastDim = dimensions[dimensions.length - 1];
View Full Code Here

TOP

Related Classes of net.algart.math.patterns.Pattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.