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
$ f' N/ w. b% l& J0 z+ T5 y% SMIE name:ChenYu class:1202 nunmber:12353032
9 {3 s3 F$ P7 V$ C; W% Change nondorminant to dorminant matrix4 p8 U( _0 g ~4 W! S0 V' L; `. {
% this method is adapted for the matrix which can be changed to dorminant
4 c+ k+ j& I5 E% m+ x0 H3 C% S% matrix only using row exchangement
6 V( a0 S2 V* P4 v% Input :A matrix2 i9 P6 @) D c! I( V9 V
% Output:A matrix which maybe dorminant
7 U1 {2 L2 M& |function method1(A)8 S3 p; j0 Y- j6 `* Q$ U5 w0 ~" d
[row,volumn] = size(A);* |0 _( H3 F E( u
record = ones(volumn,3); %use this matrix to record everyline situation0 g/ Y; r8 h( d7 t- ]
flag = 1; %first volumn record if the matrix can change to6 \" n: x2 h3 i. X' @. B
for i = 1:row %dominance,which row the row will �long.Second volumn record/ o, _1 h+ s0 t* w8 C7 [
every_line = A(i,:); %whether the matrix satisfy the necessity %that everydominance. r* g5 o0 w; }$ p" `# D& h
record(i,3) = i; %third volumn record the rowth
* c# l; z8 \: ^. J1 b: t; [' u- y. c9 Z! S [record(i,1),record(i,2)] = which_row(every_line);
7 I$ ?8 w! v1 X if record(i,2) == 0
. z4 Q' r L2 Q1 T- h3 X disp('This Matrix cannot change to dorminant matrix by row exchange.');
0 ^6 ^' P" E. w/ ?" h flag = 0;
) i" ^4 B2 o5 k; q5 d/ W: a7 p break;
1 b8 Q8 w2 h) t) T0 g+ P' c end9 j& T6 g. \: O) Y& }, P
end
& [$ _' F1 z+ Pif flag == 1
& q2 l- K! d" |" X8 P/ \& \ for i = 1:row-1+ K6 C$ S& i3 l7 r
for j = 1:row3 J( q& ? J" M1 H) Z, `
if record(j,1) == i %exchange line if flag = 1,which means it can be transformed
$ T5 s, l! o: R) `% M& ?- V; z0 Z b = A(i,:); %into dorminance8 C+ T. |0 m1 D9 v1 s5 m6 Z$ H: K& s; i
A(i,:) = A(record(j,3),:);# B: ?: N: o7 X0 d5 I4 n& b
A(record(j,3),:) = b;7 ?7 h" G4 @' ?4 K6 y9 z! f/ A
temp = record(j,:);# I1 h2 f" G1 ]6 B
record(j,:) = record(i,:);
7 b- T* r& [- k1 ]% f9 }2 G! I record(i,:) = temp;
! C- l) q+ d1 n& p1 h: o break;6 s+ {0 O7 \/ s5 K2 \
end' [' b) B y- Y2 ?( ?' n0 }& k
end
/ A: _0 |" A4 |) T0 ?) M: w end" [/ }+ q+ p# S* _ F0 ?1 O
disp(A);: B+ S9 C; q9 w, r
end 调用函数: % function judge_row:) x5 K( c% {% O% n, @3 X
% this function is to judge whether the line is a line of dorminance and
" S: p4 E/ x9 g3 E! z2 E' I2 F8 e% return which row shuold this line stand
6 D+ k& I! c! _8 e! A9 D( ~% Input : vector(a row of the matrix)* w* b9 ~ Z' v$ D
% Output:if(the line is dorminant) return flag = 1;8 K3 s# i4 e1 _9 |4 g- Q) e
% else return flag = 0.1 m& ]( Q' L, J
function [row,flag] = which_row(a)& z1 [! _8 x3 _6 W; z k& V
n = length(a);3 H2 }" @4 c0 n, l
max = a(1);
3 y* r$ p; V+ ^ \. h8 Rflag = 0;4 U+ A$ d8 ^7 Y0 g
row = 1;3 g1 i; K8 b5 U3 B* `- q3 ]
for i = 2:n
" ?* T. u. [- e" c% B) [! Z% P, f if max < a(i) %fing the max value of the line
$ A7 ~0 z$ L0 m- Y/ I3 l0 t4 D max = a(i); %it's easy for us to know that if the max value is
% g# [; _' y% r row = i; %larger than the rest of all sum
p8 W' z* h, |: i8 o0 ~7 c end %than the line is dorminance
3 l: z) `9 k* |9 D7 }end0 K4 i. z% T8 G( @
and = 0;
" |+ U* v1 d4 D" cfor i = 1:n& u& \& h4 \ U7 n) N' j; T
if i ~= row %compare maxvalue and rest sum
! g6 h+ q5 H3 O5 ?6 L5 o and = and + a(i);
! F6 A$ G4 X( {1 ~ end
% j/ ~/ w3 _5 {end
Q) j" x! R+ d5 @; Uif a(row) >= and; s1 s, p% w `2 `
flag = 1;& G4 z0 e6 t4 n# O. e
end
$ X) Z+ l. ]$ R5 d' u |