Skip to content

Commit 65c18c1

Browse files
authored
Add files via upload
1 parent 29e6f04 commit 65c18c1

7 files changed

Lines changed: 189 additions & 0 deletions

File tree

AHP_analysis.mlx

5.24 KB
Binary file not shown.

Min2Max.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function [posit_x] = Min2Max(x)
2+
posit_x = max(x) - x;
3+
%posit_x = 1 ./ x; %如果x全部都大于0,也可以这样正向化
4+
end

Positivization.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
% function [输出变量] = 函数名称(输入变量)
2+
% 函数的中间部分都是函数体
3+
% 函数的最后要用end结尾
4+
% 输出变量和输入变量可以有多个,用逗号隔开
5+
% function [a,b,c]=test(d,e,f)
6+
% a=d+e;
7+
% b=e+f;
8+
% c=f+d;
9+
% end
10+
% 自定义的函数要单独放在一个m文件中,不可以直接放在主函数里面(和其他大多数语言不同)
11+
12+
13+
14+
function [posit_x] = Positivization(x,type,i)
15+
% 输入变量有三个:
16+
% x:需要正向化处理的指标对应的原始列向量
17+
% type: 指标的类型(1:极小型, 2:中间型, 3:区间型)
18+
% i: 正在处理的是原始矩阵中的哪一列
19+
% 输出变量posit_x表示:正向化后的列向量
20+
if type == 1 %极小型
21+
disp(['' num2str(i) '列是极小型,正在正向化'] )
22+
posit_x = Min2Max(x); %调用Min2Max函数来正向化
23+
disp(['' num2str(i) '列极小型正向化处理完成'] )
24+
disp('~~~~~~~~~~~~~~~~~~~~分界线~~~~~~~~~~~~~~~~~~~~')
25+
elseif type == 2 %中间型
26+
disp(['' num2str(i) '列是中间型'] )
27+
best = input('请输入最佳的那一个值: ');
28+
posit_x = Mid2Max(x,best);
29+
disp(['' num2str(i) '列中间型正向化处理完成'] )
30+
disp('~~~~~~~~~~~~~~~~~~~~分界线~~~~~~~~~~~~~~~~~~~~')
31+
elseif type == 3 %区间型
32+
disp(['' num2str(i) '列是区间型'] )
33+
a = input('请输入区间的下界: ');
34+
b = input('请输入区间的上界: ');
35+
posit_x = Inter2Max(x,a,b);
36+
disp(['' num2str(i) '列区间型正向化处理完成'] )
37+
disp('~~~~~~~~~~~~~~~~~~~~分界线~~~~~~~~~~~~~~~~~~~~')
38+
else
39+
disp('没有这种类型的指标,请检查Type向量中是否有除了1、2、3之外的其他值')
40+
end
41+
end
42+

basic_fengxian_level.mlx

4.09 KB
Binary file not shown.

scenario_divided.m

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
clear all
2+
clc
3+
4+
% 下面这个矩阵是6个方案(行数),每个方案6个指标(列数)
5+
ganrao=[3.5 2.666666667
6+
3.416666667 2.583333333
7+
3.166666667 2.416666667
8+
3.666666667 2.75
9+
3.083333333 2.166666667
10+
4 2.416666667
11+
4.25 2.75
12+
4.333333333 3.166666667
13+
3.25 3
14+
3.166666667 2.333333333
15+
2.75 1.916666667
16+
2.333333333 1.5
17+
2.583333333 3.333333333
18+
3.833333333 3.083333333
19+
3.583333333 2.416666667
20+
3.166666667 2.166666667
21+
3.416666667 2.5
22+
2.75 2.75
23+
2.5 2.916666667
24+
2.666666667 2.833333333
25+
4.583333333 3.416666667
26+
3.5 2.583333333
27+
3.25 1.5
28+
2.916666667 1.666666667
29+
3 1.5
30+
3.333333333 1.75
31+
3.416666667 2.166666667
32+
2.333333333 2.916666667
33+
3.083333333 2.333333333
34+
3.5 1.666666667
35+
3.5 3.333333333
36+
2.833333333 2.583333333
37+
3 2.583333333
38+
4.833333333 2.083333333
39+
3.75 2.75
40+
4 2.25
41+
4 2.333333333]
42+
43+
44+
[rows,cols]=size(ganrao); % 输入矩阵的大小,rows为对象个数,cols为指标个数
45+
k=1/log(rows); % 求k
46+
47+
48+
%求比重
49+
% sigma1=sum(ganrao(:,1));
50+
% sigma2=sum(ganrao(:,2));
51+
%
52+
% PIJ=zeros(rows,cols);
53+
%
54+
% for I=1:cols
55+
% sigmaI=sum(ganrao(:,i));
56+
% for J=1:rows
57+
% PIJ(J,I)= ganrao(J,I)/sigmaI;
58+
% end
59+
% end
60+
61+
62+
y = ganrao;
63+
64+
%2 求Y(i,j)
65+
MAX=max(y);
66+
MIN=min(y);
67+
Y = zeros(rows,cols);
68+
for J=1:cols
69+
for I=1:rows
70+
Y(I,J)= (y(I,J)-MIN(J))/(MAX(J)-MIN(J));
71+
end
72+
end
73+
%% 数据预处理_标准化
74+
Z = Y ./ repmat(sum(Y.*Y) .^ 0.5, rows, 1);
75+
disp('标准化矩阵 Z = ')
76+
disp(Z)
77+
%z1=sum(Z,1);
78+
79+
%% 指标权重赋值
80+
disp("请输入是否需要增加权重向量,需要输入1,不需要输入0")
81+
ahp_w1=[0.2
82+
0.2
83+
0.2
84+
0.2
85+
0.2
86+
0.2
87+
0.08
88+
0.08
89+
0.08
90+
0.08
91+
0.08
92+
0.08
93+
0.08
94+
0.08
95+
0.08
96+
0.08
97+
0.08
98+
0.08
99+
0.08
100+
0.08
101+
0.08
102+
0.08
103+
0.05
104+
0.05
105+
0.05
106+
0.05
107+
0.05
108+
0.33
109+
0.33
110+
0.33
111+
0.33
112+
0.33
113+
0.33
114+
0.33
115+
0.33
116+
0.33
117+
0.33];
118+
ahp_w=ahp_w1(:,1)/sum(ahp_w1,1);
119+
Judge = input('请输入是否需要增加权重: ');
120+
if Judge == 1
121+
disp(['有多少个指标就输入多少个权重数(权重和为1),如[0.25,0.25,0.5]']);
122+
weigh = input(['请输入' num2str(cols) '个权重: ']);
123+
if abs(sum(weigh) - 1)<0.000001 && size(weigh,1) == 1 && size(weigh,2) == cols % 这里要注意浮点数的运算是不精准的。
124+
else
125+
weigh = input('你输入的有误,请重新输入权重行向量: ');
126+
end
127+
else
128+
weigh = ones(1,cols) ./ cols ; %如果不需要加权重就默认权重都相同,即都为1/cols(列数的倒数)
129+
end
130+
% 计算与最大值的距离和最小值的距离,并算出得分
131+
D_P = sum(((Z - repmat(max(Z),rows,1)) .^ 2 ) .* repmat(weigh,rows,1) ,2) .^ 0.5; % D+ 与最大值的距离向量
132+
D_N = sum(((Z - repmat(min(Z),rows,1)) .^ 2 ) .* repmat(weigh,rows,1) ,2) .^ 0.5; % D- 与最小值的距离向量
133+
% D_P1=ahp_w.*D_P;
134+
% D_N1=ahp_w.*D_N;1
135+
S = D_N ./ (D_P+D_N); % 未归一化的得分
136+
disp('最后的得分为:')
137+
%stand_S = D_N1/sum(D_N1)
138+
S_final=ahp_w.*S;
139+
stand_S = S_final / sum(S_final)% 归一化的得分
140+
[sorted_S,index] = sort(stand_S ,'descend')%对得分进行降序排序并返回原来的位置
141+
142+
% o=repmat(max(Z),rows,1);
143+

sq.mlx

5.73 KB
Binary file not shown.

topsis.mlx

7.51 KB
Binary file not shown.

0 commit comments

Comments
 (0)