Search in sources :

Example 56 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestFixedGrid method runExperiment.

/**
 * Run this experiment
 * @param cellGrid
 */
protected void runExperiment(final CellGrid cellGrid) {
    final TupleFileReader tupleFile = new TupleFileReader(filename, format);
    final Map<BoundingBox, Integer> bboxes = new HashMap<>();
    final ExecutorService executor = ExecutorUtil.getBoundThreadPoolExecutor(10, 100);
    tupleFile.addTupleListener(t -> {
        executor.submit(() -> {
            final Set<BoundingBox> intersectedBoxes = cellGrid.getAllInersectedBoundingBoxes(t.getBoundingBox());
            synchronized (bboxes) {
                for (final BoundingBox box : intersectedBoxes) {
                    if (bboxes.containsKey(box)) {
                        final int oldValue = bboxes.get(box);
                        bboxes.put(box, oldValue + 1);
                    } else {
                        bboxes.put(box, 1);
                    }
                }
            }
        });
    });
    try {
        System.out.println("# Processing tuples");
        tupleFile.processFile();
        executor.shutdown();
    } catch (IOException e) {
        System.err.println("Got an IOException during experiment: " + e);
        System.exit(-1);
    }
    calculateResult(bboxes);
}
Also used : HashMap(java.util.HashMap) TupleFileReader(org.bboxdb.tools.TupleFileReader) BoundingBox(org.bboxdb.commons.math.BoundingBox) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException)

Example 57 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestKDTreeSplit method getSplitPosition.

/**
 * Calculate the split position
 * @param boundingBoxToSplit
 * @return
 */
protected double getSplitPosition(final BoundingBox boundingBoxToSplit, final int dimension) {
    final List<Double> pointSamples = new ArrayList<>();
    final Set<Integer> takenSamples = new HashSet<>();
    final List<BoundingBox> elementsToProcess = elements.get(boundingBoxToSplit);
    final int numberOfElements = elementsToProcess.size();
    final long numberOfSamples = (long) (numberOfElements / 100.0 * SAMPLING_SIZE);
    double sample = 0;
    // Try to find n samples (= 2n points)
    while (pointSamples.size() < (2 * numberOfSamples)) {
        sample++;
        final int sampleId = ThreadLocalRandom.current().nextInt(numberOfElements);
        if (takenSamples.contains(sampleId)) {
            continue;
        }
        takenSamples.add(sampleId);
        final BoundingBox bboxSample = elementsToProcess.get(sampleId);
        if (bboxSample.getCoordinateLow(dimension) > boundingBoxToSplit.getCoordinateLow(dimension)) {
            pointSamples.add(bboxSample.getCoordinateLow(dimension));
        }
        if (bboxSample.getCoordinateHigh(dimension) < boundingBoxToSplit.getCoordinateHigh(dimension)) {
            pointSamples.add(bboxSample.getCoordinateHigh(dimension));
        }
        // Unable to find enough samples
        if (sample > (50 * numberOfSamples)) {
            break;
        }
    }
    pointSamples.sort((b1, b2) -> Double.compare(b1, b2));
    return pointSamples.get(pointSamples.size() / 2);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 58 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestKDTreeSplit method splitRegion.

/**
 * Split the region
 * @param sampleSize
 * @param numberOfElements
 * @return
 */
protected void splitRegion(final BoundingBox boundingBoxToSplit) {
    final int parentBoxDimension = boxDimension.get(boundingBoxToSplit) % dataDimension;
    final double splitPosition = getSplitPosition(boundingBoxToSplit, parentBoxDimension);
    final BoundingBox leftBBox = boundingBoxToSplit.splitAndGetLeft(splitPosition, parentBoxDimension, true);
    final BoundingBox rightBBox = boundingBoxToSplit.splitAndGetRight(splitPosition, parentBoxDimension, false);
    // Data to redistribute
    final List<BoundingBox> dataToRedistribute = elements.get(boundingBoxToSplit);
    // Write the box dimension
    boxDimension.put(leftBBox, parentBoxDimension + 1);
    boxDimension.put(rightBBox, parentBoxDimension + 1);
    // Insert new boxes and remove old one
    elements.put(leftBBox, new ArrayList<>());
    elements.put(rightBBox, new ArrayList<>());
    elements.remove(boundingBoxToSplit);
    dataToRedistribute.forEach(b -> {
        if (leftBBox.overlaps(b)) {
            elements.get(leftBBox).add(b);
        }
        if (rightBBox.overlaps(b)) {
            elements.get(rightBBox).add(b);
        }
    });
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox)

Example 59 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestBoundingBox method testFromToString1.

/**
 * Test the from and to string method
 */
@Test(timeout = 60000)
public void testFromToString1() {
    final BoundingBox boundingBox1 = BoundingBox.FULL_SPACE;
    final BoundingBox boundingBox2 = new BoundingBox(0d, 1d);
    final BoundingBox boundingBox3 = new BoundingBox(-5d, 5d, -5d, 5d);
    final BoundingBox boundingBox4 = new BoundingBox(Arrays.asList(new DoubleInterval(1, 2, false, false)));
    final BoundingBox boundingBox5 = new BoundingBox(Arrays.asList(new DoubleInterval(1, 2, false, true)));
    final BoundingBox boundingBox6 = new BoundingBox(Arrays.asList(new DoubleInterval(1, 2, true, false)));
    final BoundingBox boundingBox7 = new BoundingBox(Arrays.asList(new DoubleInterval(1, 2, true, false), new DoubleInterval(1, 2, false, false)));
    final BoundingBox boundingBox8 = BoundingBox.createFullCoveringDimensionBoundingBox(3);
    Assert.assertEquals(boundingBox1, new BoundingBox(boundingBox1.toCompactString()));
    Assert.assertEquals(boundingBox2, new BoundingBox(boundingBox2.toCompactString()));
    Assert.assertEquals(boundingBox3, new BoundingBox(boundingBox3.toCompactString()));
    Assert.assertEquals(boundingBox4, new BoundingBox(boundingBox4.toCompactString()));
    Assert.assertEquals(boundingBox5, new BoundingBox(boundingBox5.toCompactString()));
    Assert.assertEquals(boundingBox6, new BoundingBox(boundingBox6.toCompactString()));
    Assert.assertEquals(boundingBox7, new BoundingBox(boundingBox7.toCompactString()));
    Assert.assertEquals(boundingBox8, new BoundingBox(boundingBox8.toCompactString()));
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) DoubleInterval(org.bboxdb.commons.math.DoubleInterval) Test(org.junit.Test)

Example 60 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestBoundingBox method mergeBoxesWithWrongDimension1.

/**
 * Merge two boxes with wrong dimension
 */
@Test(expected = IllegalArgumentException.class)
public void mergeBoxesWithWrongDimension1() {
    final BoundingBox boundingBox1 = new BoundingBox(1d, 3d, 1d, 3d);
    final BoundingBox boundingBox2 = new BoundingBox(1d, 4d, 1d, 4d, 1d, 4d);
    final BoundingBox boundingBoxResult3 = BoundingBox.getCoveringBox(boundingBox1, boundingBox2);
    Assert.assertTrue(boundingBoxResult3 == null);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) Test(org.junit.Test)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)194 Test (org.junit.Test)113 Tuple (org.bboxdb.storage.entity.Tuple)61 ArrayList (java.util.ArrayList)25 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)24 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)23 BBoxDBException (org.bboxdb.misc.BBoxDBException)22 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)20 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)16 List (java.util.List)15 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)13 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)13 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)13 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)11 IOException (java.io.IOException)10 Date (java.util.Date)10 DoubleInterval (org.bboxdb.commons.math.DoubleInterval)10 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)10