You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/08/19 12:14:27 UTC
svn commit: r805728 - in /myfaces/tobago/trunk/core/src:
main/java/org/apache/myfaces/tobago/layout/math/SystemOfEquations.java
test/java/org/apache/myfaces/tobago/layout/math/SystemOfEquationsUnitTest.java
Author: lofwyr
Date: Wed Aug 19 10:14:27 2009
New Revision: 805728
URL: http://svn.apache.org/viewvc?rev=805728&view=rev
Log:
TOBAGO-606: Layout-Manager
- change algorithm in case of undefined variables
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/math/SystemOfEquations.java
myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/math/SystemOfEquationsUnitTest.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/math/SystemOfEquations.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/math/SystemOfEquations.java?rev=805728&r1=805727&r2=805728&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/math/SystemOfEquations.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/math/SystemOfEquations.java Wed Aug 19 10:14:27 2009
@@ -139,18 +139,14 @@
Collections.sort(equations, new EquationComparator());
if (numberOfVariables != equations.size()) {
- LOG.warn("SOE have not correct dimensions: " + this);
+ LOG.warn("SOE have not correct dimensions: " + this); // todo: remove this warning, when all problems are solved
}
data = new double[equations.size()][];
for (int i = 0; i < equations.size(); i++) {
data[i] = equations.get(i).fillRow(numberOfVariables + 1);
}
- /*
- for (int i = 0; i < equalEquations.size(); i++) {
- data[i + equations.size()] = equalEquations.get(i);
- }
-*/
+
step = step.next();
}
@@ -163,13 +159,11 @@
assert step == Step.PREPARED;
step = step.next();
- int min = Math.min(data.length, numberOfVariables);
-
- for (int j = 0; j < min; j++) {
+ for (int j = 0; j < numberOfVariables; j++) {
// normalize row
- if (LOG.isDebugEnabled()) {
- LOG.debug(this);
- }
+// if (LOG.isDebugEnabled()) {
+// LOG.debug(this);
+// }
double factor = data[j][j];
if (MathUtils.isZero(factor)) {
int nonZeroIndex = findNonZero(j);
@@ -177,19 +171,8 @@
swapRow(j, nonZeroIndex);
factor = data[j][j];
} else {
-// LOG.error("No Not unique solvable: " + this);
-// continue;
-
- int fullZeroIndex = findFullZero();
- if (fullZeroIndex != -1) {
- swapRow(j, fullZeroIndex);
- data[j][j] = 1.0;
- data[j][numberOfVariables] = 100.0; // todo: default
- LOG.warn("Setting free (undefined) variable x_" + j + " to " + data[j][numberOfVariables]);
- factor = data[j][j];
- } else {
- LOG.error("Not unique solvable: " + this);
- }
+ insertRow(j);
+ continue;
}
}
divideRow(j, factor);
@@ -203,19 +186,27 @@
}
private void reduce() {
- assert step == Step.TRIANGULAR;
- step = step.next();
-
if (LOG.isDebugEnabled()) {
LOG.debug(this);
}
+
+ assert step == Step.TRIANGULAR;
+ step = step.next();
+
for (int j = equations.size() - 1; j >= 0; j--) {
if (rowNull(j)) {
LOG.error("Not solvable: " + this);
continue;
}
for (int k = j - 1; k >= 0; k--) {
- substractMultipleOfRowJToRowK(j, k);
+// if (LOG.isDebugEnabled()) {
+// LOG.debug("j=" + j + "k=" + k + this);
+// }
+ double factor = data[k][j];
+ if (MathUtils.isNotZero(factor)) {
+ data[k][j] -= data[j][j] * factor;
+ data[k][numberOfVariables] -= data[j][numberOfVariables] * factor;
+ }
}
}
@@ -320,6 +311,24 @@
return -1;
}
+ private void insertRow(int j) {
+ LOG.warn("Not unique solvable, inserting dummy");
+ double[][] temp = data;
+ data = new double[temp.length + 1][];
+ for (int i = 0; i < temp.length; i++) {
+ if (i < j) {
+ data[i] = temp[i];
+ } else {
+ data[i + 1] = temp[i];
+ }
+ }
+ data[j] = new double[numberOfVariables + 1];
+ data[j][j] = 1;
+ data[j][numberOfVariables] = 100.0; // todo: default
+ LOG.warn("Setting free (undefined) variable x_" + j + " to " + data[j][numberOfVariables]);
+ equations.add(j, new ZeroEquation());// fixme
+ }
+
/**
* Searches for a row where all values are zero (comes from ZeroEquation)
*
Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/math/SystemOfEquationsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/math/SystemOfEquationsUnitTest.java?rev=805728&r1=805727&r2=805728&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/math/SystemOfEquationsUnitTest.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/math/SystemOfEquationsUnitTest.java Wed Aug 19 10:14:27 2009
@@ -19,8 +19,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.layout.LayoutTokens;
import org.apache.myfaces.tobago.layout.Measure;
import org.apache.myfaces.tobago.layout.PixelMeasure;
+import org.apache.myfaces.tobago.layout.RelativeLayoutToken;
import org.junit.Assert;
import org.junit.Test;
@@ -147,14 +149,14 @@
SystemOfEquations system = new SystemOfEquations(10);
system.addEqualsEquation(new FixedEquation(0, px(900), "test"));
system.addEqualsEquation(new PartitionEquation(1, 3, 0, px(0), px(0), px(0), "test"));
- system.addEqualsEquation(new CombinationEquation(5, 2, 2, px(0), "test"));
+ system.addEqualsEquation(new CombinationEquation(5, 2, 2, px(0), new RelativeLayoutToken(1), "test"));
system.addEqualsEquation(new PartitionEquation(6, 3, 5, px(0), px(0), px(0), "test"));
system.addEqualsEquation(new ProportionEquation(1, 2, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(1, 3, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(6, 7, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(6, 8, 1, 1, "test"));
- system.addEqualsEquation(new RemainderEquation(4, "test"));
- system.addEqualsEquation(new RemainderEquation(9, "test"));
+ system.addEqualsEquation(new RemainderEquation(4, tokens(), "test"));
+ system.addEqualsEquation(new RemainderEquation(9, tokens(), "test"));
Measure[] result = system.solve();
long end = System.nanoTime();
@@ -194,14 +196,14 @@
SystemOfEquations system = new SystemOfEquations(10);
// system.addEqualsEquation(new FixedEquation(0, 900)); // e. g. this is the missing equation
system.addEqualsEquation(new PartitionEquation(1, 3, 0, px(0), px(0), px(0), "test"));
- system.addEqualsEquation(new CombinationEquation(5, 2, 2, px(0), "test"));
+ system.addEqualsEquation(new CombinationEquation(5, 2, 2, px(0), new RelativeLayoutToken(1), "test"));
system.addEqualsEquation(new PartitionEquation(6, 3, 5, px(0), px(0), px(0), "test"));
system.addEqualsEquation(new ProportionEquation(1, 2, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(1, 3, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(6, 7, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(6, 8, 1, 1, "test"));
- system.addEqualsEquation(new RemainderEquation(4, "test"));
- system.addEqualsEquation(new RemainderEquation(9, "test"));
+ system.addEqualsEquation(new RemainderEquation(4, tokens(), "test"));
+ system.addEqualsEquation(new RemainderEquation(9, tokens(), "test"));
Measure[] result = system.solve();
long end = System.nanoTime();
@@ -258,14 +260,14 @@
SystemOfEquations system = new SystemOfEquations(10);
// system.addEqualsEquation(new FixedEquation(0, 900));
system.addEqualsEquation(new PartitionEquation(1, 3, 0, px(0), px(0), px(0), "test"));
- system.addEqualsEquation(new CombinationEquation(5, 2, 2, px(0), "test"));
+ system.addEqualsEquation(new CombinationEquation(5, 2, 2, px(0), new RelativeLayoutToken(1), "test"));
system.addEqualsEquation(new PartitionEquation(6, 3, 5, px(0), px(0), px(0), "test"));
system.addEqualsEquation(new ProportionEquation(1, 2, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(1, 3, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(6, 7, 1, 1, "test"));
system.addEqualsEquation(new ProportionEquation(6, 8, 1, 1, "test"));
- system.addEqualsEquation(new RemainderEquation(4, "test"));
- system.addEqualsEquation(new RemainderEquation(9, "test"));
+ system.addEqualsEquation(new RemainderEquation(4, tokens(), "test"));
+ system.addEqualsEquation(new RemainderEquation(9, tokens(), "test"));
Measure[] result = system.solve();
long end = System.nanoTime();
@@ -309,11 +311,11 @@
system.addEqualsEquation(new FixedEquation(0, px(310), "test"));
system.addEqualsEquation(new PartitionEquation(1, 2, 0, px(5), px(0), px(0), "test"));
system.addEqualsEquation(new ProportionEquation(1, 2, 1, 1, "test"));
- system.addEqualsEquation(new CombinationEquation(4, 1, 1, px(0), "test"));
- system.addEqualsEquation(new CombinationEquation(5, 1, 1, px(0), "test"));
- system.addEqualsEquation(new CombinationEquation(6, 2, 1, px(0), "test"));
- system.addEqualsEquation(new CombinationEquation(7, 2, 1, px(0), "test"));
- system.addEqualsEquation(new RemainderEquation(3, "test"));
+ system.addEqualsEquation(new CombinationEquation(4, 1, 1, px(0), new RelativeLayoutToken(1), "test"));
+ system.addEqualsEquation(new CombinationEquation(5, 1, 1, px(0), new RelativeLayoutToken(1), "test"));
+ system.addEqualsEquation(new CombinationEquation(6, 2, 1, px(0), new RelativeLayoutToken(1), "test"));
+ system.addEqualsEquation(new CombinationEquation(7, 2, 1, px(0), new RelativeLayoutToken(1), "test"));
+ system.addEqualsEquation(new RemainderEquation(3, tokens(), "test"));
Measure[] result = system.solve();
long end = System.nanoTime();
@@ -335,8 +337,8 @@
system.addEqualsEquation(new PartitionEquation(1, 2, 0, px(0), px(0), px(0), "test"));
system.addEqualsEquation(new ProportionEquation(1, 2, 1, 1, "test"));
system.addEqualsEquation(new PartitionEquation(4, 1, 1, px(0), px(0), px(0), "test"));
- system.addEqualsEquation(new RemainderEquation(3, "test"));
- system.addEqualsEquation(new RemainderEquation(5, "test"));
+ system.addEqualsEquation(new RemainderEquation(3, tokens(), "test"));
+ system.addEqualsEquation(new RemainderEquation(5, tokens(), "test"));
Measure[] result = system.solve();
long end = System.nanoTime();
@@ -368,4 +370,8 @@
return new PixelMeasure(pixel);
}
+ private LayoutTokens tokens() {
+ return LayoutTokens.parse("*");
+ }
+
}