SetPairAnalysis.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Created by lenovo on 2023/10/18.
  3. //
  4. #include "SetPairAnalysis.h"
  5. /********************************************************************
  6. *@Demo1归一化均值
  7. * QVector<SetPairAnalysis::EvaluateIndex> rMat;
  8. * rMat << SetPairAnalysis::EvaluateIndex { 70, 20, 10 };
  9. * rMat << SetPairAnalysis::EvaluateIndex { 70, 18, 12 };
  10. * QVector<qreal> wMat, eMat;
  11. * wMat << 1.0 << 0.5 << 1.0;
  12. * eMat << 1.0 << 1.0 << -1.0;
  13. * SetPairAnalysis spa(rMat, wMat, eMat);
  14. * SetPairAnalysis::Relations r = spa.getRelations();
  15. * qDebug() << r;
  16. *
  17. *@Demo2总体平衡均值
  18. * QVector<SetPairAnalysis::EvaluateIndex> rMat;
  19. * QVector<qreal> wMat, eMat;
  20. * rMat << SetPairAnalysis::EvaluateIndex { 2.5, 66, 80, 800 };
  21. * rMat << SetPairAnalysis::EvaluateIndex { 3.0, 79, 77, 810 };
  22. * rMat << SetPairAnalysis::EvaluateIndex { 3.5, 85, 90, 900 };
  23. * rMat << SetPairAnalysis::EvaluateIndex { 4.0, 98, 92, 920 };
  24. * rMat << SetPairAnalysis::EvaluateIndex { 3.5, 83, 88, 780 };
  25. * wMat << 0.3 << 0.5 << 0.15 << 0.05;
  26. * eMat << 1.0 << 1.0 << 1.0 << 1.0;
  27. * QVector<bool> dir;
  28. * dir << false << true << false << false;
  29. * SetPairAnalysis spa(rMat, wMat, eMat, dir);
  30. * SetPairAnalysis::Relations r = spa.getRelations();
  31. * qDebug() << r;
  32. *
  33. *
  34. ********************************************************************/
  35. SetPairAnalysis::SetPairAnalysis(const QVector<EvaluateIndex> &rMat, const QVector<qreal> &wMat,
  36. const QVector<qreal> &eMat, const QVector<bool> &optiDir)
  37. : m_rMat(rMat), m_wMat(wMat), m_eMat(eMat) {
  38. Q_ASSERT(rMat.count() != 0);
  39. Q_ASSERT(rMat.at(0).count() != 0);
  40. // Q_ASSERT(rMat.at(0).count() == wMat.count());
  41. if (optiDir.isEmpty()) {
  42. for (auto &r: m_rMat) {
  43. qreal sum = 0;
  44. for (int i = 0; i < r.count(); ++i) {
  45. sum += r.at(i);
  46. }
  47. for (int i = 0; i < r.count(); ++i) {
  48. r[i] = r[i] / sum;
  49. }
  50. }
  51. } else {
  52. EvaluateIndex optiIndex = EvaluateIndex(m_rMat.at(0).count());
  53. for (int r = 0; r < m_rMat.count(); ++r) {
  54. for (int i = 0; i < m_rMat.at(r).count(); ++i) {
  55. if (r == 0) {
  56. optiIndex[i] = m_rMat.at(r).at(i);
  57. } else {
  58. if (optiDir.at(i)) { //最大值
  59. if (optiIndex.at(i) < m_rMat.at(r).at(i)) {
  60. optiIndex[i] = m_rMat.at(r).at(i);
  61. }
  62. } else {
  63. if (optiIndex.at(i) > m_rMat.at(r).at(i)) {
  64. optiIndex[i] = m_rMat.at(r).at(i);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. // qDebug() << optiIndex;
  71. for (auto &r: m_rMat) {
  72. for (int i = 0; i < r.count(); ++i) {
  73. if (optiDir.at(i)) { //最大值
  74. // qDebug() << r[i] << "/" << optiIndex.at(i);
  75. r[i] = r[i] / optiIndex.at(i);
  76. } else {
  77. // qDebug() << optiIndex.at(i) << "/" << r[i];
  78. r[i] = optiIndex.at(i) / r[i];
  79. }
  80. }
  81. // qDebug() << "next";
  82. }
  83. }
  84. // qDebug() << m_rMat;
  85. if (m_eMat.isEmpty()) {
  86. m_eMat = QVector<qreal>(m_wMat.count(), 1.0);
  87. }
  88. }
  89. Relations SetPairAnalysis::getRelations() const {
  90. Relations uMat;
  91. for (auto r: m_rMat) {
  92. qreal ui = 0;
  93. for (int i = 0; i < r.count(); ++i) {
  94. ui += r.at(i) * m_wMat.at(i) * m_eMat.at(i);
  95. }
  96. uMat << ui;
  97. }
  98. return uMat;
  99. }