- int nc = numkids * 2 + cols * 3 + 1 + 2;
- if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
- LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex();
- LinearProgramming.Problem lpr_h = new LinearProgramming.Problem(nc, nc);
- LinearProgramming.Simplex lp_v = new LinearProgramming.Simplex();
- LinearProgramming.Problem lpr_v = new LinearProgramming.Problem(nc, nc);
-
- //#repeat col/row colspan/rowspan contentwidth/contentheight width/height colMaxWidth/rowMaxHeight colWidth/rowHeight \
- // HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight colWidth/rowHeight x_slack/y_slack lp_h/lp_v lpr_h/lpr_v
- do {
- // objective function
- coeff[cols*2+numkids] = coeff[cols*2+numkids+1] = (float)-10000.0; // attempt to make sum of columns equal to parent width
- for(int i=cols*2; i<cols*2+numkids; i++) coeff[i] = (float)100.0; // second priority: try to honor maxwidths
- for(int i=cols; i<cols*2; i++) coeff[i] = (float)(-1.0); // third priority: try to make all columns similar size
- lp_h.set_obj_fn(lpr_h, coeff);
- lp_h.set_maxim(lpr_h);
-
- // top priority: try to match the parent's width
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
- coeff[cols*2+numkids] = (float)-1.0;
- lp_h.add_constraint(lpr_h, coeff, LinearProgramming.LE, (float)width);
-
- for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
- coeff[cols*2+numkids+1] = (float)1.0;
- lp_h.add_constraint(lpr_h, coeff, LinearProgramming.GE, (float)width);
-
- // obey minwidth, second priority: try to obey maxwidth (if relevant)
+ //#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 \
+ // computeRegions/computeRegions_v
+ if (numkids > 0) do {
+ computeRegions();
+ int nc = numregions * 3 + numkids * 2 + 3;
+ if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
+ lp_h.init(nc);
+
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
+ if (!findMinimum) {
+ coeff[numregions*2+numkids] = (float)10000.0; // priority 1: sum of columns no greater than parent
+ for(int i=numregions*2; i<numregions*2+numkids; i++) coeff[i] = (float)100.0; // priority 2: honor maxwidths
+ for(int i=numregions; i<numregions*2; i++) coeff[i] = (float)(0.1); // priority 3: equalize columns
+ } else {
+ coeff[numregions*2+numkids] = (float)1.0;
+ }
+ lp_h.setObjective(coeff, false);
+
+ // priority 1: sum of columns as close to parent's width as possible
+ for(int i=0; i<coeff.length; i++) coeff[i] = (i<numregions) ? (float)(regions[i+1] - regions[i]) : (float)0.0;
+ coeff[numregions*2+numkids] = (float)-1.0;
+ if (!findMinimum) lp_h.add_constraint(coeff, Simplex.EQ, (float)width);
+ else lp_h.add_constraint(coeff, Simplex.LE, (float)0);
+