test_main.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #include <QCoreApplication>
  2. #include <QDebug>
  3. #include "EntropyWeights.h"
  4. #include "MatterElementAnalysis.h"
  5. #include "GreyClusterEvaluation.h"
  6. #include "SetPairAnalysis.h"
  7. #include "HierarchicalAnalysis.h"
  8. #include "HierarchyWeighting.h"
  9. void testHW()
  10. {
  11. SMat sam_mat = {
  12. {
  13. 1,
  14. 2,
  15. 3,
  16. 4,
  17. 5,
  18. 6,
  19. 7,
  20. 8,
  21. 9,
  22. 10,
  23. 11,
  24. 12,
  25. 13,
  26. 14,
  27. 15,
  28. 16,
  29. 17,
  30. },
  31. {
  32. 1,
  33. 16,
  34. 3,
  35. 4,
  36. 5,
  37. 6,
  38. 10,
  39. 8,
  40. 9,
  41. 7,
  42. 11,
  43. 12,
  44. 13,
  45. 14,
  46. 15,
  47. 2,
  48. 17,
  49. },
  50. };
  51. HierarchyWeighting hw(sam_mat);
  52. HWMat mat = { { 1 } };
  53. HWMat mat1 = { {
  54. 1.0,
  55. 2.0,
  56. },
  57. { 1.0 / 2.0, 1.0 } };
  58. HWMat mat2 = { {
  59. 1.0,
  60. 2.0,
  61. 3.0,
  62. },
  63. { 1.0 / 2.0, 1.0, 2.0 },
  64. { 1.0 / 3.0, 1.0 / 2.0, 1.0 } };
  65. HWMat mat3 = {
  66. {
  67. 1.0,
  68. 2.0,
  69. 2.0,
  70. 3.0,
  71. 3.0,
  72. },
  73. { 1.0 / 2.0, 1.0, 2.0, 2.0, 3.0 },
  74. { 1.0 / 2.0, 1.0 / 2.0, 1.0, 2.0, 2.0 },
  75. { 1.0 / 3.0, 1.0 / 2.0, 1.0 / 2.0, 1.0, 2.0 },
  76. { 1.0 / 3.0, 1.0 / 3.0, 1.0 / 2.0, 1.0 / 2.0, 1.0 },
  77. };
  78. hw.push("1", "临床", mat1);
  79. hw.push("1.1", "医疗", mat1);
  80. hw.push("1.2", "管理", mat2);
  81. hw.push("1.1.1", "医疗质量", mat3);
  82. hw.push("1.1.2", "护理质量", mat3);
  83. hw.push("1.2.1", "经济管理", mat);
  84. hw.push("1.2.2", "行政管理", mat2);
  85. hw.push("1.2.3", "精神文明", mat2);
  86. qDebug() << hw.isFull();
  87. hw.evaluate();
  88. int best = hw.getBestIndex();
  89. // qDebug() << best;
  90. }
  91. void testHA()
  92. {
  93. QStringList ll = { "展开时间", "撤收时间", "携行重量", "操作人数", "防护能力", "保密能力" };
  94. QVector<qreal> nn = { 1, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 3.0, 3, 1, 1.0 / 3.0,
  95. 3, 1.0 / 5.0, 1.0 / 3.0, 5, 3, 1, 5, 3, 3,
  96. 3, 1.0 / 3.0, 1.0 / 5.0, 1, 1.0 / 7.0, 1.0 / 3.0, 5, 5, 1.0 / 3.0,
  97. 7, 1, 3, 3, 3, 1.0 / 3.0, 3, 1.0 / 3.0, 1 };
  98. HierarchicalAnalysis cc(ll.size(), nn);
  99. qDebug() << cc.consitst();
  100. QVector<qreal> m_weights = cc.getWeights();
  101. qDebug() << m_weights;
  102. }
  103. void testSPA()
  104. {
  105. QVector<EvaluateIndex> rmat;
  106. #ifdef cxn
  107. // 指标1
  108. rmat << QVector<double> {
  109. 2.5, 3.0, 3.5, 4.0, 3.5,
  110. };
  111. // 指标2
  112. rmat << QVector<double> {
  113. 66, 79, 85, 98, 83,
  114. };
  115. // 指标3
  116. rmat << QVector<double> {
  117. 80, 77, 90, 92, 88,
  118. };
  119. // 指标4
  120. rmat << QVector<double>
  121. {
  122. 800, 810, 900, 920, 780,
  123. #else
  124. // 样本1
  125. rmat << QVector<double> {
  126. 2.5,
  127. 66,
  128. 80,
  129. 800,
  130. };
  131. // 样本2
  132. rmat << QVector<double> {
  133. 3.0,
  134. 79,
  135. 77,
  136. 810,
  137. };
  138. // 样本3
  139. rmat << QVector<double> {
  140. 3.5,
  141. 85,
  142. 90,
  143. 900,
  144. };
  145. // 样本4
  146. rmat << QVector<double> {
  147. 4.0,
  148. 98,
  149. 92,
  150. 920,
  151. };
  152. // 样本4
  153. rmat << QVector<double> {
  154. 3.5,
  155. 83,
  156. 88,
  157. 780,
  158. };
  159. #endif
  160. // 权重
  161. QVector<qreal> wmat = { 0.3, 0.5, 0.15, 0.05 };
  162. // 同异反系数矩阵
  163. QVector<qreal> eMat = { 1, 1, 1, 1, 1 };
  164. QVector<bool> dir = { false, true, false, false };
  165. SetPairAnalysis spa(rmat, wmat, eMat, dir);
  166. Relations r = spa.getRelations();
  167. qDebug() << r;
  168. };
  169. void testEntropyWeights()
  170. {
  171. EntropyMat em;
  172. #if 0
  173. //指标1
  174. em << QVector<double>{
  175. 50625,
  176. 19600,
  177. 90000,
  178. 12500,
  179. 13500,
  180. 40000,
  181. 17408,
  182. };
  183. //指标2
  184. em << QVector<double>{
  185. 23.3330000000000,
  186. 52.6670000000000,
  187. 37.3300000000000,
  188. 18,
  189. 15,
  190. 31.6000000000000,
  191. 17.0667000000000,
  192. };
  193. //指标3
  194. em << QVector<double>{
  195. 3.50000000000000,
  196. 8,
  197. 14,
  198. 11,
  199. 15,
  200. 22,
  201. 20,
  202. };
  203. #else
  204. em << QVector<double> {
  205. 0.2662, 0.3595, 0.4755, 0.8027, 0.3368, 0.5047, 0.6996, 0.5941,
  206. };
  207. em << QVector<double> {
  208. 0.5977, 0.4208, 0.2756, 0.9144, 0.4421, 0.2021, 0.1581, 0.3003,
  209. };
  210. em << QVector<double> {
  211. 0.2623, 0.1796, 0.1004, 0.0179, 0.1841, 0.0633, 0.0494, 0.1296,
  212. };
  213. #endif
  214. QVector<bool> direction = { true, true, true };
  215. EntropyWeights ew(em, direction);
  216. QVector<double> weights, score;
  217. ew.compute(weights, score);
  218. qDebug() << weights << score;
  219. }
  220. void testGCElementAnalysis()
  221. {
  222. GCEMat mat;
  223. GCERangeMat ranges;
  224. // 样本1
  225. mat << QVector<GCEmat> {
  226. { 85, 105 }, { 785, 950 }, { 0.6, 0.89 }, { 1041, 1700 }, { 47, 38 },
  227. };
  228. // 指标1
  229. ranges << QVector<GCERange> {
  230. { 0, 70, 85, 100, 115 },
  231. { 1, 85, 100, 115, 125 },
  232. { 2, 100, 115, 125, 140 },
  233. };
  234. // 指标2
  235. ranges << QVector<GCERange> {
  236. { 0, 400, 500, 650, 800 },
  237. { 1, 500, 650, 800, 1000 },
  238. { 2, 650, 800, 1000, 1100 },
  239. };
  240. // 指标3
  241. ranges << QVector<GCERange> {
  242. { 0, 0.45, 0.5, 0.65, 0.75 },
  243. { 1, 0.5, 0.65, 0.75, 0.9 },
  244. { 2, 0.65, 0.75, 0.9, 0.95 },
  245. };
  246. // 指标4
  247. ranges << QVector<GCERange> {
  248. { 0, 500, 800, 1200, 1600 },
  249. { 1, 800, 1200, 1600, 2200 },
  250. { 2, 1200, 1600, 2200, 2500 },
  251. };
  252. // 指标5
  253. ranges << QVector<GCERange> {
  254. { 0, 28, 30, 40, 50 },
  255. { 1, 30, 40, 50, 65 },
  256. { 2, 40, 50, 65, 70 },
  257. };
  258. GreyClusterEvaluation gc(mat, ranges);
  259. gc.evaluate({ 0.2, 0.15, 0.05, 0.4, 0.2 });
  260. BestIndex index = gc.getBestIndex();
  261. qDebug() << index.front_index << index.back_index;
  262. }
  263. void testMEvaluation()
  264. {
  265. MEAMat mat;
  266. MEARangeMat ranges;
  267. // 样本1
  268. mat << QVector<double> {
  269. 3.16, 5.3, 10, 3.8, 25, 0.0041, 3,
  270. };
  271. // 样本2
  272. mat << QVector<double> {
  273. 2.41, 1.8, 2.6, 5.2, 10, 0.0021, 3,
  274. };
  275. // 样本3
  276. mat << QVector<double> {
  277. 3.5, 6.4, 23, 28, 6, 0.025, 3,
  278. };
  279. // 等级1
  280. ranges << QVector<MEARange> {
  281. { 0, 1, 1.5 }, { 1, 0, 2 }, { 2, 0, 15 }, { 3, 0, 2 }, { 4, 40, 20 }, { 5, 0, 0.003 }, { 6, 0, 2 },
  282. };
  283. // 等级2
  284. ranges << QVector<MEARange> {
  285. { 0, 1.5, 2 }, { 1, 2, 4 }, { 2, 15, 25 }, { 3, 2, 5 }, { 4, 20, 10 }, { 5, 0.003, 0.005 }, { 6, 2, 4 },
  286. };
  287. // 等级3
  288. ranges << QVector<MEARange> {
  289. { 0, 2, 2.5 }, { 1, 4, 6 }, { 2, 25, 35 }, { 3, 5, 15 }, { 4, 10, 6 }, { 5, 0.005, 0.016 }, { 6, 4, 6 },
  290. };
  291. // 等级4
  292. ranges << QVector<MEARange> {
  293. { 0, 2.5, 3 }, { 1, 6, 8 }, { 2, 35, 45 }, { 3, 15, 45 }, { 4, 6, 4 }, { 5, 0.016, 0.03 }, { 6, 6, 7 },
  294. };
  295. // 等级5
  296. ranges << QVector<MEARange> {
  297. { 0, 3, 4 }, { 1, 8, 10 }, { 2, 45, 55 }, { 3, 45, 90 }, { 4, 4, 3 }, { 5, 0.03, 0.06 }, { 6, 7, 8 },
  298. };
  299. // 等级范围p
  300. ranges << QVector<MEARange> {
  301. { 0, 1, 4 }, { 1, 0, 10 }, { 2, 0, 55 }, { 3, 0, 90 }, { 4, 40, 3 }, { 5, 0, 0.06 }, { 6, 0, 8 },
  302. };
  303. // 等级
  304. MatterElementAnalysis me(mat, ranges);
  305. me.evaluate({ 0.189, 0.203, 0.052, 0.162, 0.202, 0.151, 0.041 });
  306. QVector<int> index = me.getBestIndex();
  307. qDebug() << index;
  308. }