# AHP 幂法求解c# 部分代码

private void Weights() {
double[,] a = new double[3, 3];
a[0, 0] = 1.0;
a[1, 1] = 1.0;
a[2, 2] = 1.0;
a[0, 1] = 2.0;
a[0, 2] = 6.0;
a[1, 0] = 0.5;
a[1, 2] = 4.0;
a[2, 0] = 1.0 / 6;
a[2, 1] = 1.0 / 4;

//初始向量Wk
double[] w0 = new double[3];
for (int i = 0; i < 3; i++) {
w0[i] = 1.0 / 3;
}

//一般向量W（k+1）

double[] w1 = new double[3];

//W（k+1）的归一化向量

double[] w2 = new double[3];

double sum = 1.0;

double d = 1.0;

double delt = 0.00001;

while (d > delt) {

d=0.0;

sum = 0;

//获取向量

for (int j = 0; j < 3; j++) {

w1[j] = a[j, 0] * w0[0] + a[j, 1] * w0[1] + a[j, 2] * w0[2];
sum += w1[j];
}

//向量归一化
for (int k = 0; k < 3; k++) {
w2[k] = w1[k] / sum;
d = Math.Max(Math.Abs(w2[k] - w0[k]), d);//最大差值

w0[k] = w2[k];//用于下次迭代使用
}
}

string s = "W1(";
string s1 = "W2(";
double lamta = 0.0;
for (int k = 0; k < 3; k++) {
lamta+=w1[k]/(3*w0[k]);
s += String.Format("{0},", w1[k]);
s1 += String.Format("{0},", w2[k]);
}
double CI = (lamta - 3) / 2;
double CR = CI / 0.58;
Response.Write(String.Format("lamta:{0}
CI:{1}
CR:{2}
{3}){4})",lamta, CI, CR, s.Substring(0, s.Length - 1), s1.Substring(0, s1.Length - 1)));

}

• 博文量
69
• 访问量
102144