![]() |
Qt 6.x
The Qt SDK
|
#include <qsimplex_p.h>
Public Member Functions | |
QSimplex () | |
~QSimplex () | |
qreal | solveMin () |
qreal | solveMax () |
bool | setConstraints (const QList< QSimplexConstraint * > &constraints) |
void | setObjective (QSimplexConstraint *objective) |
void | dumpMatrix () |
The QSimplex class is a Linear Programming problem solver based on the two-phase simplex method.
It takes a set of QSimplexConstraints as its restrictive constraints and an additional QSimplexConstraint as its objective function. Then methods to maximize and minimize the problem solution are provided.
The two-phase simplex method is based on the following steps: First phase: 1.a) Modify the original, complex, and possibly not feasible problem, into a new, easy to solve problem. 1.b) Set as the objective of the new problem, a feasible solution for the original complex problem. 1.c) Run simplex to optimize the modified problem and check whether a solution for the original problem exists.
Second phase: 2.a) Go back to the original problem with the feasibl (but not optimal) solution found in the first phase. 2.b) Set the original objective. 3.c) Run simplex to optimize the original problem towards its optimal solution.
Definition at line 115 of file qsimplex_p.h.
QSimplex::QSimplex | ( | ) |
Definition at line 45 of file qsimplex_p.cpp.
QSimplex::~QSimplex | ( | ) |
Definition at line 52 of file qsimplex_p.cpp.
void QSimplex::dumpMatrix | ( | ) |
Definition at line 319 of file qsimplex_p.cpp.
References QString::arg(), QString::fromLatin1(), i, j, qDebug, qPrintable, and str.
bool QSimplex::setConstraints | ( | const QList< QSimplexConstraint * > & | newConstraints | ) |
Sets the new constraints in the simplex solver and returns whether the problem is feasible.
This method sets the new constraints, normalizes them, creates the simplex matrix and runs the first simplex phase.
Definition at line 93 of file qsimplex_p.cpp.
References QList< T >::at(), QSet< T >::cbegin(), QList< T >::clear(), QSimplexConstraint::constant, QSimplexConstraint::Equal, QList< T >::first(), i, QSimplexVariable::index, QSet< T >::insert(), QList< T >::isEmpty(), it, iter, j, QSimplexConstraint::LessOrEqual, QSimplexConstraint::MoreOrEqual, Q_ASSERT, Q_FALLTHROUGH, qAbs(), qWarning, QList< T >::size(), QSet< T >::values(), and QSimplexConstraint::variables.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax(), and QGraphicsAnchorLayoutPrivate::solvePreferred().
void QSimplex::setObjective | ( | QSimplexConstraint * | newObjective | ) |
Definition at line 289 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax(), and QGraphicsAnchorLayoutPrivate::solvePreferred().
qreal QSimplex::solveMax | ( | ) |
Maximize the original objective.
Definition at line 536 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax().
qreal QSimplex::solveMin | ( | ) |
Minimize the original objective.
Definition at line 527 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax(), and QGraphicsAnchorLayoutPrivate::solvePreferred().