Forráskód Böngészése

更新物元法算法

Signed-off-by: codeClown <zhaomengshou@126.com>
codeClown 1 hete
szülő
commit
cabf41b557

+ 44 - 16
QFD/algorithm/MatterElementAnalysis.cpp

@@ -39,30 +39,58 @@ void MatterElementAnalysis::evaluate(const QVector<double> &weights)
     evaluationlevel(weights);
 }
 
-void MatterElementAnalysis::associatedValue(int sam, int index, double value)
+static double correlationP(double value, double left, double right)
 {
-    auto pFunc = [](double v, double left, double right) {
-        return std::abs(v - (left + right) / 2) - (right - left) / 2;
-    };
+    return std::abs(value - (left + right) / 2) - (right - left) / 2;
+}
+
+static bool containValue(double value, bool left_close, bool right_close, double left, double right)
+{
+    if (value > left && value < right)
+        return true;
+
+    if (value == left && left_close)
+        return true;
+
+    if (value == right && right_close)
+        return true;
+
+    return false;
+}
 
+void MatterElementAnalysis::associatedValue(int sam, int index, double value)
+{
     double r = 0;
-    for (int i = 0; i < ranges_.count() - 1; ++i)  // i是等级,index是指标
+    for (int i = 0; i < ranges_.count() - 1; ++i) //i是等级,index是指标
     {
-        //        Q_ASSERT(ranges_.at(i).at(index).index == index);
+        Q_ASSERT(ranges_.at(i).at(index).index == index);
         double minValue = ranges_.at(i).at(index).min_value;
         double maxValue = ranges_.at(i).at(index).max_value;
-        double minend   = ranges_.last().at(index).min_value;
-        double maxend   = ranges_.last().at(index).max_value;
-        double r1       = pFunc(value, minValue, maxValue);
-        double r2       = pFunc(value, minend, maxend);
-
-        if (abs(r1 - r2) <= 0.00000001) {
-            r = -r1 - 1;
-        } else {
-            r = r1 / (r2 - r1);
+        bool leftValueClose = ranges_.at(i).at(index).left_close;
+        bool rightValueClose = ranges_.at(i).at(index).right_close;
+        double r1 = correlationP(value, minValue, maxValue);
+
+        if (containValue(value, leftValueClose, rightValueClose, minValue, maxValue))
+        {
+            r = -r1 / abs(maxValue - minValue);
         }
+        else
+        {
+            double minEnd = ranges_.last().at(index).min_value;
+            double maxEnd = ranges_.last().at(index).max_value;
+            double r2 = correlationP(value, minEnd, maxEnd);
+            if (abs(r1 - r2) <= 0.00000001)
+            {
+                r = -r1 - 1;
+            }
+            else
+            {
+                r = r1 / (r2 - r1);
+            }
+        }
+
         range_cvt_[sam][index][i] = r;
-        // 结果放在range_cvt_
+        //结果放在range_cvt_
     }
 }
 

+ 3 - 1
QFD/algorithm/MatterElementAnalysis.h

@@ -9,7 +9,9 @@
 
 struct MEARange
 {
-    int index;  // 指标号
+    int index;        //指标号
+    bool left_close;  //左闭合
+    bool right_close; //右闭合
     double min_value;
     double max_value;
 };