function AHPSolver
%code by ariszheng 2007-11-11 ariszheng@gmail.com
HierarchyNum=input('Hierarchy Num of Ahp\n');
NumOfElem=input('Number of element in every Hierarchy\n');
weightKtoTop=0;
for i=1:HierarchyNum-1
sprintf('plese input the DecMatrix of %dth Hierarchy',i)
k=0;
while true
flag=input('Do you want input DecMatrix in this Hierarchy? 1 or 0 \n');
if flag==1
k=k+1;
sprintf('plese input the %d row %d th: DecMatrix ',i,k)
sprintf('the position of 支配元素 in %d th 层 ',i)
DecMatrix(k).DecEle=input('\n');
sprintf('the position of 被支配元素 in %d 层',i+1)
DecMatrix(k).SupEle=input('\n');
DecMatrix(k).Matrix=input('DecMatirx \n');
[DecMatrix(k).Weight,DecMatrix(k).LamdaMax,DecMatrix(k).CR]=AHPWeightVector(DecMatrix(k).Matrix);
disp('the weight of this DecMatrix:');
DecMatrix(k).Weight
disp('the DecMatrix.LamdaMax:');
DecMatrix(k).LamdaMax
disp('DecMatrix.CR:');
DecMatrix(k).CR
else
disp('this DecMatrix in this Hierarchy Input over');
break;
end
end
if i==1;
weightKtoTop=DecMatrix(1).Weight;
CR=DecMatrix(1).CR;
else
for j=1:k
CR=CR+weightKtoTop(j)*DecMatrix(j).CR;
end
U=zeros( NumOfElem(i+1),NumOfElem(i));
for j=1:k
U(DecMatrix(j).SupEle,j)=DecMatrix(j).Weight;
end
weightKtoTop=U*weightKtoTop;
end
sprintf('the weight of %d Hierarchy element is',i+1);
weightKtoTop
end
end