• 较优H圈matlab实现


    大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang

    %解决完备图中的较优H

    clc

    clear

    w = [ inf 6 1 8 3 1 ;...        %权赋矩阵

         6 inf 1 1 6 9 ;...

         1 1 inf 3 6 7 ;...

         8 1 3 inf 1 2 ;...

         3 6 6 1 inf 1 ;...

         1 9 7 2 1 inf ] ;

    v = [ 11 12 13 14 15 16 ;...   %两点之间的路径,如25表示从点2到点5

         21 22 23 24 25 26 ;...

         31 32 33 34 35 36 ;...

         41 42 43 44 45 46 ;...

         51 52 53 54 55 56 ;...

         61 62 63 64 65 66 ] ;

    p = [ 12 23 34 45 56 61 ]    %保存某个H圈的每两点间的路径,H圈便是由这些小的路径构成的

     

    W = zeros(1,6) ;

    S=0;

    for h = 1 : 6

       d= rem(p(h),10) ;

       c= (p(h) - d)/10 ;

      W(h) = w(c,d) ;

       S= S + W(h) ;

    end

    S

     

     

    for i=1:1000

         x =  randperm(6) ;

         m = x(1) ;

         n = x(2) ;

         j = rem(p(m),10) ;

         i = (p(m) - j)/10 ;

         z = rem(p(n),10) ;

         y = (p(n) - z)/10 ;

        if ( w(i,j) + w(y,z) > w(i,y) + w(j,z) )

            s = 0;

            for b = 1 : 6

                if ( p(b) == v(i,y) | p(b) == v(j,z) | p(b) == v(y,i)| p(b) == v(z,j) )

                     s = 1 ;

                     break ;

                end

            end

            if s

                i = i + 1 ;

                break ;

            end

            p(m) = v(i,y) ;

            p(n) = v(j,z) ;

        end

     end

     

    W = zeros(1,6) ;

    S=0;

    for h = 1 : 6

       d= rem(p(h),10) ;

       c= (p(h) - d)/10 ;

      W(h) = w(c,d) ;

       S= S + W(h) ;

    end

    p

    S

  • 相关阅读:
    使用winsw将jar包注册成windows服务
    windows 下redis在后台运行
    nDPI的安装和使用
    Passive DNS安装使用
    ffmpeg-join
    Subtitle-ass-srt
    spring cloud项目05:中心化配置-P03-高可用
    spring cloud项目04:中心化配置-P02
    spring cloud项目03:高可用注册中心
    spring boot项目07:日志
  • 原文地址:https://www.cnblogs.com/xiaoyajiang/p/5950377.html
Copyright © 2020-2023  润新知