#include "ConsistencyCheck.h" #include #include ConsistencyCheck::ConsistencyCheck(const QStringList &nodes, const QVector &nxnValus) : m_nodes(nodes), m_sqartnValues(QVector(nodes.count(), 0)), m_weights(QVector(nodes.count(), 0)), m_averageWeights(QVector(nodes.count(), 0)), m_CI(0), m_CR(0) { // qDebug() << "ConsistencyCheck nodes" << nodes; calc(nxnValus); } void ConsistencyCheck::calc(const QVector &nxnValus) { // qDebug() << "ConsistencyCheck nxnValus" << nxnValus; QVector nodeMul(m_nodes.count(), 1); for (int m = 0; m < m_nodes.count(); ++m) { for (int n = 0; n < m_nodes.count(); ++n) { nodeMul[m] *= nxnValus[m * m_nodes.count() + n]; } } // qDebug() << "nodeMul" << nodeMul; qreal nSum = 0; for (int n = 0; n < m_sqartnValues.count(); ++n) { m_sqartnValues[n] = qPow(nodeMul[n], (qreal)1 / m_sqartnValues.count()); nSum += m_sqartnValues[n]; } // qDebug() << "sqartnValues" << m_sqartnValues; for (int w = 0; w < m_weights.count(); ++w) { m_weights[w] = m_sqartnValues[w] / nSum; } // qDebug() << "weights" << m_weights; // m0*w0+m1*w1+m2*w2+m3*w3...mn*wn for (int m = 0; m < m_nodes.count(); ++m) { for (int n = 0; n < m_nodes.count(); ++n) { m_averageWeights[m] += nxnValus[m * m_nodes.count() + n] * m_weights[n]; } } // qDebug() << "averageWeights" << m_averageWeights; // Awi/Wi QVector awiDividedWi(m_nodes.count(), 0); qreal awiDividedWiAverage = 0; for (int m = 0; m < m_nodes.count(); ++m) { awiDividedWi[m] = m_averageWeights[m] / m_weights[m]; awiDividedWiAverage += awiDividedWi[m]; } awiDividedWiAverage /= m_nodes.count(); // qDebug() << "awiDividedWi" << awiDividedWi; // CI=(λ-n)/(n-1) m_CI = (awiDividedWiAverage - m_nodes.count()) / (m_nodes.count() - 1); qreal result = m_nodes.count() <= 10 ? RI[m_nodes.count() - 1] : RI[9]; if (qFuzzyCompare(result, 0)) { m_CR = 0; } else { m_CR = m_CI / result; } // qDebug() << RI[m_nodes.count() - 1] << "m_CI" << m_CI << "m_CR" << m_CR; }