Browse Source

添加算法注释,修正一些bug

Signed-off-by: codeClown <zhaomengshou@126.com>
codeClown 1 year ago
parent
commit
3008b19f16

+ 5 - 2
ExpertClient/EXDataTableView.cpp

@@ -292,8 +292,11 @@ void EXDataTableView::itemClicked(const QModelIndex &index)
 
     QTableView *table         = (QTableView *)sender();
     QStandardItemModel *model = (QStandardItemModel *)table->model();
-    SchemeBar *scheme =
-            new SchemeBar(model->item(index.row(), 0)->text(), model->horizontalHeaderItem(index.column())->text(), l);
+    //    SchemeBar *scheme =
+    //            new SchemeBar(model->item(index.row(), 0)->text(),
+    //            model->horizontalHeaderItem(index.column())->text(), l);
+    SchemeBar *scheme = new SchemeBar(model->verticalHeaderItem(index.row())->text(),
+                                      model->horizontalHeaderItem(index.column())->text(), l);
     scheme->setModal(true);
     scheme->setAttribute(Qt::WA_DeleteOnClose);
 

+ 3 - 2
ExpertClient/EXDataViewDelegate.cpp

@@ -13,14 +13,15 @@ SchemeBar::SchemeBar(const QString &lLabel, const QString &rLabel, const QString
 {
     setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
     QHBoxLayout *hlay = new QHBoxLayout;
-    QLabel *l         = new QLabel(leftLabel);
-    QLabel *r         = new QLabel(rightLabel);
+    QLabel *l         = new QLabel(leftLabel.trimmed());
+    QLabel *r         = new QLabel(rightLabel.trimmed());
 
     QHBoxLayout *centerLay = new QHBoxLayout;
     QButtonGroup *btnGroup = new QButtonGroup(this);
 
     for (QString &v : barValueList) {
         QPushButton *btn = new QPushButton(v);
+        btn->setMaximumWidth(30);
         centerLay->addWidget(btn);
         btnGroup->addButton(btn);
         if (v.startsWith("1/")) {

+ 23 - 0
QFD/CCanvas/CMind.cpp

@@ -262,3 +262,26 @@ QList<CNodeData> CMind::leaves() const
 {
     return leavesOfNode(root());
 }
+
+void CMind::getSeqNodes(QList<QList<SeqNode>> &seqNodes) const
+{
+    for (int i = 1; i < this->levels(); ++i) {
+        seqNodes << QList<SeqNode>();
+    }
+
+    QMap<QString, QStringList> all;
+    for (int i = 1; i < this->levels(); i++) {
+        QList<CNodeData> nodes = this->nodesInLevel(i);
+
+        for (const CNodeData &node : nodes) {
+            QList<CNodeData> subNodes = this->subNodes(node);
+            SeqNode snode;
+            snode.name = node.name.trimmed();
+            for (const CNodeData &sub : subNodes) {
+
+                snode.childs.append(sub.name.trimmed());
+            }
+            seqNodes[i - 1].append(snode);
+        }
+    }
+}

+ 8 - 0
QFD/CCanvas/CMind.h

@@ -5,6 +5,12 @@
 
 #include <QObject>
 
+struct SeqNode
+{
+    QString name;
+    QStringList childs;
+};
+
 class CMind : public QObject
 {
     Q_OBJECT
@@ -62,6 +68,8 @@ public:
     // 脑图的叶子节点列表
     QList<CNodeData> leaves() const;
 
+    void getSeqNodes(QList<QList<SeqNode>> &seqNodes) const;  // 序列所有节点
+
 signals:
     void sigRemoveNode(int id);
 

+ 5 - 4
QFD/algorithm/AverageMethod.h

@@ -2,6 +2,7 @@
 #define AVERAGEMETHOD_H
 #include <QString>
 #include <QVector>
+
 /**
  * @brief 平均值法
  */
@@ -10,13 +11,13 @@ class AverageMethod
 public:
     enum MethodType
     {
-        Max = 0,  //最大值
-        Min,      //最小值
+        Max = 0,  // 最大值
+        Min,      // 最小值
         ZScore    // Z—Score
     };
 
-    typedef QVector<qreal> EvaluateIndex;  //评估指标
-    typedef QVector<qreal> Relations;      //联系度
+    typedef QVector<qreal> EvaluateIndex;  // 评估指标
+    typedef QVector<qreal> Relations;      // 联系度
 
     /**
      * @brief 平均值法构造函数

+ 1 - 1
QFD/algorithm/ConsistencyCheck.h

@@ -5,7 +5,7 @@
 #include <QVector>
 
 /**
- * @brief 专家输入数据校验, AHP
+ * @brief 专家输入数据校验, AHP,废弃
  */
 class ConsistencyCheck
 {

+ 23 - 0
QFD/algorithm/EntropyWeights.cpp

@@ -7,6 +7,29 @@
 #include <numeric>
 #include <cmath>
 
+/**
+    QVector<QVector<double>> pdata = { { 4.1, 3.9, 5.9, 4.9, 4,   6.1, 8.2,  6.5,  7.5,  6.8,
+                                         7.4, 5.7, 2.4, 2.2, 1.9, 1.8, 15.9, 18.9, 18.8, 16.8 },
+                                       { 0.04, 0.08, 0.07, 0.23, 0.14, 0.23, 0.21, 0.13, 0.16, 0.04,
+                                         0.05, 0.08, 0.14, 0.24, 0.11, 0.06, 0.2,  0.09, 0.12, 0.27 },
+                                       { 0.19, 0.38, 0.23, 1.03, 0.57, 1.19, 0.88, 0.8,  1.28, 0.17,
+                                         0.33, 0.6,  0.23, 0.35, 0.3,  0.28, 1.05, 0.82, 0.8,  1.74 },
+                                       { 0.01, 0.18, 0.04, 0.3,  0.11, 0.47, 0.2,  0.26, 0.88, 0.02,
+                                         0.06, 0.47, 0.04, 0.06, 0.1,  0.1,  0.21, 0.34, 0.39, 1.51 },
+                                       { 0.36, 0.19, 0.36, 1.4,  1.12, 0.93, 0.97, 0.52, 0.8,  0.24,
+                                         0.39, 0.46, 0.94, 1.78, 0.5,  0.29, 1.84, 0.58, 0.76, 1.78 },
+                                       { 0.05, 0.04, 0.07, 0.09, 0.05, 0.07, 0.1,  0.09, 0.12, 0.11,
+                                         0.1,  0.08, 0.02, 0.02, 0.04, 0.03, 0.12, 0.36, 0.26, 0.32 } };
+
+    EntropyWeights ew(pdata);
+
+    QVector<double> weights;
+    QVector<double> score;
+    ew.compute(weights, score);
+    qDebug() << score;
+    qDebug() << weights;
+ */
+
 EntropyWeights::EntropyWeights(const EntropyMat &mat, const QVector<bool> &direction)
     : ymin_(0.002), ymax_(0.996), mat_(mat), direction_(direction)
 {

+ 3 - 0
QFD/algorithm/EntropyWeights.h

@@ -9,6 +9,9 @@
 
 typedef QVector<QVector<double>> EntropyMat;
 
+/**
+ * @brief 熵权法
+ */
 class EntropyWeights
 {
 public:

+ 17 - 11
QFD/algorithm/GreyClusterEvaluation.h

@@ -1,4 +1,4 @@
-//
+//
 // Created by lenovo on 2023/10/16.
 //
 
@@ -7,26 +7,33 @@
 
 #include <QVector>
 
-struct GCERange {
-    int level;//等级
+struct GCERange
+{
+    int level;  // 等级
     double left_left;
     double left_val;
     double right_val;
     double right_right;
 };
-struct GCEmat {
+struct GCEmat
+{
     double front_val;
     double back_val;
 };
-struct BestIndex {
+struct BestIndex
+{
     int front_index;
     int back_index;
 };
 
 typedef QVector<GCEmat> GCEMat;
-typedef QVector<QVector<GCERange> > GCERangeMat;
+typedef QVector<QVector<GCERange>> GCERangeMat;
 
-class GreyClusterEvaluation {
+/**
+ * @brief 灰色聚类
+ */
+class GreyClusterEvaluation
+{
 public:
     /**
      *
@@ -39,8 +46,8 @@ public:
 
     BestIndex getBestIndex() const;
 
-    int sample_num_; //样本数
-    int level_num_;//等级数
+    int sample_num_;  // 样本数
+    int level_num_;   // 等级数
 
 private:
     void triangularwhiteningweight(int sam, double front_val, double back_val);
@@ -53,5 +60,4 @@ private:
     QVector<GCEmat> ranges_weight_;
 };
 
-
-#endif //ALGORITHM_GREYCLUSTEREVALUATION_H
+#endif  // ALGORITHM_GREYCLUSTEREVALUATION_H

+ 1 - 1
QFD/algorithm/HierarchicalAnalysis.h

@@ -5,7 +5,7 @@
 #include <QVector>
 
 /**
- * @brief AHP
+ * @brief AHP层次分析法
  */
 class HierarchicalAnalysis
 {

+ 22 - 26
QFD/algorithm/HierarchyWeighting.h

@@ -1,4 +1,4 @@
-//
+//
 // Created by lenovo on 2023/10/18.
 //
 
@@ -10,8 +10,8 @@
 #include <QDebug>
 #include <QtMath>
 
-typedef QVector<QVector<qreal> > HWMat;
-typedef QVector<QVector<qreal> > SMat;
+typedef QVector<QVector<qreal>> HWMat;
+typedef QVector<QVector<qreal>> SMat;
 
 struct HWWeight
 {
@@ -23,47 +23,43 @@ struct HWWeight
 
 struct HWNode
 {
-    QString node; // 1.1 , 1.1.1
+    QString node;  // 1.1 , 1.1.1
     QString name;
     HWMat mat;
-    QVector<int> node_number; // [1, 1] , [1, 1, 1]
+    QVector<int> node_number;  // [1, 1] , [1, 1, 1]
 };
 
+/**
+ * @brief 层次加权法
+ */
 class HierarchyWeighting
 {
 public:
-    HierarchyWeighting(const SMat& smat); //
+    HierarchyWeighting(const SMat &smat);  //
     void evaluate();
 
-    void push(const QString& node, const QString& name, const HWMat& value);
+    void push(const QString &node, const QString &name, const HWMat &value);
     bool isFull() const;
-    const QVector<double>& getsampleweight() const
-    {
-        return smat_cv_;
-    }
-    int getBestIndex() const
-    {
-        return best_index_;
-    }
+    const QVector<double> &getsampleweight() const { return smat_cv_; }
+    int getBestIndex() const { return best_index_; }
 
 private:
-    void EvaluateNodeWeight(const HWNode& hwnode);
+    void EvaluateNodeWeight(const HWNode &hwnode);
     void LastLevelWeight();
     void BestSample();
 
-    const qreal RI[10]
-        = {0, 0, 0.58, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45, 1.49};
-    const qreal thd = 0.1;
+    const qreal RI[10] = { 0, 0, 0.58, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45, 1.49 };
+    const qreal thd    = 0.1;
     qreal m_CI;
     qreal m_CR;
 
-    QVector<HWNode> mat_;            //各节点
-    QVector<HWWeight> weights_node_; //各节点计算出的权重
-    SMat smat_;                      //样本
-    int sam_num_;                    //样本数量
-    int best_index_;                 //最好的样本索引
+    QVector<HWNode> mat_;             // 各节点
+    QVector<HWWeight> weights_node_;  // 各节点计算出的权重
+    SMat smat_;                       // 样本
+    int sam_num_;                     // 样本数量
+    int best_index_;                  // 最好的样本索引
     QVector<double> smat_cv_;
-    QVector<double> weights_; //最后一层综合权重
+    QVector<double> weights_;  // 最后一层综合权重
 };
 
-#endif //ALGORITHM_HIERARCHYWEIGHTING_H
+#endif  // ALGORITHM_HIERARCHYWEIGHTING_H

+ 14 - 9
QFD/algorithm/MatterElementAnalysis.h

@@ -1,4 +1,4 @@
-//
+//
 // Created by Austin on 2023/10/11.
 //
 
@@ -7,16 +7,21 @@
 
 #include <QVector>
 
-struct MEARange {
-    int index; //指标号
+struct MEARange
+{
+    int index;  // 指标号
     double min_value;
     double max_value;
 };
 
-typedef QVector<QVector<double> > MEAMat;
-typedef QVector<QVector<MEARange> > MEARangeMat;
+typedef QVector<QVector<double>> MEAMat;
+typedef QVector<QVector<MEARange>> MEARangeMat;
 
-class MatterElementAnalysis {
+/**
+ * @brief 物元法
+ */
+class MatterElementAnalysis
+{
 public:
     /**
      *
@@ -31,8 +36,8 @@ public:
 
     QVector<int> getBestIndex() const;
 
-    int sample_num_; //样本数
-    int index_num_;  //指标数
+    int sample_num_;  // 样本数
+    int index_num_;   // 指标数
 
 private:
     void associatedValue(int sam, int index, double value);
@@ -45,4 +50,4 @@ private:
     MEAMat range_weights_;
 };
 
-#endif //ALGORITHM__MATTERELEMENTANALYSIS_H_
+#endif  // ALGORITHM__MATTERELEMENTANALYSIS_H_

+ 9 - 8
QFD/algorithm/SetPairAnalysis.h

@@ -1,4 +1,4 @@
-//
+//
 // Created by lenovo on 2023/10/18.
 //
 
@@ -8,6 +8,10 @@
 #include "QString"
 #include "QVector"
 
+typedef QVector<qreal> EvaluateIndex;  // 评估指标
+typedef QVector<qreal> Relations;      // 联系度
+typedef QStringList EvaluateNames;
+
 /**
  * @brief 集对分析法,SPA,又称同异反综合分析法
  * 集成析是从系统的角度去认识确定性和不确定性的关系,并确定研究对象是一个确定不确定系统,
@@ -17,13 +21,10 @@
  * c:P/N 相反属性联系度(对立度)
  * 集对联系度公式:u = a + b*i + c*j
  */
-typedef QVector<qreal> EvaluateIndex;  //评估指标
-typedef QVector<qreal> Relations;      //联系度
-typedef QStringList EvaluateNames;
-
-class SetPairAnalysis {
+class SetPairAnalysis
+{
 public:
-    //评估对象
+    // 评估对象
     /**
      * @brief 集对分析法构造函数
      * @param rMat 同异反评估矩阵
@@ -51,4 +52,4 @@ private:
     EvaluateNames m_evalNames;
 };
 
-#endif //ALGORITHM_SETPAIRANALYSIS_H
+#endif  // ALGORITHM_SETPAIRANALYSIS_H