首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matlab+图theory+特定权重分配

Matlab+图theory+特定权重分配
EN

Stack Overflow用户
提问于 2012-11-02 23:55:50
回答 1查看 192关注 0票数 0

我希望将权重分配给边,使得Sum of (到达节点的权重)和它自己的权重加为一。

这是我尝试过的:

代码语言:javascript
复制
    clear all;
    close all;
    clc;
    %% building the graph
    g=graph;
    for k=1:6

     add(g,k,k+1)
     add(g,1,4)
     add(g,5,7)
    end
    %%assigining the statuses 0 and 1
    %label(g,1,'0');
    %label(g,2,'1');
    %label(g,3,'1');
    %label(g,4,'1');
    %label(g,5,'1');
    %label(g,6,'0');
    %label(g,7,'0');
    figure,ldraw(g);
    %x=rand(1,1);
    %y=rand(1,1)
    %% get line info from the figure
    lineH = findobj(gca, 'type', 'line');
    xData = cell2mat(get(lineH, 'xdata')); % get x-data
    yData = cell2mat(get(lineH, 'ydata')); % get y-data

    %% if an edge is between (x1,y1)<->(x2,y2), place a label at
    %%the center of the line, i.e. (x1+x2)/2 (y1+y2)/2 etc
    labelposx=mean(xData');
    labelposy=mean(yData');

    %% generate some random weights vectori.e. the probability matrix
    weights=rand(1,1,length(labelposx)) 

    % plot the weights on top of the figure
    text(labelposx,labelposy,mat2cell(weights), 'HorizontalAlignment','center',... 
                                        'BackgroundColor',[.7 .9 .7]);
    %%Transition matrix or markov matrix
    % Transition=[0 (1,2) 0 (1,4) 0 0 0;
    %    (2,1) 0 (2,3) 0 0 0 0;
    %    0 (3,2) 0 (3,4) 0 0 0;
    %    0 0 (4,3) 0 (4,5) 0 0;
    %    0 0 0 (5,4) 0 (5,6) (5,7);
    %    0 0 0 0 (6,5) 0 (6,7);
    %    0 0 0 0 (7,5) (7,6) 0];

    Transition= [0 weights(:,:,8) 0 weights(:,:,6) 0 0 0;
    weights(:,:,8) 0 weights(:,:,7) 0 0 0 0;
    0 weights(:,:,7) 0 weights(:,:,5) 0 0 0;
    weights(:,:,6) 0 weights(:,:,5) 0 weights(:,:,4) 0 0;
    0 0 0 weights(:,:,4) 0 weights(:,:,3) weights(:,:,2);
    0 0 0 0 weights(:,:,3) 0 weights(:,:,1);
    0 0 0 0 weights(:,:,2) weights(:,:,1) 0]
    %set_matrix
    %%dij-- Probability matrix
    sparse(Transition);
    d=[weights(:,:,8);weights(:,:,7);weights(:,:,5);weights(:,:,4);
     weights(:,:,3);weights(:,:,1);weights(:,:,1)]
    %%Si[k]-- matrix of the statuses(labels)
    %S=[0 1 1 1 1 0 0]

例如:加到节点4的权重加上它自己的权重应该等于1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-05 08:05:34

查看这个漂亮的random vectors generator with fixed sum文件。我想这将会回答你的问题。有关此链接的更多信息,请参阅Non biased return a list of n random positive numbers (>=0) so that their sum == total_sum

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13198769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档