EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
这个是只是用行变换将非严格占优矩阵通过行变换转换为严格占有矩阵。 伪代码如下: Input matrix:A Output: If A can transform into a dominance with our method,we can get the dominance. Else output’Cannot transform the matrix into dominance’ Variable: Set a matrix record with the size [row_of_matrix,3] Record[row_length_matrix,3] %This matrix is for record A’s situation. % Record[1:,1] first volumn stands for this row of A should be put which row % Record[1:,2] second volumn stands for whether this row satisfy the necessity of transform into a dominance.If yes,set 1;otherwise 0. % Record[1:,3] third volumn stands for which initial row belong to. Flag% this variable is to record whether the matrix A can transform into a dominance. % If yes,Flag = 1; % otherwise Flag = 0 % beneath code is to test whether the matrix can transform into a dominance % and record the situation of every row. for i = 1:size_of_matrix Test every row(Record); If test_row’s Record[1:,2] == 0 then break and output ’Cannot transform the matrix into dominance’ Flag = 0; end end % If Flag = 1,we use row exchangement to transform A into dominance If Flag = 1 Row_exchangment by record. for i = 1:row-1 for j = 1:row if record(j,1) == i %exchange line if flag = 1,which %means it can be transformed into dominance exchange A(i,:) and A(record(j,3),:); exchange record(j,:) and record(i,:); break; end end end Display A; end 具体实现代码如下: % Project 1
' w6 o5 V+ F" m. I' j% SMIE name:ChenYu class:1202 nunmber:12353032
! c' n9 R4 p! U/ e. h9 ^) h% Change nondorminant to dorminant matrix
7 m) E5 F2 \/ j8 G7 M) {% this method is adapted for the matrix which can be changed to dorminant
1 I) j& W# d! ~: g0 D5 y$ C% matrix only using row exchangement
/ F& T/ K/ K' i+ I0 q1 G% Input :A matrix
3 X! M7 q$ l* C7 k% Output:A matrix which maybe dorminant
) `5 D, |* u. C. N9 P- pfunction method1(A)
/ X5 }9 w. _9 ]4 B3 y/ E[row,volumn] = size(A);% U- z5 e! A3 c1 J- x
record = ones(volumn,3); %use this matrix to record everyline situation
s; o) T$ x' Q7 O' d8 o2 G5 bflag = 1; %first volumn record if the matrix can change to" w6 S) A; m& s( k! j U4 D0 Z+ l6 `
for i = 1:row %dominance,which row the row will �long.Second volumn record
" v* t/ w5 k4 T9 F9 q6 g* N7 j every_line = A(i,:); %whether the matrix satisfy the necessity %that everydominance9 {8 |* P) B3 }. r- ~7 e
record(i,3) = i; %third volumn record the rowth
2 Q% c; [) e) U8 Y- E [record(i,1),record(i,2)] = which_row(every_line);
5 G: y; l* Y6 J& { E1 s if record(i,2) == 0
+ [' R6 c# ?* V3 j% n; m: C disp('This Matrix cannot change to dorminant matrix by row exchange.');& k! ^% y; L/ O( P, {7 o
flag = 0;, h3 i0 _/ U9 E9 T. F: q) l- `& U% k
break;
+ T3 z0 a+ i9 Y$ e end/ v1 m) }, W ]: l( e4 S B/ r
end! z0 Z& G2 B! d1 ^3 w
if flag == 1
) n3 K6 H t0 }) W5 i$ R3 p" S" s for i = 1:row-1
) ^7 Y( x( `$ ] j* X for j = 1:row
/ H- D8 S" h+ M6 L1 N if record(j,1) == i %exchange line if flag = 1,which means it can be transformed
" e$ T; }' I/ v J* T. L4 ^+ ]1 q b = A(i,:); %into dorminance
1 {; a1 z( Q x3 t8 W, v; C1 a A(i,:) = A(record(j,3),:);
! L7 e3 I V8 ]! A A(record(j,3),:) = b;- O' O' i! @& M* B S3 G; H
temp = record(j,:);
: b. D6 ~! C( n record(j,:) = record(i,:);) H* n n6 _+ J/ L" A* O
record(i,:) = temp;0 T9 f, [6 y/ S. Z
break;
: c( M i# p+ \6 _' A end/ {3 P1 N4 ?# F/ Q) F
end; x% U4 n# t3 l" v( J
end
% b+ `: m! J" n3 r- r( d disp(A);' |* g1 T9 S$ b1 C$ M9 P- ?- p$ R
end 调用函数: % function judge_row:
; ~ ^" B; o( W. o# L( J% this function is to judge whether the line is a line of dorminance and5 ?# D" c. v! O# R! I, r, k
% return which row shuold this line stand# D2 l' o8 B8 B3 v, p+ P
% Input : vector(a row of the matrix). d7 v# d9 M$ n5 M
% Output:if(the line is dorminant) return flag = 1;
2 F% @( A' l0 b3 k' g% else return flag = 0.+ k& q: R: |; L# W9 t# h' e `6 E, z
function [row,flag] = which_row(a)1 m2 Y0 T9 A% f2 P
n = length(a);7 n' |; z% [3 }4 u
max = a(1);
5 h- v: E" K# J* R. Tflag = 0;: x( ~* l2 M4 ?; I8 Q6 O4 O, [' s
row = 1;7 @4 |5 P/ c( y
for i = 2:n0 k+ D) i+ k; {) K
if max < a(i) %fing the max value of the line
! w0 F- p, r g8 _. ~ max = a(i); %it's easy for us to know that if the max value is* K% v3 b& f* B4 U
row = i; %larger than the rest of all sum
4 m" h6 r% e& N# U2 ^( J' B7 l end %than the line is dorminance
9 i$ C1 r2 {. W2 g5 Pend( Z! c6 j% }1 {7 Z, P, ]' i; k
and = 0;
$ Y! T! _7 L8 Q; `6 H3 y8 ~' Dfor i = 1:n
5 P# [- B) N$ R3 C if i ~= row %compare maxvalue and rest sum( L: ]. {6 B$ E/ C$ K% V- D
and = and + a(i);
0 g! M) S9 ?4 p) O5 G& Q end
% W$ d/ Z4 g6 {% l( U; a2 \end
" G2 J% o! D4 p! r2 nif a(row) >= and
& C# a v* {* q flag = 1;+ U3 k$ H* w$ C" K4 b) c- E
end / h* m- ^) ?6 [! {5 _( L
|