找回密码
 注册
关于网站域名变更的通知
查看: 482|回复: 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 12 l) i0 E3 q2 I0 u# C
% SMIE   name:ChenYu   class:1202   nunmber:12353032) w, ~: }7 X1 W0 g* D1 K$ W0 X
% Change nondorminant to dorminant matrix& r( S+ ]% O( ~  v8 p* x
% this method is adapted for the matrix which can be changed to dorminant
/ \3 q% Y4 g5 B* f$ |3 a% matrix only using row exchangement
( {7 D, _: L5 d& \6 ~' [% Input :A matrix* B0 S+ x( A( }+ g( D) X7 J$ \3 u- |
% Output:A matrix which maybe dorminant
0 A- {% m5 N9 |* ]7 w% c  hfunction method1(A)
9 t& N9 v% R* d1 ~/ ?# v# ~7 ][row,volumn] = size(A);
+ [# Y" C3 N& ~2 `% i% xrecord = ones(volumn,3);                 %use this matrix to record everyline situation
1 v; S  u$ x8 b3 Zflag   = 1;                              %first volumn record if the matrix can change to
; O, m9 C2 _/ w" dfor i = 1:row                            %dominance,which row the row will

                                         �long.Second volumn record
: c* y" S/ z- \% T6 L- U& L    every_line                = A(i,:);  %whether the matrix satisfy the necessity

                                         %that everydominance
6 x# P! w1 ~. @8 N5 |+ E( C. w    record(i,3)               = i;       %third volumn record the rowth
# i' ?% u) G" z    [record(i,1),record(i,2)] = which_row(every_line);9 f( x. o) ?, N
    if  record(i,2)           == 01 B- M3 c* \2 a) @+ o: Q
        disp('This Matrix cannot change to dorminant matrix by row exchange.');. q' Z" L) k! |$ }' g' y
        flag                  = 0;/ s- C# J" U: @" O. k
        break;) ]& \& R0 @' P2 n
    end5 E% k$ Q/ q6 k3 |+ k) `
end
1 g6 d2 [2 T2 v$ S$ w7 G& O* Iif flag == 1# [9 h. D. ?2 X8 P& X  x7 N/ J. ~; W
    for i = 1:row-1  j- T& {0 C5 f7 N+ |
        for j = 1:row& R7 J/ t; F# J, ~( V
            if record(j,1) == i         %exchange line if flag = 1,which means it can be transformed4 v- T9 U! Y+ l/ q( c
                b                = A(i,:);             %into dorminance
  J% [4 N5 i- g3 E% ^                A(i,:)           = A(record(j,3),:);- I4 r% s9 k& q% m* F) I* s9 T5 S
                A(record(j,3),:) = b;
. w9 z& @4 A6 E, b" r9 q+ A                temp             = record(j,:);* y! t, s! ^1 K7 s( a  w
                record(j,:)      = record(i,:);
  K) ~$ {# b# b( K' P3 j$ M                record(i,:)      = temp;4 m& `1 j# G0 R. B% o
                break;
( x+ R8 s# z+ A$ l; S: h7 J9 [8 N            end# w* O0 I, H  k* r# g4 j$ @
        end- {& C/ d, E/ z3 v/ k
    end5 R3 S2 P. h' `: x0 F, y% ?- K
    disp(A);# s" I- s9 U1 q% e( i; l" v
end

调用函数:

% function judge_row:
$ N8 r4 i7 X4 K  f7 \1 Q$ y, v% this function is to judge whether the line is a line of dorminance and- O) {+ ?5 x. h3 ~
% return which row shuold this line stand
$ O# k# D# z) H  ]% Input : vector(a row of the matrix)( }- I% U9 P+ E/ w4 p9 \8 i
% Output:if(the line is dorminant) return flag = 1;
9 G$ c9 \- C; x9 l9 B%                             else return flag = 0.
3 C4 e; R; Y7 C) l& F% Pfunction [row,flag] = which_row(a)
6 T4 {) w' j) z: Z" In = length(a);: t. C0 I0 `% ]* c
max  = a(1);
3 G5 q6 v! p; l+ i+ E  P3 B/ a( |flag = 0;
/ Z1 _; `7 }. h9 w8 Orow  = 1;2 L9 X( E# x. W8 ^
for i = 2:n- d) j* W4 v- n0 F
    if max < a(i)          %fing the max value of the line# ^) Y) ^3 k: R% m) l# J( W- }
       max = a(i);         %it's easy for us to know that if the max value is
* W  O& Z. p! e; `2 u       row = i;            %larger than the rest of all sum
: {2 R7 s7 J2 J8 G. S    end                    %than the line is dorminance* d7 L) c6 \- J
end
8 g0 x) k. G2 r$ A( |2 J8 M4 X& z/ t: e8 Mand = 0;" h" X8 z, I6 ?
for i = 1:n
6 T6 q+ I8 I8 Z5 A8 G   if i ~= row             %compare maxvalue and rest sum( c3 l, G+ M* E2 |! J1 Z
        and = and + a(i);5 s1 M  }( G2 p
    end" z3 A* E5 n7 C8 X+ ?2 ~
end6 J3 _7 x8 g7 h1 S  K1 \
if a(row) >= and
" A5 _1 B" p: l! ^    flag = 1;: t. X9 w4 U' x/ K3 D. p# j& @# d: r
end

0 X, r+ v% t7 Z, \1 j! o* j5 \) E

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-24 16:26 , Processed in 0.171875 second(s), 24 queries , Gzip On.

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

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

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