fixed bug 519
authoradam <adam@megacz.com>
Mon, 5 Apr 2004 06:29:55 +0000 (06:29 +0000)
committeradam <adam@megacz.com>
Mon, 5 Apr 2004 06:29:55 +0000 (06:29 +0000)
darcs-hash:20040405062955-5007d-af8edadf68a40bd5dfef7e877736d2124267c6b2.gz

src/org/ibex/Box.java
src/org/ibex/util/LinearProgramming.java

index 2ada11f..3c3b868 100644 (file)
@@ -304,14 +304,14 @@ public final class Box extends JSScope implements Scheduler.Task {
         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;
@@ -337,12 +337,16 @@ public final class Box extends JSScope implements Scheduler.Task {
             }
 
             // 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
index c8cfe7f..2dc47d4 100644 (file)
@@ -238,8 +238,9 @@ public class LinearProgramming {
             alternate_mat = new MatrixArray(mat_alloc);
         }
         
-        public void init(int nrows, int ncolumns) {
+        public void init(int ncolumns) {
             int nsum;  
+            int nrows = 0;
             nsum=nrows+ncolumns;
             active=FALSE;
             debug=FALSE;