ConsistencyCheck.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "ConsistencyCheck.h"
  2. #include <QtMath>
  3. #include <QDebug>
  4. ConsistencyCheck::ConsistencyCheck(const QStringList &nodes, const QVector<qreal> &nxnValus)
  5. : m_nodes(nodes),
  6. m_sqartnValues(QVector<double>(nodes.count(), 0)),
  7. m_weights(QVector<double>(nodes.count(), 0)),
  8. m_averageWeights(QVector<double>(nodes.count(), 0)),
  9. m_CI(0),
  10. m_CR(0)
  11. {
  12. // qDebug() << "ConsistencyCheck nodes" << nodes;
  13. calc(nxnValus);
  14. }
  15. void ConsistencyCheck::calc(const QVector<qreal> &nxnValus)
  16. {
  17. // qDebug() << "ConsistencyCheck nxnValus" << nxnValus;
  18. QVector<qreal> nodeMul(m_nodes.count(), 1);
  19. for (int m = 0; m < m_nodes.count(); ++m) {
  20. for (int n = 0; n < m_nodes.count(); ++n) {
  21. nodeMul[m] *= nxnValus[m * m_nodes.count() + n];
  22. }
  23. }
  24. // qDebug() << "nodeMul" << nodeMul;
  25. qreal nSum = 0;
  26. for (int n = 0; n < m_sqartnValues.count(); ++n) {
  27. m_sqartnValues[n] = qPow(nodeMul[n], (qreal)1 / m_sqartnValues.count());
  28. nSum += m_sqartnValues[n];
  29. }
  30. // qDebug() << "sqartnValues" << m_sqartnValues;
  31. for (int w = 0; w < m_weights.count(); ++w) {
  32. m_weights[w] = m_sqartnValues[w] / nSum;
  33. }
  34. // qDebug() << "weights" << m_weights;
  35. // m0*w0+m1*w1+m2*w2+m3*w3...mn*wn
  36. for (int m = 0; m < m_nodes.count(); ++m) {
  37. for (int n = 0; n < m_nodes.count(); ++n) {
  38. m_averageWeights[m] += nxnValus[m * m_nodes.count() + n] * m_weights[n];
  39. }
  40. }
  41. // qDebug() << "averageWeights" << m_averageWeights;
  42. // Awi/Wi
  43. QVector<qreal> awiDividedWi(m_nodes.count(), 0);
  44. qreal awiDividedWiAverage = 0;
  45. for (int m = 0; m < m_nodes.count(); ++m) {
  46. awiDividedWi[m] = m_averageWeights[m] / m_weights[m];
  47. awiDividedWiAverage += awiDividedWi[m];
  48. }
  49. awiDividedWiAverage /= m_nodes.count();
  50. // qDebug() << "awiDividedWi" << awiDividedWi;
  51. // CI=(λ-n)/(n-1)
  52. m_CI = (awiDividedWiAverage - m_nodes.count()) / (m_nodes.count() - 1);
  53. qreal result = m_nodes.count() <= 10 ? RI[m_nodes.count() - 1] : RI[9];
  54. if (qFuzzyCompare(result, 0)) {
  55. m_CR = 0;
  56. } else {
  57. m_CR = m_CI / result;
  58. }
  59. // qDebug() << RI[m_nodes.count() - 1] << "m_CI" << m_CI << "m_CR" << m_CR;
  60. }