# How to generate directed multigraphs with fixed edge count and no self-loops?

**URL:** <https://igraph.discourse.group/t/how-to-generate-directed-multigraphs-with-fixed-edge-count-and-no-self-loops/1982>\
**Category:** Usage\
**Tags:** Mathematica\
**Created:** [6 April 2025 06:43 UTC](https://igraph.discourse.group/t/how-to-generate-directed-multigraphs-with-fixed-edge-count-and-no-self-loops/1982 "2025-04-06T06:43:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anhnha](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/anhnha/32/1169_2.png) [@anhnha](https://igraph.discourse.group/u/anhnha)\
**Post date:** [6 April 2025 06:43 UTC](https://igraph.discourse.group/t/how-to-generate-directed-multigraphs-with-fixed-edge-count-and-no-self-loops/1982/1 "2025-04-06T06:43:07Z")

</div>

I’m trying to generate all directed multigraphs with exactly _n_ edges and no self-loops.  
Currently, my approach is to use the **nauty** package:  
`geng -> multig -> direg`  
However, the issue is that **direg** only supports simple graphs, not multigraphs.

I wonder if there’s a way to achieve this using **IGraph** in Mathematica instead.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [6 April 2025 20:56 UTC](https://igraph.discourse.group/t/how-to-generate-directed-multigraphs-with-fixed-edge-count-and-no-self-loops/1982/2 "2025-04-06T20:56:55Z")

</div>

Can you give a small example? For example n=3 vertices and m=2 edges would give:

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/2X/e/e05c938ac40c194a1cd1d5fa2894e96c61edbee7.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/2X/a/af4db300cb4a6c8a448164925d00fb2bf7025107.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/2X/a/afa2faea5a52f355f1485cfaf9caf44ffe113d49.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/2X/7/72d46e4948c0bf74a5dc9388abc1134d07415c27.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/2X/6/60a546d32b05d67b9463246af34df5226ab1f6dd.png)

Is this correct?

If so, I think `multig` would not help, as it cannot reduce the edge count of the underlying simple graph.

* * *

To answer your question, unfortunately I do not think IGraph/M currently has the functionality to help here. It can test for isomorphism between multigraphs, but this is based on VF2 and therefore it is slow and only supports pairwise tests. It does not support canonicalization. Thus only tiny graphs could be handled.

What is the vertex and edge count of the graphs you are looking to enumerate?

---

<div class="post-metadata">

**Author:** ![anhnha](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/anhnha/32/1169_2.png) [@anhnha](https://igraph.discourse.group/u/anhnha)\
**Post date:** [6 April 2025 23:23 UTC](https://igraph.discourse.group/t/how-to-generate-directed-multigraphs-with-fixed-edge-count-and-no-self-loops/1982/3 "2025-04-06T23:23:52Z")

</div>

Hi, thanks for the help.  
That’s correct, except I forgot to mention that the multigraphs should have **no isolated vertices**.  
The number of vertices can vary and is not fixed, as long as the total number of edges is exactly **m**.

My goal is to generate all **directed multigraphs** with **no self-loops** and **no isolated vertices** , and exactly **m** edges, where **m** can range from 1 to 30, for example.  
I want to generate all such graphs (it’s okay if isomorphic ones are included).  
Do you happen to know of any workaround or other tools that might help with this?
