Esempio n. 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>");
 }
Esempio n. 2
0
 private int countLeafs(RNode n) {
   if (n.isLeaf()) return 1;
   int res = 0;
   for (RNode c : n.children) {
     res += countLeafs(c);
   }
   return res;
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 private RNode findFittingLeaf(RNode n, REntry e) throws DimensionalException {
   if (n.isLeaf()) return n;
   double min = Double.MAX_VALUE;
   List<RNode> minNodes = new ArrayList<RNode>();
   for (RNode nc : n.children()) {
     double d = getEnlargement(nc, e);
     if (d < min) {
       min = d;
       minNodes.clear();
       minNodes.add(nc);
     } else if (d == min) {
       minNodes.add(nc);
     }
   }
   RNode next;
   if (minNodes.size() > 1) next = getMinimalAreaNode(minNodes);
   else next = minNodes.get(0);
   return findFittingLeaf(next, e);
 }