Qt 4.8
|
The QSimplex class is a Linear Programming problem solver based on the two-phase simplex method. More...
#include <qsimplex_p.h>
Public Functions | |
void | dumpMatrix () |
QSimplex () | |
bool | setConstraints (const QList< QSimplexConstraint *> constraints) |
Sets the new constraints in the simplex solver and returns whether the problem is feasible. More... | |
void | setObjective (QSimplexConstraint *objective) |
qreal | solveMax () |
Maximize the original objective. More... | |
qreal | solveMin () |
Minimize the original objective. More... | |
virtual | ~QSimplex () |
Private Types | |
enum | solverFactor { Minimum = -1, Maximum = 1 } |
Private Functions | |
void | clearColumns (int first, int last) |
void | clearDataStructures () |
void | clearRow (int rowIndex) |
void | collectResults () |
Reads results from the simplified matrix and saves them in the "result" member of each QSimplexVariable. More... | |
void | combineRows (int toIndex, int fromIndex, qreal factor) |
int | findPivotColumn () |
bool | iterate () |
Does one iteration towards a better solution for the problem. More... | |
int | pivotRowForColumn (int column) |
For a given pivot column, find the pivot row. More... | |
void | reducedRowEchelon () |
void | setValueAt (int row, int column, qreal value) |
bool | simplifyConstraints (QList< QSimplexConstraint *> *constraints) |
Looks for single-valued variables and remove them from the constraints list. More... | |
void | solveMaxHelper () |
Run simplex on the current matrix with the current objective. More... | |
qreal | solver (solverFactor factor) |
Both solveMin and solveMax are interfaces to this method. More... | |
qreal | valueAt (int row, int column) |
Properties | |
int | columns |
QList< QSimplexConstraint * > | constraints |
int | firstArtificial |
qreal * | matrix |
QSimplexConstraint * | objective |
int | rows |
QList< QSimplexVariable * > | variables |
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 149 of file qsimplex_p.h.
|
private |
Enumerator | |
---|---|
Minimum | |
Maximum |
Definition at line 181 of file qsimplex_p.h.
QSimplex::QSimplex | ( | ) |
Definition at line 84 of file qsimplex_p.cpp.
|
virtual |
Definition at line 91 of file qsimplex_p.cpp.
|
private |
Definition at line 350 of file qsimplex_p.cpp.
Referenced by setConstraints().
|
private |
Definition at line 99 of file qsimplex_p.cpp.
Referenced by setConstraints(), and ~QSimplex().
|
private |
Definition at line 340 of file qsimplex_p.cpp.
Referenced by solver().
|
private |
Reads results from the simplified matrix and saves them in the "result" member of each QSimplexVariable.
Definition at line 608 of file qsimplex_p.cpp.
Referenced by solver().
|
private |
Definition at line 384 of file qsimplex_p.cpp.
Referenced by iterate(), and reducedRowEchelon().
void QSimplex::dumpMatrix | ( | ) |
Definition at line 362 of file qsimplex_p.cpp.
|
private |
Definition at line 410 of file qsimplex_p.cpp.
Referenced by iterate().
|
private |
Does one iteration towards a better solution for the problem.
See 'solveMaxHelper'.
Definition at line 487 of file qsimplex_p.cpp.
Referenced by solveMaxHelper().
|
private |
For a given pivot column, find the pivot row.
That is, the row with the minimum associated "quotient" where:
The last condition avoids a bug where artificial variables would be left behind for the second-phase simplex, and with 'good' constraints would be removed before it, what would lead to incorrect results.
Definition at line 445 of file qsimplex_p.cpp.
Referenced by iterate().
|
private |
Definition at line 470 of file qsimplex_p.cpp.
Referenced by solveMaxHelper().
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 135 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax(), and QGraphicsAnchorLayoutPrivate::solvePreferred().
void QSimplex::setObjective | ( | QSimplexConstraint * | newObjective | ) |
Definition at line 332 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax(), and QGraphicsAnchorLayoutPrivate::solvePreferred().
|
inlineprivate |
Definition at line 201 of file qsimplex_p.h.
Referenced by iterate(), setConstraints(), and solver().
|
private |
Looks for single-valued variables and remove them from the constraints list.
Definition at line 635 of file qsimplex_p.cpp.
Referenced by setConstraints().
qreal QSimplex::solveMax | ( | ) |
Maximize the original objective.
Definition at line 594 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax().
|
private |
Run simplex on the current matrix with the current objective.
This is the iterative method. The matrix lines are combined as to modify the variable values towards the best solution possible. The method returns when the matrix is in the optimal state.
Definition at line 323 of file qsimplex_p.cpp.
Referenced by setConstraints(), and solver().
qreal QSimplex::solveMin | ( | ) |
Minimize the original objective.
Definition at line 582 of file qsimplex_p.cpp.
Referenced by QGraphicsAnchorLayoutPrivate::solveMinMax(), and QGraphicsAnchorLayoutPrivate::solvePreferred().
|
private |
Both solveMin and solveMax are interfaces to this method.
The enum solverFactor admits 2 values: Minimum (-1) and Maximum (+1).
This method sets the original objective and runs the second phase Simplex to obtain the optimal solution for the problem. As the internal simplex solver is only able to maximize objectives, we handle the minimization case by inverting the original objective and then maximizing it.
Definition at line 538 of file qsimplex_p.cpp.
Referenced by solveMax(), and solveMin().
|
inlineprivate |
Definition at line 196 of file qsimplex_p.h.
Referenced by collectResults(), findPivotColumn(), iterate(), pivotRowForColumn(), reducedRowEchelon(), setConstraints(), and solver().
|
private |
Definition at line 190 of file qsimplex_p.h.
Referenced by clearColumns(), clearDataStructures(), clearRow(), collectResults(), combineRows(), dumpMatrix(), findPivotColumn(), pivotRowForColumn(), setConstraints(), and solver().
|
private |
Definition at line 185 of file qsimplex_p.h.
Referenced by clearDataStructures(), setConstraints(), and solver().
|
private |
Definition at line 191 of file qsimplex_p.h.
Referenced by clearDataStructures(), and setConstraints().
|
private |
Definition at line 193 of file qsimplex_p.h.
Referenced by clearColumns(), clearDataStructures(), clearRow(), combineRows(), dumpMatrix(), and setConstraints().
|
private |
Definition at line 187 of file qsimplex_p.h.
Referenced by clearDataStructures(), setObjective(), and solver().
|
private |
Definition at line 189 of file qsimplex_p.h.
Referenced by clearColumns(), clearDataStructures(), collectResults(), dumpMatrix(), iterate(), pivotRowForColumn(), reducedRowEchelon(), and setConstraints().
|
private |
Definition at line 186 of file qsimplex_p.h.
Referenced by clearDataStructures(), collectResults(), QSimplexConstraint::invert(), and setConstraints().