123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // Created by lenovo on 2023/10/18.
- //
- #include "SetPairAnalysis.h"
- /********************************************************************
- *@Demo1归一化均值
- * QVector<SetPairAnalysis::EvaluateIndex> rMat;
- * rMat << SetPairAnalysis::EvaluateIndex { 70, 20, 10 };
- * rMat << SetPairAnalysis::EvaluateIndex { 70, 18, 12 };
- * QVector<qreal> wMat, eMat;
- * wMat << 1.0 << 0.5 << 1.0;
- * eMat << 1.0 << 1.0 << -1.0;
- * SetPairAnalysis spa(rMat, wMat, eMat);
- * SetPairAnalysis::Relations r = spa.getRelations();
- * qDebug() << r;
- *
- *@Demo2总体平衡均值
- * QVector<SetPairAnalysis::EvaluateIndex> rMat;
- * QVector<qreal> wMat, eMat;
- * rMat << SetPairAnalysis::EvaluateIndex { 2.5, 66, 80, 800 };
- * rMat << SetPairAnalysis::EvaluateIndex { 3.0, 79, 77, 810 };
- * rMat << SetPairAnalysis::EvaluateIndex { 3.5, 85, 90, 900 };
- * rMat << SetPairAnalysis::EvaluateIndex { 4.0, 98, 92, 920 };
- * rMat << SetPairAnalysis::EvaluateIndex { 3.5, 83, 88, 780 };
- * wMat << 0.3 << 0.5 << 0.15 << 0.05;
- * eMat << 1.0 << 1.0 << 1.0 << 1.0;
- * QVector<bool> dir;
- * dir << false << true << false << false;
- * SetPairAnalysis spa(rMat, wMat, eMat, dir);
- * SetPairAnalysis::Relations r = spa.getRelations();
- * qDebug() << r;
- *
- *
- ********************************************************************/
- SetPairAnalysis::SetPairAnalysis(const QVector<EvaluateIndex> &rMat, const QVector<qreal> &wMat,
- const QVector<qreal> &eMat, const QVector<bool> &optiDir)
- : m_rMat(rMat), m_wMat(wMat), m_eMat(eMat) {
- Q_ASSERT(rMat.count() != 0);
- Q_ASSERT(rMat.at(0).count() != 0);
- // Q_ASSERT(rMat.at(0).count() == wMat.count());
- if (optiDir.isEmpty()) {
- for (auto &r: m_rMat) {
- qreal sum = 0;
- for (int i = 0; i < r.count(); ++i) {
- sum += r.at(i);
- }
- for (int i = 0; i < r.count(); ++i) {
- r[i] = r[i] / sum;
- }
- }
- } else {
- EvaluateIndex optiIndex = EvaluateIndex(m_rMat.at(0).count());
- for (int r = 0; r < m_rMat.count(); ++r) {
- for (int i = 0; i < m_rMat.at(r).count(); ++i) {
- if (r == 0) {
- optiIndex[i] = m_rMat.at(r).at(i);
- } else {
- if (optiDir.at(i)) { //最大值
- if (optiIndex.at(i) < m_rMat.at(r).at(i)) {
- optiIndex[i] = m_rMat.at(r).at(i);
- }
- } else {
- if (optiIndex.at(i) > m_rMat.at(r).at(i)) {
- optiIndex[i] = m_rMat.at(r).at(i);
- }
- }
- }
- }
- }
- // qDebug() << optiIndex;
- for (auto &r: m_rMat) {
- for (int i = 0; i < r.count(); ++i) {
- if (optiDir.at(i)) { //最大值
- // qDebug() << r[i] << "/" << optiIndex.at(i);
- r[i] = r[i] / optiIndex.at(i);
- } else {
- // qDebug() << optiIndex.at(i) << "/" << r[i];
- r[i] = optiIndex.at(i) / r[i];
- }
- }
- // qDebug() << "next";
- }
- }
- // qDebug() << m_rMat;
- if (m_eMat.isEmpty()) {
- m_eMat = QVector<qreal>(m_wMat.count(), 1.0);
- }
- }
- Relations SetPairAnalysis::getRelations() const {
- Relations uMat;
- for (auto r: m_rMat) {
- qreal ui = 0;
- for (int i = 0; i < r.count(); ++i) {
- ui += r.at(i) * m_wMat.at(i) * m_eMat.at(i);
- }
- uMat << ui;
- }
- return uMat;
- }
|