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
. s" b4 o) P, |7 U7 i- f" }0 s% SMIE name:ChenYu class:1202 nunmber:123530326 T% Y# d" b+ A8 y5 m9 n0 E
% Change nondorminant to dorminant matrix5 u, g0 Y" ]& E
% this method is adapted for the matrix which can be changed to dorminant0 X) A5 f' n# N- ]0 [
% matrix only using row exchangement$ }. I k- k \6 q* f
% Input :A matrix
# _' D) j2 K$ l7 Q2 k7 q; d% Output:A matrix which maybe dorminant
' ^/ b5 Q) ?' t- o" ]$ U; a. k2 k& pfunction method1(A)- S! E o8 m4 o' `9 j: j, |. k6 o6 Y
[row,volumn] = size(A);9 X/ p5 g O% r, Y
record = ones(volumn,3); %use this matrix to record everyline situation
2 U/ T7 x' X) Eflag = 1; %first volumn record if the matrix can change to+ G1 k, D- O: m6 b' l2 `5 q* B* i
for i = 1:row %dominance,which row the row will �long.Second volumn record B2 `- Y& b) u
every_line = A(i,:); %whether the matrix satisfy the necessity %that everydominance3 B: X/ c7 Y& t
record(i,3) = i; %third volumn record the rowth
9 O% y2 y" }7 S* O$ {' [( r/ h [record(i,1),record(i,2)] = which_row(every_line);
( M0 b, X! F- x$ z if record(i,2) == 06 B, _# X% a: M
disp('This Matrix cannot change to dorminant matrix by row exchange.');- u. @; _8 p% L) _
flag = 0;; o! V( _4 R5 C, H. l s( @; ?, T
break;
: x1 @2 {5 M$ @' ? end" i' G1 @* M- d0 W! L q, C# c
end: x% C* Y" E: U4 A! F9 w
if flag == 1
4 Q1 `# ?6 o7 O+ E C0 D" g9 V for i = 1:row-18 z0 R* y3 L) i* g; U" ?+ p* D7 e
for j = 1:row
. }: o" o F, e0 S: Z1 c if record(j,1) == i %exchange line if flag = 1,which means it can be transformed E$ s" [1 Z7 ^ N0 ?- k' V
b = A(i,:); %into dorminance
9 n* o a! O" S0 D* ` A(i,:) = A(record(j,3),:);
) W- V3 e$ T4 y' _2 v0 i- z5 i$ ~3 v A(record(j,3),:) = b;1 D0 ]4 E- s# A
temp = record(j,:);
* U+ J+ h. m2 W- `6 L# N record(j,:) = record(i,:);" _3 U4 k/ [# o+ W! R8 U
record(i,:) = temp;
/ K7 h9 }( E2 E, K" ` break;4 C1 e3 r* ^' t7 `
end+ A0 U( Y/ P: l; y' A7 B. [0 h. o3 l
end
/ W4 c$ v8 S/ C+ f. Y7 D end
" ~1 w/ Z5 c9 i0 |1 ? disp(A);( a/ g0 a5 p3 j7 y( W' w' E9 s
end 调用函数: % function judge_row:
0 a! K$ c9 Q0 G% m' ^% this function is to judge whether the line is a line of dorminance and
5 T& D- [6 S- e' Y% return which row shuold this line stand
8 d* K7 s* j1 a: e3 S( D7 r% Input : vector(a row of the matrix)
0 }) D2 L/ R$ w- J" e& V% Output:if(the line is dorminant) return flag = 1;
; Z' d* y* b) G% else return flag = 0.
4 f" \* a. V) D3 {0 D9 Zfunction [row,flag] = which_row(a)
4 V/ b4 A0 s1 C" Bn = length(a);
3 T$ P& N5 i7 {' x2 A# Kmax = a(1);
0 S! t- B1 C6 \, n7 X* Rflag = 0;! P% h, }) n/ b @2 F$ c% C
row = 1;" Y/ p+ H, Y% G8 f
for i = 2:n
7 y9 F" D- L; u( o# h+ g if max < a(i) %fing the max value of the line/ E8 m0 U# {( }7 t
max = a(i); %it's easy for us to know that if the max value is9 e/ W3 N5 w \% B7 {! e
row = i; %larger than the rest of all sum2 m; v7 j: U i( w) Q, g
end %than the line is dorminance( I3 G) n$ O8 U) @
end# n3 a7 ]/ g1 H" L- h6 H% H. ~
and = 0;
* u) U! B# K1 m0 l* }for i = 1:n5 G3 I, j' k0 t$ c) k7 j! r
if i ~= row %compare maxvalue and rest sum$ l6 Y/ h" C& u# ?
and = and + a(i);
+ b& w" O9 k1 t; r# p# ?* [; d$ @ end
3 \+ ~; J7 P2 V7 Xend7 c. l# @) w/ ]9 }( J
if a(row) >= and2 H# Y& F0 y' u1 `
flag = 1;9 H( B6 O5 Q3 e) ~
end
- [/ ^( o4 S! @0 } |