do {
int nc = numkids * 2 + cols * 3 + 1 + 2;
if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
- lp_h.init(nc, nc);
+ lp_h.init(nc);
// objective function
for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
- coeff[cols*2+numkids] = (float)-100000.0; // priority 1: sum of columns equals parent
- for(int i=cols*2; i<cols*2+numkids; i++) coeff[i] = (float)-1000.0; // priority 2: honor maxwidths
- for(int i=cols; i<cols*2; i++) coeff[i] = (float)(-1.0); // priority 3: equalize columns
- lp_h.setObjective(coeff, true);
+ coeff[cols*2+numkids] = (float)10000.0; // priority 1: sum of columns equals parent
+ for(int i=cols*2; i<cols*2+numkids; i++) coeff[i] = (float)100.0; // priority 2: honor maxwidths
+ for(int i=cols; i<cols*2; i++) coeff[i] = (float)(1.0); // priority 3: equalize columns
+ lp_h.setObjective(coeff, false);
// priority 1: sum of columns at least as big as parent
for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
}
// priority 3: equalize columns
+ for(int i=0 ; i<cols; i++) lp_h.set_lowbo(i+1, (float)0.0);
for(int i=0 ; i<cols; i++) {
- lp_h.set_lowbo(i+1, (float)0.0);
- lp_h.bound_difference(i, cols+i, ((float)width)/((float)cols), LinearProgramming.LE, coeff);
- lp_h.bound_sum( i, cols+i, ((float)width)/((float)cols), LinearProgramming.GE, coeff);
+ for(int j=0 ; j<i; j++) {
+ for(int k=0; k<coeff.length; k++) coeff[k] = (float)(k==i?1.0:k==j?-1.0:k==(cols+1)?-1.0:0.0);
+ lp_h.add_constraint(coeff, LinearProgramming.LE, 0);
+ for(int k=0; k<coeff.length; k++) coeff[k] = (float)(k==i?1.0:k==j?-1.0:k==(cols+1)?1.0:0.0);
+ lp_h.add_constraint(coeff, LinearProgramming.GE, 0);
+ }
}
-
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
lp_h.solve();
} while(false);
//#end