private string GenerateReport() { StringBuilder ReportStr = new StringBuilder(); string[,] currentMatrix; double[] WeightVector; MatrixOperater matrixOperater = new MatrixOperater(); Hashtable AllFactorWeights = new Hashtable(); //存储所有的权重 System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); //新建计时停表 stopwatch.Restart(); if (checkMarix(ShowResultOrNot: false) == true) { ReportStr.Append("Matrix check pass.\r\n\r\n"); for (int MatrixIndex = 1; MatrixIndex < MatrixList.Count; MatrixIndex++) { currentMatrix = (string[, ])MatrixList[MatrixIndex]; //输出该层因素 ReportStr.Append(" "); //左上角表格留空 for (int i = 0; i < currentMatrix.GetLength(0); i++) { ReportStr.Append(((TreeNodeCollection)LayerList[MatrixIndex])[i].Text + " "); } //换行 ReportStr.Append("\r\n"); //输出矩阵权重 ReportStr.Append("W" + MatrixIndex.ToString() + " "); WeightVector = matrixOperater.GetEigenvectorOfMatrix( matrixOperater.conventStringMatrixIntoNumberArray( currentMatrix ) ); for (int i = 0; i < WeightVector.Length; i++) { ReportStr.Append(Math.Round(WeightVector[i], 4).ToString() + " "); AllFactorWeights.Add(((TreeNodeCollection)LayerList[MatrixIndex])[i].Text, WeightVector[i]); //把得到的权重存起来 } //换行 ReportStr.Append("\r\n"); //输出分隔符 ReportStr.Append("------------------------------------------------\r\n"); } //输出层次总排序 ReportStr.Append("\r\nTotal sorting weights:\r\n"); Hashtable totalSortingHashtable = GetTotalSortingWeightVector(AllFactorWeights); foreach (string factor in totalSortingHashtable.Keys) { ReportStr.Append(factor + ": " + totalSortingHashtable[factor].ToString() + "\r\n"); } ReportStr.Append("------------------------------------------------\r\n"); stopwatch.Stop(); ReportStr.Append("Checking finish in " + stopwatch.Elapsed.TotalMilliseconds.ToString() + "ms.\r\n"); } else { ReportStr.Append("Matrix check not pass!"); } return(ReportStr.ToString()); }
private bool checkMarix(bool ShowResultOrNot) { StringBuilder checkResultStr = new StringBuilder(); StringBuilder MatrixNotOKPrompt = new StringBuilder(); MatrixOperater matrixOperater = new MatrixOperater(); ArrayList checkResultList; string[,] currentMatrix; bool matrixComplete = true; bool AllPass = true; System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); //新建计时停表 stopwatch.Restart(); for (int MatrixIndex = 1; MatrixIndex < MatrixList.Count; MatrixIndex++) { //显示正在检查那个数组 checkResultStr.Append("Checking " + listBoxMatrix.Items[MatrixIndex - 1].ToString() + "\r\n"); //将该数组信息输出 currentMatrix = (string[, ])MatrixList[MatrixIndex]; for (int i = 0; i < currentMatrix.GetLength(0); i++) { for (int j = 0; j < currentMatrix.GetLength(1); j++) { checkResultStr.Append(currentMatrix[i, j]); //检查是否要插入制表符 if (j < currentMatrix.GetLength(1) - 1) { checkResultStr.Append("\t"); } } checkResultStr.Append("\r\n"); } //再换一行,准备输出计算结果和判断结果 checkResultStr.Append("\r\n"); //检查数组是否已经填写完毕 if (matrixOperater.IsMatrixHasZero(currentMatrix)) { checkResultStr.Append("This matrix not complete(Zero detected)!\r\n"); matrixComplete = false; } else { //输出计算结果 checkResultList = matrixOperater.CheckMatrix( matrixOperater.conventStringMatrixIntoNumberArray( currentMatrix ) ); checkResultStr.Append("CI = " + checkResultList[0] + " CR = " + checkResultList[1] + " CR < 0.1? " + (((bool)checkResultList[2]) ? "YES" : "NO") + "\r\n"); //如果有超限数组,加入提示 if ((bool)checkResultList[2] == false) { MatrixNotOKPrompt.Append(listBoxMatrix.Items[MatrixIndex - 1].ToString() + "\r\n"); } } //输出分隔符 checkResultStr.Append("------------------------------------------------\r\n"); } //检查结束 stopwatch.Stop(); checkResultStr.Append("Checking finish in " + stopwatch.Elapsed.TotalMilliseconds.ToString() + "ms.\r\n"); //输出检查结果 if (MatrixNotOKPrompt.ToString().Equals("") && matrixComplete) { //如果没有不OK的矩阵 checkResultStr.Append("Congratulations, All Matrix pass the test!\r\n"); AllPass = true; } else if (matrixComplete) { checkResultStr.Append("Some matrix given in the following did not pass the test, check and retest.\r\n"); checkResultStr.Append(MatrixNotOKPrompt.ToString() + "\r\n"); AllPass = false; } else { checkResultStr.Append("Some matrix not complete, check and retest.\r\n"); AllPass = false; } if (ShowResultOrNot) { //显示结果 FormText formText = new FormText(); formText.Show(checkResultStr.ToString(), "MatrixCheckResult"); } return(AllPass); }