Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsimplex_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSIMPLEX_P_H
5#define QSIMPLEX_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include <QtCore/qhash.h>
20#include <QtCore/qpair.h>
21#include <QtCore/qstring.h>
22
23QT_REQUIRE_CONFIG(graphicsview);
24
26
34
35
48{
50
56
57 QHash<QSimplexVariable *, qreal> variables;
60
61 QPair<QSimplexVariable *, qreal> helper;
63
64 void invert();
65
66 bool isSatisfied() {
67 qreal leftHandSide(0);
68
71 leftHandSide += iter.value() * iter.key()->result;
72 }
73
75
76 if ((leftHandSide == constant) || qAbs(leftHandSide - constant) < 0.0000001)
77 return true;
78
79 switch (ratio) {
80 case LessOrEqual:
81 return leftHandSide < constant;
82 case MoreOrEqual:
83 return leftHandSide > constant;
84 default:
85 return false;
86 }
87 }
88
89#ifdef QT_DEBUG
92 result += QString::fromLatin1("-- QSimplexConstraint %1 --").arg(quintptr(this), 0, 16);
93
96 result += QString::fromLatin1(" %1 x %2").arg(iter.value()).arg(quintptr(iter.key()), 0, 16);
97 }
98
99 switch (ratio) {
100 case LessOrEqual:
101 result += QString::fromLatin1(" (less) <= %1").arg(constant);
102 break;
103 case MoreOrEqual:
104 result += QString::fromLatin1(" (more) >= %1").arg(constant);
105 break;
106 default:
107 result += QString::fromLatin1(" (eqal) == %1").arg(constant);
108 }
109
110 return result;
111 }
112#endif
113};
114
116{
117 Q_DISABLE_COPY_MOVE(QSimplex)
118public:
119 QSimplex();
120 ~QSimplex();
121
122 qreal solveMin();
123 qreal solveMax();
124
125 bool setConstraints(const QList<QSimplexConstraint *> &constraints);
126 void setObjective(QSimplexConstraint *objective);
127
128 void dumpMatrix();
129
130private:
131 // Matrix handling
132 inline qreal valueAt(int row, int column);
133 inline void setValueAt(int row, int column, qreal value);
134 void clearRow(int rowIndex);
135 void clearColumns(int first, int last);
136 void combineRows(int toIndex, int fromIndex, qreal factor);
137
138 // Simplex
139 bool simplifyConstraints(QList<QSimplexConstraint *> *constraints);
140 int findPivotColumn();
141 int pivotRowForColumn(int column);
142 void reducedRowEchelon();
143 bool iterate();
144
145 // Helpers
146 void clearDataStructures();
147 void solveMaxHelper();
148 enum SolverFactor { Minimum = -1, Maximum = 1 };
149 qreal solver(SolverFactor factor);
150 void collectResults();
151
152 QList<QSimplexConstraint *> constraints;
153 QList<QSimplexVariable *> variables;
154 QSimplexConstraint *objective;
155
156 int rows;
157 int columns;
158 int firstArtificial;
159
160 qreal *matrix;
161};
162
163inline qreal QSimplex::valueAt(int rowIndex, int columnIndex)
164{
165 return matrix[rowIndex * columns + columnIndex];
166}
167
168inline void QSimplex::setValueAt(int rowIndex, int columnIndex, qreal value)
169{
170 matrix[rowIndex * columns + columnIndex] = value;
171}
172
174
175#endif // QSIMPLEX_P_H
\inmodule QtCore
Definition qhash.h:1145
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1219
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1215
bool setConstraints(const QList< QSimplexConstraint * > &constraints)
void dumpMatrix()
void setObjective(QSimplexConstraint *objective)
qreal solveMax()
qreal solveMin()
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLuint index
[2]
GLint first
GLenum GLenum GLsizei void GLsizei void * column
GLuint GLenum matrix
GLenum GLenum GLsizei void * row
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QT_REQUIRE_CONFIG(feature)
size_t quintptr
Definition qtypes.h:167
double qreal
Definition qtypes.h:187
static uint toIndex(ExecutionEngine *e, const Value &v)
QObject::connect nullptr
char * toString(const MyType &t)
[31]
QHash< QSimplexVariable *, qreal > variables
Definition qsimplex_p.h:57
QPair< QSimplexVariable *, qreal > helper
Definition qsimplex_p.h:61
QSimplexVariable * artificial
Definition qsimplex_p.h:62