示例#1
0
 private void visualize(RNode n, java.io.PrintWriter pw, int x0, int y0, int w, int h) {
   pw.printf(
       "<div style=\"position:absolute; left: %d; top: %d; width: %d; height: %d; border: 1px dashed\">\n",
       x0, y0, w, h);
   pw.println("<pre>");
   pw.println("Node: " + n.toString() + " \n(root==" + (n == root) + ") \n");
   pw.println("Coords start: " + Arrays.toString(n.getMbr().getP_start()) + "\n");
   pw.println("coords end: " + Arrays.toString(n.getMbr().getP_end()) + "\n");
   pw.println("# Children: " + ((n.children() == null) ? 0 : n.children().size()) + "\n");
   if (n instanceof REntry) {
     REntry n1 = (REntry) n;
     pw.println("Content: " + n1.getContent());
   }
   pw.println("isLeaf: " + n.isLeaf() + "\n");
   pw.println("</pre>");
   int numChildren = (n.children() == null) ? 0 : n.children().size();
   for (int i = 0; i < numChildren; i++) {
     visualize(
         n.children().get(i),
         pw,
         (int) (x0 + (i * w / (float) numChildren)),
         y0 + elemHeight,
         (int) (w / (float) numChildren),
         h - elemHeight);
   }
   pw.println("</div>");
 }
示例#2
0
 private double getDistance(RNode e1, RNode e2) {
   double[] a1 = e1.getMbr().getP_start();
   double[] a2 = e1.getMbr().getP_end();
   double[] b1 = e2.getMbr().getP_start();
   double[] b2 = e2.getMbr().getP_end();
   double dist = 0;
   for (int i = 0; i < dimension; i++) {
     /*suma los cuadrados de la resta de los puntos medios de los 2 mbr's para cada coordenada*/
     dist += Math.pow(Math.abs(a1[i] - a2[i]) / 2.0 - Math.abs(b1[i] - b2[i]) / 2.0, 2);
   }
   dist = Math.sqrt(dist);
   return dist;
 }
示例#3
0
 private double getEnlargement(RNode host, RNode guest) throws DimensionalException {
   double[] p1Host = host.getMbr().getP_start();
   double[] p2Host = host.getMbr().getP_end();
   double[] p1Guest = guest.getMbr().getP_start();
   double[] p2Guest = guest.getMbr().getP_end();
   double[] minRes = new double[dimension];
   double[] maxRes = new double[dimension];
   for (int i = 0; i < dimension; i++) {
     double minH = Math.min(p1Host[i], p2Host[i]);
     double maxH = Math.max(p1Host[i], p2Host[i]);
     double minG = Math.min(p1Guest[i], p2Guest[i]);
     double maxG = Math.max(p1Guest[i], p2Guest[i]);
     if (minG < minH) minRes[i] = minG;
     else minRes[i] = minH;
     if (maxG > maxH) maxRes[i] = maxG;
     else maxRes[i] = maxH;
   }
   return new MBR(minRes, maxRes, dimension).getArea() - host.getMbr().getArea();
 }
示例#4
0
 /**
  * shrinks the mbr area to the just necessary
  *
  * @param n
  */
 private void update(RNode n) throws DimensionalException {
   double[] minCoords = new double[dimension];
   double[] maxCoords = new double[dimension];
   for (int i = 0; i < dimension; i++) {
     minCoords[i] = Double.MAX_VALUE;
     maxCoords[i] = -Double.MAX_VALUE;
     for (RNode c : n.children()) {
       c.setParent(n);
       double minp = Math.min(c.getMbr().getP_start()[i], c.getMbr().getP_end()[i]);
       double maxp = Math.max(c.getMbr().getP_end()[i], c.getMbr().getP_start()[i]);
       if (minp < minCoords[i]) {
         minCoords[i] = minp;
       }
       if (maxp > maxCoords[i]) {
         maxCoords[i] = maxp;
       }
     }
   }
   n.setMbr(new MBR(minCoords, maxCoords, dimension));
 }
示例#5
0
 private RNode[] quadSeeds(List<RNode> cc) throws DimensionalException {
   RNode e1;
   RNode e2;
   RNode s1 = null;
   RNode s2 = null;
   double maxDeadSpace = -Double.MAX_VALUE;
   for (int i = 0; i < dimension; i++) {
     for (int k = i + 1; k < dimension; k++) {
       e1 = cc.get(i);
       e2 = cc.get(k);
       double areae1 = e1.getMbr().getArea();
       double areae2 = e2.getMbr().getArea();
       double[] p1Host = e1.getMbr().getP_start();
       double[] p2Host = e1.getMbr().getP_end();
       double[] p1Guest = e2.getMbr().getP_start();
       double[] p2Guest = e2.getMbr().getP_end();
       double[] minRes = new double[dimension];
       double[] maxRes = new double[dimension];
       for (int j = 0; j < dimension; j++) {
         double minH = Math.min(p1Host[j], p2Host[j]);
         double maxH = Math.max(p1Host[j], p2Host[j]);
         double minG = Math.min(p1Guest[j], p2Guest[j]);
         double maxG = Math.max(p1Guest[j], p2Guest[j]);
         if (minG < minH) minRes[j] = minG;
         else minRes[j] = minH;
         if (maxG > maxH) maxRes[j] = maxG;
         else maxRes[j] = maxH;
       }
       MBR ambr = new MBR(minRes, maxRes, dimension);
       double totarea = ambr.getArea();
       if (maxDeadSpace < totarea - areae1 - areae2) {
         maxDeadSpace = totarea - areae1 - areae2;
         s1 = e1;
         s2 = e2;
       }
     }
   }
   RNode[] seeds = new RNode[] {s1, s2};
   cc.removeAll(Arrays.asList(seeds));
   return seeds;
 }
示例#6
0
 private RNode getMinimalAreaNode(List<RNode> nodes) {
   RNode minimal = null;
   double minArea = Double.MAX_VALUE;
   for (RNode e : nodes) {
     double eArea = e.getMbr().getArea();
     if (eArea < minArea) {
       minArea = eArea;
       minimal = e;
     }
   }
   return minimal;
 }
示例#7
0
 private RNode[] makePartition(RNode n) throws DimensionalException {
   numOfPartitions++;
   numOfNodes += 2;
   RNode[] parts = new RNode[] {n, new RNode(n.getMbr(), n.isLeaf(), M_order)};
   parts[1].setParent(n.getParent());
   if (parts[1].getParent() != null) {
     parts[1].getParent().children().add(parts[1]);
   }
   List<RNode> cpyc = new LinkedList<RNode>(n.children());
   n.children().clear();
   RNode[] seeds = getSeeds(cpyc);
   parts[0].children().add(seeds[0]);
   parts[1].children().add(seeds[1]);
   update(parts[0]);
   update(parts[1]);
   while (!cpyc.isEmpty()) {
     if (parts[0].missingEntries(m_order) == 0
         && parts[1].missingEntries(m_order) + cpyc.size() == m_order) {
       parts[1].children().addAll(cpyc);
       cpyc.clear();
       update(parts[0]);
       update(parts[1]);
       return parts;
     } else if (parts[1].missingEntries(m_order) == 0
         && parts[0].missingEntries(m_order) + cpyc.size() == m_order) {
       parts[0].children().addAll(cpyc);
       cpyc.clear();
       update(parts[0]);
       update(parts[1]);
       return parts;
     }
     RNode next = chooseNext(cpyc, seeds), chosen;
     double enl1 = getEnlargement(parts[0], next);
     double enl2 = getEnlargement(parts[1], next);
     if (enl1 < enl2) chosen = parts[0];
     else if (enl2 < enl1) chosen = parts[1];
     else {
       double ar1 = parts[0].getMbr().getArea();
       double ar2 = parts[1].getMbr().getArea();
       if (ar1 < ar2) chosen = parts[0];
       else if (ar2 < ar1) chosen = parts[1];
       else {
         if (parts[0].children().size() < parts[1].children().size()) chosen = parts[0];
         else if (parts[0].children().size() > parts[1].children().size()) chosen = parts[1];
         else chosen = parts[new Random().nextInt(2)];
       }
     }
     chosen.children().add(next);
     update(chosen);
   }
   return parts;
 }