找回密码
 注册
关于网站域名变更的通知
查看: 468|回复: 1
打印 上一主题 下一主题

Matlab之将非严格占优矩阵化为严格占优矩阵

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-8-20 16:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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
2 Y3 J! a6 e. S4 a* Q, J% SMIE   name:ChenYu   class:1202   nunmber:12353032
$ B- h7 A# C: ^( Z' v- ~% Change nondorminant to dorminant matrix
( _" S6 I& d3 t! |( q) a/ h% this method is adapted for the matrix which can be changed to dorminant4 V1 k% q) |; {
% matrix only using row exchangement" ], Z, q6 A" X2 [4 i
% Input :A matrix
( B- t  {# N+ d- n: v% Output:A matrix which maybe dorminant9 D+ _7 h& Q% \+ I* W" X" o9 ~* X
function method1(A)
' f* q' Z0 _  \* q% E" Y) w[row,volumn] = size(A);
' j3 _' X; V) \! g. I6 Grecord = ones(volumn,3);                 %use this matrix to record everyline situation
0 A9 i9 R  |4 ^flag   = 1;                              %first volumn record if the matrix can change to
. `) Y! k$ u- Z- Q8 b2 A: ~for i = 1:row                            %dominance,which row the row will

                                         �long.Second volumn record. U) w+ C8 `# V% B% s1 ~0 i
    every_line                = A(i,:);  %whether the matrix satisfy the necessity

                                         %that everydominance
8 L: r  l" K1 \7 d1 e    record(i,3)               = i;       %third volumn record the rowth8 }, G" ?) k5 u& s
    [record(i,1),record(i,2)] = which_row(every_line);5 ]2 X: _- E3 c0 c, E
    if  record(i,2)           == 0- z7 P% Q" p* e" i1 }6 ~4 Y. D8 x
        disp('This Matrix cannot change to dorminant matrix by row exchange.');6 Y& \7 V3 `" t) g7 e9 u
        flag                  = 0;
; G+ Q7 F5 ~. U# e' Z        break;$ P% r/ J! K! s2 s
    end, v$ Q: r( j/ _9 d8 x- E
end, Z1 Q% \2 S" X' c! W
if flag == 1" E7 M% R6 P& o: @% w
    for i = 1:row-1
% s! \9 v) N  z2 a: |' [9 Z        for j = 1:row' q, p; }) W4 S4 i( ^9 N& I) r
            if record(j,1) == i         %exchange line if flag = 1,which means it can be transformed% y0 H) P0 n% c4 C* o
                b                = A(i,:);             %into dorminance+ B6 z3 y5 o& \$ F- p- Z4 h
                A(i,:)           = A(record(j,3),:);
# Y+ w+ x* h; n9 ?                A(record(j,3),:) = b;
/ E8 n7 u( }, y; _                temp             = record(j,:);$ l1 b) b  D+ `
                record(j,:)      = record(i,:);6 e8 b0 Q, {! }9 q: M2 E- c
                record(i,:)      = temp;
" l! z2 U5 ^0 t                break;" c/ c; G% _5 l$ j" l8 A+ A! w/ V# F
            end" j9 H- Z9 h  G1 O
        end5 D' K& J% \4 c" Y. @1 R
    end9 U0 R4 M) J/ {8 P' J9 w* o# D0 p2 G
    disp(A);
/ A% k% H3 K% yend

调用函数:

% function judge_row:7 [& \2 p% E+ z& N
% this function is to judge whether the line is a line of dorminance and  m" ~2 A, I1 J( l  l
% return which row shuold this line stand
. P" ^0 a) d2 v% Input : vector(a row of the matrix)( Q3 [( z4 p& L" i. E# \3 d8 ^
% Output:if(the line is dorminant) return flag = 1;: R! Y9 M6 g1 v" i8 t
%                             else return flag = 0.
7 }% C2 a% G+ g' ^. N/ efunction [row,flag] = which_row(a)
. l9 d% g. p* J  o$ B) a% p" Dn = length(a);
$ l4 [' t0 h  C; E. I- C( x# G; Hmax  = a(1);
" ^  r0 a3 m+ N7 d6 U$ |flag = 0;1 B! o0 p, X* R7 ~" R
row  = 1;
, h* g' A. O! ]% @2 {; m9 Ifor i = 2:n
' E6 b) I+ o; j& c! m3 r    if max < a(i)          %fing the max value of the line
0 m) ?! \# P: D: V+ D: B( a       max = a(i);         %it's easy for us to know that if the max value is
' |/ }( U, O$ B       row = i;            %larger than the rest of all sum) I+ A3 p) x! o: @( t0 p& V
    end                    %than the line is dorminance
! x2 a0 }% A6 H0 A! oend9 ~* V5 [5 R8 Z: M3 Q5 H
and = 0;
' t5 p+ e! G9 ]3 Gfor i = 1:n* Q# f+ q7 x/ @3 _9 J) g: ^. D
   if i ~= row             %compare maxvalue and rest sum# Y4 J! q) [; Q: U  K- m
        and = and + a(i);
- S" T" \$ C7 r; T) R    end+ a2 C$ S- Y1 A- e+ a8 u! {% O
end
& B9 y# B4 j3 I5 F' eif a(row) >= and7 \1 e5 p* U. U6 e, ~. D# @& E
    flag = 1;
4 ^- _; S( q% uend

7 m4 L. N4 R' s. K: Z+ o- t% m4 \

该用户从未签到

2#
发表于 2020-8-20 16:49 | 只看该作者
代码有点长啊,我泡泡试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-5 18:48 , Processed in 0.156250 second(s), 24 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表