Qt 4.8
Public Types | Public Functions | Public Variables | List of all members
QSimplexConstraint Struct Reference

#include <qsimplex_p.h>

Public Types

enum  Ratio { LessOrEqual = 0, Equal, MoreOrEqual }
 

Public Functions

void invert ()
 
bool isSatisfied ()
 
 QSimplexConstraint ()
 
QString toString ()
 

Public Variables

QSimplexVariableartificial
 
qreal constant
 
QPair< QSimplexVariable *, qrealhelper
 
Ratio ratio
 
QHash< QSimplexVariable *, qrealvariables
 

Detailed Description

Warning
This function is not part of the public interface.

Representation of a LP constraint like:

(c1 * X1) + (c2 * X2) + ... = K or <= K or >= K

Where (ci, Xi) are the pairs in "variables" and K the real "constant".

Definition at line 81 of file qsimplex_p.h.

Enumerations

◆ Ratio

Enumerator
LessOrEqual 
Equal 
MoreOrEqual 

Definition at line 85 of file qsimplex_p.h.

Constructors and Destructors

◆ QSimplexConstraint()

QSimplexConstraint::QSimplexConstraint ( )
inline

Definition at line 83 of file qsimplex_p.h.

Functions

◆ invert()

void QSimplexConstraint::invert ( )

Definition at line 692 of file qsimplex_p.cpp.

Referenced by QSimplex::simplifyConstraints().

693 {
694  constant = -constant;
695  ratio = Ratio(2 - ratio);
696 
698  for (iter = variables.begin(); iter != variables.end(); ++iter) {
699  iter.value() = -iter.value();
700  }
701 }
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QHash< QSimplexVariable *, qreal > variables
Definition: qsimplex_p.h:91
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464

◆ isSatisfied()

bool QSimplexConstraint::isSatisfied ( )
inline

Definition at line 100 of file qsimplex_p.h.

Referenced by QSimplex::simplifyConstraints().

100  {
101  qreal leftHandSide(0);
102 
104  for (iter = variables.constBegin(); iter != variables.constEnd(); ++iter) {
105  leftHandSide += iter.value() * iter.key()->result;
106  }
107 
108  Q_ASSERT(constant > 0 || qFuzzyCompare(1, 1 + constant));
109 
110  if ((leftHandSide == constant) || qAbs(leftHandSide - constant) < 0.0000001)
111  return true;
112 
113  switch (ratio) {
114  case LessOrEqual:
115  return leftHandSide < constant;
116  case MoreOrEqual:
117  return leftHandSide > constant;
118  default:
119  return false;
120  }
121  }
double qreal
Definition: qglobal.h:1193
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QHash< QSimplexVariable *, qreal > variables
Definition: qsimplex_p.h:91
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674

◆ toString()

QString QSimplexConstraint::toString ( )
inline

Definition at line 124 of file qsimplex_p.h.

124  {
125  QString result;
126  result += QString::fromAscii("-- QSimplexConstraint %1 --").arg(quintptr(this), 0, 16);
127 
129  for (iter = variables.constBegin(); iter != variables.constEnd(); ++iter) {
130  result += QString::fromAscii(" %1 x %2").arg(iter.value()).arg(quintptr(iter.key()), 0, 16);
131  }
132 
133  switch (ratio) {
134  case LessOrEqual:
135  result += QString::fromAscii(" (less) <= %1").arg(constant);
136  break;
137  case MoreOrEqual:
138  result += QString::fromAscii(" (more) >= %1").arg(constant);
139  break;
140  default:
141  result += QString::fromAscii(" (eqal) == %1").arg(constant);
142  }
143 
144  return result;
145  }
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QHash< QSimplexVariable *, qreal > variables
Definition: qsimplex_p.h:91
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674

Properties

◆ artificial

QSimplexVariable* QSimplexConstraint::artificial

Definition at line 96 of file qsimplex_p.h.

Referenced by QSimplex::setConstraints().

◆ constant

qreal QSimplexConstraint::constant

◆ helper

QPair<QSimplexVariable *, qreal> QSimplexConstraint::helper

Definition at line 95 of file qsimplex_p.h.

Referenced by QSimplex::setConstraints().

◆ ratio

Ratio QSimplexConstraint::ratio

◆ variables

QHash<QSimplexVariable *, qreal> QSimplexConstraint::variables

The documentation for this struct was generated from the following files: