找回密码
 注册
关于网站域名变更的通知
查看: 479|回复: 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
5 Y* d& [$ f! B9 w8 g( ?6 p% SMIE   name:ChenYu   class:1202   nunmber:12353032
( A0 U" I- d" x, b. N: D5 y% Change nondorminant to dorminant matrix
9 t% R/ a+ t6 P% L$ x( \3 j2 ~$ k% this method is adapted for the matrix which can be changed to dorminant
# Y) q. W9 r8 F7 k% matrix only using row exchangement& l. ?) V- c4 l3 a" k" y
% Input :A matrix$ f0 k1 W! E3 F) {- x1 j
% Output:A matrix which maybe dorminant
3 W4 N; G! _) U' _2 i# }% `function method1(A)% i% w- S& V* u2 [+ J& Z  F
[row,volumn] = size(A);
0 ~4 ?% J3 D4 F3 _4 lrecord = ones(volumn,3);                 %use this matrix to record everyline situation3 v1 Q; c! I: ^; O) j
flag   = 1;                              %first volumn record if the matrix can change to
  i) V, E" u6 l/ P7 Tfor i = 1:row                            %dominance,which row the row will

                                         �long.Second volumn record8 T- E+ j" @& w. Q2 A
    every_line                = A(i,:);  %whether the matrix satisfy the necessity

                                         %that everydominance3 Y" W/ H" n1 F, E, ]
    record(i,3)               = i;       %third volumn record the rowth/ f/ ]- x7 e4 T: [4 x, v
    [record(i,1),record(i,2)] = which_row(every_line);3 |$ X* m/ n7 T: y; t1 I% b' h/ t- J4 w
    if  record(i,2)           == 0  Q; O- i' y+ p( n% j- D- t9 C
        disp('This Matrix cannot change to dorminant matrix by row exchange.');  a* {9 `- f) ~$ g  ?
        flag                  = 0;
4 O9 f" ]7 J- I( j; I        break;3 b9 t* b+ z9 I" _: Q  o- p
    end
9 I$ Y, @, H1 e! f$ Lend1 l* z1 L; |6 w* ?
if flag == 1% @% ]: a: C, V1 l
    for i = 1:row-1. U  U" b9 `& z5 b7 Y" m
        for j = 1:row1 w, B( q; v  i% V9 ^; n# ?
            if record(j,1) == i         %exchange line if flag = 1,which means it can be transformed
4 |( b* t3 O2 r+ J/ @; Y- V                b                = A(i,:);             %into dorminance9 M, D. B" O8 m$ j, l. s0 i
                A(i,:)           = A(record(j,3),:);
# l+ I+ w! L, V9 @: `  e                A(record(j,3),:) = b;' j6 M8 ^+ ~7 H8 f+ w$ z
                temp             = record(j,:);' t4 K' _1 h  @) t$ Y2 w) B9 y
                record(j,:)      = record(i,:);
: C/ B% _- C9 M; H0 i* |$ q+ s                record(i,:)      = temp;' {8 U0 K% ~/ [' h5 B
                break;
+ p- j. T9 s0 r/ t8 u            end3 c% N/ L! j0 }8 e1 E
        end
0 [) X9 m' @7 q: H& N" E0 c    end+ a# D* N6 ~" z) j
    disp(A);
. |' ?9 t$ @+ Y9 ]end

调用函数:

% function judge_row:
" K% t: I* G, z# w( ]% this function is to judge whether the line is a line of dorminance and5 k, x7 s/ O3 o1 P6 h5 Z
% return which row shuold this line stand* T  V1 S/ F& P7 j1 }
% Input : vector(a row of the matrix)
3 r5 p% l8 C3 D6 Q# `& Z% Output:if(the line is dorminant) return flag = 1;
9 {3 E3 }4 g* s- Q9 g  @2 v%                             else return flag = 0.
( B; V1 Z. J. `function [row,flag] = which_row(a)+ f2 l7 m0 o5 j2 a
n = length(a);
4 n; y- G- [# i. @0 U2 `# c5 O& umax  = a(1);  _+ P" z+ Q2 K. n0 l9 z# c& ^
flag = 0;+ z! g  r0 {5 |
row  = 1;
8 t9 r4 m7 g3 Mfor i = 2:n
7 |& ~" z, U- G; t5 W) V% z    if max < a(i)          %fing the max value of the line# n  S  T3 i! a8 g. Y
       max = a(i);         %it's easy for us to know that if the max value is
3 i4 K8 I6 S. W; B2 J0 D       row = i;            %larger than the rest of all sum& W9 p2 B% B$ \
    end                    %than the line is dorminance; \/ [- b4 w8 d8 W2 K
end
; r3 G  Y9 y# Y- P& ~0 Aand = 0;
. A6 i/ t% S, z1 y" H) h! Kfor i = 1:n$ R5 z, ~- Y( q, Z& \
   if i ~= row             %compare maxvalue and rest sum
) \1 A8 \  U$ L' b        and = and + a(i);) C7 C; N1 M! B2 e" J5 _" ^& m
    end
- F3 p" H: H; f+ gend/ G3 H4 M# v' B7 S
if a(row) >= and
9 C. b0 \* n  `0 B( b+ a    flag = 1;
. H% s2 P" f$ P1 v' g# `# Tend

/ K4 h8 d9 _( o+ x( Y8 [

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-24 13:39 , Processed in 0.140625 second(s), 23 queries , Gzip On.

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

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

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