summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-09-28 14:49:42 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-06 09:28:49 (GMT)
commitba66cc0bde91e1143ac0a34f249f98e4573a5737 (patch)
tree9df08eaed5c4f79e4efd210cd9c07183e6fcab1c /src/gui
parentad69bb73754534f61658a83e85dadb75e603c90a (diff)
downloadQt-ba66cc0bde91e1143ac0a34f249f98e4573a5737.zip
Qt-ba66cc0bde91e1143ac0a34f249f98e4573a5737.tar.gz
Qt-ba66cc0bde91e1143ac0a34f249f98e4573a5737.tar.bz2
QSimplex: Remove overly conservative assertion
This assertion started failing after the addition of expanding state. After some investigation we felt that the assertion itself was too strong and would fail in some valid cases. The new assertion is formally right as it tests whether the simplex solver was able to satisfy the simplex constraints, _exactly_ what it is expected to do. Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/graphicsview/qsimplex_p.cpp24
-rw-r--r--src/gui/graphicsview/qsimplex_p.h26
2 files changed, 31 insertions, 19 deletions
diff --git a/src/gui/graphicsview/qsimplex_p.cpp b/src/gui/graphicsview/qsimplex_p.cpp
index 00fc204..95003d2 100644
--- a/src/gui/graphicsview/qsimplex_p.cpp
+++ b/src/gui/graphicsview/qsimplex_p.cpp
@@ -285,24 +285,6 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> newConstraints)
// anymore.
clearColumns(firstArtificial, columns - 2);
- #ifdef QT_DEBUG
- // Ensure that at the end of the simplex each row should either:
- // - Have a positive value on the column associated to its variable, or
- // - Have zero values in all columns.
- //
- // This avoids a regression where restrictions would be lost
- // due to randomness in the pivotRowForColumn method.
- for (int i = 1; i < rows; ++i) {
- int variableIndex = valueAt(i, 0);
- if (valueAt(i, variableIndex) > 0)
- continue;
-
- for (int j = 1; j < columns; ++j) {
- Q_ASSERT(valueAt(i, j) == 0);
- }
- }
- #endif
-
return true;
}
@@ -537,6 +519,12 @@ qreal QSimplex::solver(solverFactor factor)
solveMaxHelper();
collectResults();
+ #ifdef QT_DEBUG
+ for (int i = 0; i < constraints.size(); ++i) {
+ Q_ASSERT(constraints[i]->isSatisfied());
+ }
+ #endif
+
return factor * valueAt(0, columns - 1);
}
diff --git a/src/gui/graphicsview/qsimplex_p.h b/src/gui/graphicsview/qsimplex_p.h
index 54b080d..b517cb9 100644
--- a/src/gui/graphicsview/qsimplex_p.h
+++ b/src/gui/graphicsview/qsimplex_p.h
@@ -94,8 +94,32 @@ struct QSimplexConstraint
QPair<QSimplexVariable *, qreal> helper;
QSimplexVariable * artificial;
-};
+ #ifdef QT_DEBUG
+ bool isSatisfied() {
+ qreal leftHandSide(0);
+
+ QHash<QSimplexVariable *, qreal>::const_iterator iter;
+ for (iter = variables.constBegin(); iter != variables.constEnd(); ++iter) {
+ leftHandSide += iter.value() * iter.key()->result;
+ }
+
+ Q_ASSERT(constant > 0 || qFuzzyCompare(1, 1 + constant));
+
+ if (qFuzzyCompare(1000 + leftHandSide, 1000 + constant))
+ return true;
+
+ switch (ratio) {
+ case LessOrEqual:
+ return leftHandSide < constant;
+ case MoreOrEqual:
+ return leftHandSide > constant;
+ default:
+ return false;
+ }
+ }
+ #endif
+};
class QSimplex
{