Create random graph with limited degree

조회 수: 5 (최근 30일)
Sara
Sara 2020년 7월 12일
댓글: Sara 2020년 7월 13일
I want to create random and an undirected graph where the maximum degree of each node in the graph = 4, we can have in the graph nodes with the degree 2,3 or even 4 but none of them has a degree greater than 4, in other words, the degree of each node is between 1 and 4.
anyone can help?

채택된 답변

Bruno Luong
Bruno Luong 2020년 7월 13일
n = 10; % number of nodes
maxDeg = 4;
M=rand(n);
M=0.5*(M+M');
S1=sort(M,1,'descend');
S2=sort(M,2,'descend');
T=max(S1(maxDeg,:),S2(:,maxDeg));
A=M>=T;
G=graph(A)
plot(G)

추가 답변 (1개)

Christine Tobler
Christine Tobler 2020년 7월 13일
You could start by just making an undirected graph, and then go through each node and compute its degree. If the degree is larger than 4, remove some of the edges connecting to that node at random.
Do you need it to be "uniformly" random, and if yes in which way?
  댓글 수: 1
Sara
Sara 2020년 7월 13일
I will try that thank you verry much

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by