找回密码
 注册
关于网站域名变更的通知
查看: 449|回复: 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
/ f8 o$ F# k+ ]% SMIE   name:ChenYu   class:1202   nunmber:123530326 m% ^8 I6 J1 b, o, I/ d
% Change nondorminant to dorminant matrix
% ]) w2 g$ Z% w- o% this method is adapted for the matrix which can be changed to dorminant/ G  z$ y: k6 a8 H2 `% u8 }
% matrix only using row exchangement
. _' e( E" d( o: [* q6 Y% Input :A matrix
5 a$ y& D# ^- e# |% Output:A matrix which maybe dorminant
. ~. R! ^- \$ Tfunction method1(A)( h  ]5 d$ H* m0 V! k5 z9 f% Q
[row,volumn] = size(A);! q  D5 e% B" G* p
record = ones(volumn,3);                 %use this matrix to record everyline situation
) ~# ]% c: a% W9 a/ yflag   = 1;                              %first volumn record if the matrix can change to1 d5 \+ k' V7 B1 [: _. ?3 E
for i = 1:row                            %dominance,which row the row will

                                         �long.Second volumn record
- _7 X& S- G0 o7 h; ]3 g$ a    every_line                = A(i,:);  %whether the matrix satisfy the necessity

                                         %that everydominance
- Y* D% Y9 M$ ~# G. I, B  _' G    record(i,3)               = i;       %third volumn record the rowth9 {/ X; |0 s9 J: h2 j* x3 R& }
    [record(i,1),record(i,2)] = which_row(every_line);1 X5 m: x+ G& t7 }
    if  record(i,2)           == 02 G; v4 F7 p0 f0 m6 [8 @' y% Z1 L
        disp('This Matrix cannot change to dorminant matrix by row exchange.');2 D8 k+ W( K; g
        flag                  = 0;
. b# G0 f. F3 c: n4 p( |        break;
* z" |3 _2 Y* d8 x( B; |1 w- H    end
4 X: M- O; t& R5 D6 o7 N+ Uend2 R' F% u% b3 x! l
if flag == 1
, [7 Y2 Z* o- p( j: r% g) I    for i = 1:row-1
3 `* W# I  n! L' x1 o        for j = 1:row
/ P" X* I; B1 v/ F! Z            if record(j,1) == i         %exchange line if flag = 1,which means it can be transformed
9 o1 t/ F6 Y# ]% C( A& v( t                b                = A(i,:);             %into dorminance
$ `5 H$ D9 o) R: B: K                A(i,:)           = A(record(j,3),:);9 R" M( u$ x( Y$ u* x! T& O6 `+ w
                A(record(j,3),:) = b;: \! M! W' T6 S0 P. Z, m$ G
                temp             = record(j,:);$ J3 b) f2 a! u* c
                record(j,:)      = record(i,:);
1 p) P& o# Z, {                record(i,:)      = temp;1 U! j( U# O' a) Z' U, q
                break;7 \. V3 [$ [" F* B8 b7 p$ E+ g
            end4 m$ d1 X! ?1 z0 A$ C8 V& v
        end. b( f# U+ w# B6 C0 ~3 ]
    end
2 p6 H. E2 l& l/ @    disp(A);" o& U! S; Q, |% H$ y2 A
end

调用函数:

% function judge_row:
: D! Q5 K' |2 p* N; J: c, O% this function is to judge whether the line is a line of dorminance and4 H( i& q7 J( p  p
% return which row shuold this line stand1 i: r( g( C3 C4 {) r
% Input : vector(a row of the matrix), m- @4 D& v5 P9 j+ k/ u
% Output:if(the line is dorminant) return flag = 1;( K8 |3 P0 F" y* h0 Q
%                             else return flag = 0.
1 d, w: ?% h/ L# V0 Dfunction [row,flag] = which_row(a)1 }4 I5 v5 O! j( t
n = length(a);
7 n1 M$ D2 b9 z9 M$ z6 Q5 omax  = a(1);
1 X% S9 Y9 m6 Hflag = 0;
0 b- y1 N% A7 J& `" O) }; @% orow  = 1;
- X, Z+ H+ \& Q) }7 |: Ufor i = 2:n. f/ m# g% f7 {
    if max < a(i)          %fing the max value of the line
4 ]' d8 _" T# m5 I) p: {" o" W       max = a(i);         %it's easy for us to know that if the max value is
6 m0 r' T1 {" G       row = i;            %larger than the rest of all sum5 N8 G2 z3 X. Z. T1 Y7 {$ r
    end                    %than the line is dorminance
. J" d% x- b$ I& w" Q7 Aend
6 B" F+ Z, U% S( [* Aand = 0;( R* S: W- z" h: R6 ]! P; Z
for i = 1:n
9 [) M# {; c9 K. T' W   if i ~= row             %compare maxvalue and rest sum
. X6 h( T. z0 ~+ b3 O        and = and + a(i);( n* c* d, ?/ h3 @; H
    end% A( U  r0 ~3 l- W! p1 ]$ {, P( ?- L
end
9 a+ h0 P( m# b; R9 s7 l; zif a(row) >= and
/ M9 e4 L( F! |& ~( u1 j3 f8 J2 f    flag = 1;( n! _1 u! I0 x* ]
end

6 a# g  }+ [8 @+ @3 N( f6 \

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-8-17 21:14 , Processed in 0.109375 second(s), 23 queries , Gzip On.

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

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

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