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/ a. Q) |; K7 {; }1 @, ~( M* u
% SMIE name:ChenYu class:1202 nunmber:12353032
& f) o. Y+ ~* K% Change nondorminant to dorminant matrix8 W. x3 l; Y! r" _
% this method is adapted for the matrix which can be changed to dorminant
# e8 L: V0 N& M5 x, K6 k3 m Y% matrix only using row exchangement4 n& a- w% Y! y! U- J
% Input :A matrix
& {1 M- s% ~ r- {7 d% Output:A matrix which maybe dorminant
8 A3 Y' [1 r) A2 w9 [6 Xfunction method1(A)5 V; O% |. P i$ l3 D0 i
[row,volumn] = size(A);& c: }2 E- @$ J0 E
record = ones(volumn,3); %use this matrix to record everyline situation
6 r/ b% i- T6 `) oflag = 1; %first volumn record if the matrix can change to9 T+ V* F w; }* ^7 P U
for i = 1:row %dominance,which row the row will �long.Second volumn record
- R( U; T7 w! P% n3 I- m' g every_line = A(i,:); %whether the matrix satisfy the necessity %that everydominance
8 i. S3 B& l/ d record(i,3) = i; %third volumn record the rowth
6 d4 N# I" r0 E( T! k. l [record(i,1),record(i,2)] = which_row(every_line);
) |7 j4 _/ z0 t- ^ ~. D, a; o' u1 h if record(i,2) == 0
6 V7 ], h# J( o, E- [ disp('This Matrix cannot change to dorminant matrix by row exchange.');
# B# f3 c0 y4 W& X4 K) F* F: w flag = 0;, \ h" L6 o3 [: [7 L" O8 i% h* r
break;3 W# K! d6 m' |9 M% v
end
! [$ h' h" B9 y& ^5 j7 n z) q/ X% S6 `end
* K: E9 L9 s" Lif flag == 1
3 H/ P% L; ^$ H for i = 1:row-1/ w- v# M/ b3 n4 o: w- G3 I
for j = 1:row4 O3 S" Z- i$ R& r! R$ r+ C
if record(j,1) == i %exchange line if flag = 1,which means it can be transformed
3 X( [( S' c3 F& \ b = A(i,:); %into dorminance2 |: E9 [# I0 R1 w5 W/ K
A(i,:) = A(record(j,3),:);& `2 v" w. a- E( k% Q
A(record(j,3),:) = b;
8 V& Q' e( c8 h9 m7 j8 J temp = record(j,:);
! T" a+ C4 s; m# e- M2 M: m record(j,:) = record(i,:);0 r6 Q2 t4 a5 Y6 c6 M! u( }
record(i,:) = temp;
+ s c& \, Z0 P1 n; M6 g- w7 d break;- x" `& n* ?! G, O/ W0 ?
end
. U+ ?( K& B. d- q( i$ e end
* @; @0 `$ ~9 u$ p end
9 V* _" v/ C& | disp(A);1 F5 {% k. v6 `
end 调用函数: % function judge_row:
# }% @% G- h+ @9 R% this function is to judge whether the line is a line of dorminance and
3 U5 d; t' X- L2 z% P% return which row shuold this line stand
9 h4 z$ M# A+ ]( u/ y' q& ^% Input : vector(a row of the matrix)3 @6 j$ F/ s; b# Z4 S1 e
% Output:if(the line is dorminant) return flag = 1;1 o8 [4 Q- k: g
% else return flag = 0.
; V$ D! w4 e4 c4 Y- gfunction [row,flag] = which_row(a)1 p* m4 s% O) ~6 h
n = length(a);
) j8 l3 ]! C+ |6 Xmax = a(1);! ~; ~/ a$ C- p) f) ]7 L" ~
flag = 0;) M) R# j2 y3 V1 t
row = 1;
9 X$ I K/ R( hfor i = 2:n
! i# \3 Y1 V5 u& R" o$ v4 I if max < a(i) %fing the max value of the line( y* o0 _$ A2 X; Z; d, F2 }
max = a(i); %it's easy for us to know that if the max value is1 O E; R8 X* ?' f' @
row = i; %larger than the rest of all sum! |# o1 v }1 q5 X& C
end %than the line is dorminance
8 r, G8 M9 ~' f9 s6 eend
* U- @' a1 U- s. cand = 0;
" O. ~( ?5 a a0 O' |for i = 1:n
* C3 v5 o" u6 B$ g6 N9 J! @ if i ~= row %compare maxvalue and rest sum3 f- |( \( s3 i/ @% j' \0 f) u
and = and + a(i);
" l0 l* `" z( \8 z" J1 X end
2 t- x' y, W7 j" S3 }end
4 M* u: y* [# l2 @! D2 Wif a(row) >= and& k& J% s( m7 b) L, ^- m" E
flag = 1;
: n2 I& M& [9 }; g' Y. ], \* ~. Iend 2 k1 F% C6 w1 u/ f
|