From: adam Date: Wed, 7 Apr 2004 06:55:11 +0000 (+0000) Subject: simplex optimization: make place_children() run in O(numkids) rather than O(numcols^2) X-Git-Tag: RC4~37 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=5de59cbabd2184a23380fee1bdf32e52c5bb44d7 simplex optimization: make place_children() run in O(numkids) rather than O(numcols^2) darcs-hash:20040407065511-5007d-b5fa5c1fb1ec90357a2a191486f0c86836f4df19.gz --- diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 59d4ca7..f680f20 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -295,61 +295,104 @@ public final class Box extends JSScope implements Scheduler.Task { private static float[] coeff = null; private static LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex(100, 100, 300); - private static LinearProgramming.Simplex lp_v = new LinearProgramming.Simplex(100, 100, 300); + private static LinearProgramming.Simplex lp = new LinearProgramming.Simplex(100, 100, 300); + boolean[] breakpoints = new boolean[65535]; + int[] regions = new int[65535]; + int[] regions_v = new int[65535]; void place_children() { int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++; - //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK \ - // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp_v lp_h/lp_v - if (cols > 1) { - int nc = numkids * 2 + cols * 3 + 1 + 2; + int numregions = 0, numregions_v = 0; + //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \ + // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp lp_h/lp easy_width/easy_height regions/regions_v + if (cols > 1) do { + /* boolean easy_width = contentwidth >= width; */ + for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) { + breakpoints[c.col] = true; + breakpoints[min(cols, c.col+c.colspan)] = true; + } + numregions = 0; + // FIXME: depends on cols + for(int i=0; i i && c.maxwidth < Integer.MAX_VALUE) + good = false; + if (good) { easy_width = true; break; } + } + if (easy_width) break; + */ + int nc = numregions * 2 + numkids + 1; if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1]; lp_h.init(nc); - // objective function for(int i=0; i=child.col && i= child.col && regions[r+1] <= min(child.col+child.colspan,cols)) + coeff[r] = (float)(regions[r+1] - regions[r]); lp_h.add_constraint(coeff, LinearProgramming.GE, (float)child.contentwidth); + + // priority 2: honor maxwidths int child_maxwidth = child.test(HSHRINK) ? min(child.maxwidth, child.contentwidth) : child.maxwidth; if (child_maxwidth < Integer.MAX_VALUE) { - for(int i=0; i=child.col && i= child.col && regions[r+1] <= min(child.col+child.colspan,cols)) + coeff[r] = (float)(regions[r+1] - regions[r]); + coeff[numregions*2+childnum] = (float)-1.0; + lp_h.add_constraint(coeff, LinearProgramming.LE, (float)child_maxwidth); } - for(int j=0; j= child.col && regions[r+1] <= min(child.col+child.colspan,cols)) { + child_width += Math.round(lp_h.solution[lp_h.rows+r+1] * (regions[r+1] - regions[r])); + } else if (regions[r+1] <= child.col) { + child_x += Math.round(lp_h.solution[lp_h.rows+r+1] * (regions[r+1] - regions[r])); + } + } } diff = (child_width - min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth)); child_x += (child.test(ALIGN_RIGHT) ? diff : child.test(ALIGN_LEFT) ? 0 : diff / 2);