How to generate all the matrices of graphs for given numbers of vertices and edges?

5 ビュー (過去 30 日間)
Yichao Li
Yichao Li 2019 年 3 月 22 日
編集済み: Maxwell Day 2020 年 11 月 23 日
Hi, everyone. Assuming all the nodes are equivalent. I wanna generate all the possible matrices to describe undirected graphs whose numbers of vertices and edges are given.
e.g. n=4 is the number of vertices and m=3 is the number of edges.
Then the possible graphs are type1:1-2-3-4, type2:1-2-4.
2 |
| 3
no 2-1-3-4 or 1-3-4,...., because all the vertices are indistinguishable.
then the code can give me the matrices as [0 1 1 1; 1 0 0 0; 1 0 0 0; 1 0 0 0] and [0 1 0 1; 1 0 1 1; 0 1 0 0; 0 1 0 0] which respectively describes the links in type1 and type 2(if it can show graphs is better).
So is there any command or function can do this? Any help is appreciated. Thanks!
  3 件のコメント
Yichao Li
Yichao Li 2019 年 3 月 25 日
Thanks for your answer! 2-1-3-4 is not valid because here all the vertices are indistinguishable so topologically, 1-2-3-4 is equivalent to 2-1-3-4.
Actually this question has been solved by Mathematica, but still thanks for your effort.
Siddhikant Mishra
Siddhikant Mishra 2020 年 4 月 15 日
could you give me the link to the mathmatica solution?

サインインしてコメントする。

回答 (1 件)

Christine Tobler
Christine Tobler 2019 年 3 月 22 日
I've attached a script that computes this for n=4 and e=3. This script will not scale well to larger numbers of nodes and edges, but should work pretty well for small cases.
There are some comments in the attachment, hope these are clear enough.
  2 件のコメント
Yichao Li
Yichao Li 2019 年 3 月 25 日
Actually this question has been solved by Mathematica, but still thanks for your effort!
Maxwell Day
Maxwell Day 2020 年 11 月 23 日
編集済み: Maxwell Day 2020 年 11 月 23 日
Hi @Christine Tobler, the generateGraphs.m code has been extremely helpful to me. Thank you.
Instead of specifying n and e, how could the code be revised to specify n (# of nodes) and a value d (degree of each of those nodes) for each value of n? E.g. revise the code to generate all possible graphs with 2 vertices of degree 2 and 2 vertices of degree 3?
Is there anyway to revise the code to allow for loops and multi-edges?, when I refer to multiedges I wish to generate graphs where up to two edges between any two vertices are allowed.
Thanks again!
-Maxwell Day

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeUndirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by