Questions tagged [graphs-and-networks]
Questions about handling graphs in Mathematica, graph theory, graph visualization, GraphPlot, the built-in Graph type and the Combinatorica` package.
2,269 questions
0
votes
0
answers
57
views
HowTo vertically center node labels in Graph output
Version: "14.3.0 for Linux x86 (64-bit) (July 8, 2025)"
The code listed below using the data following it produces the result shown in the image. I want the node labels positioned directly ...
1
vote
1
answer
80
views
How to check if two edges have consistent orientation in all simple cycles of a graph?
How can I check whether two edges (tagged "c" and "d") have consistent orientation (either always the same ...
4
votes
1
answer
127
views
Is there any efficient way to find cycle matroid of a graph?
Is there any efficient way to find cycle matroid of a graph?
A cycle matroid is basically all sets of edges in a graph that does not form a cycle.
The code below works pretty well for small graphs, ...
2
votes
1
answer
112
views
How to display labeled edges in Mathematica 13.3
The following is a minimal example where it seems that 13.3 is unable to display labels over edges. How to fix that?
...
3
votes
1
answer
80
views
How to generate all graphs that decompose into a given list of subgraphs at articulation points?
Given a list of directed edge-tagged graphs gList like this:
...
1
vote
2
answers
139
views
Speeding up plotting of a large Directed Acyclic Graph
I have a large DAG that I'm trying to visualise. It's the history of a large (~350k+ commits) git repository with multiple separate origin points. I've tried using a handful of different graph layout ...
1
vote
0
answers
78
views
VertexContract cannot handle tagged edges when vertices are lists
VertexContract works with EdgeTaggedGraphs:
...
4
votes
2
answers
183
views
How can I reconstruct a graph from a list of fundamental cycles?
Assume that I have a list of simple cycle EdgeTaggedGraph objects called fundamentalCycles. I would like to construct a graph <...
3
votes
1
answer
125
views
Why Graph and EdgeShapeFunction do not respect order of vertices of edges?
Switching between {1, 5} and {5, 1} has no effect on produced graphs even though EdgeList-s ...
3
votes
3
answers
237
views
Find paths between two vertices without repeating edges but allowing vertex revisits
Suppose I have a graph (undirected):
...
0
votes
1
answer
135
views
Accelerate Mathematica code computing visibility polynomial of one graph
Let $G$ be a graph of order $n$. Then the visibility polynomial, $\mathcal{V}(G)$, of $G$ is defined as
$$
\\
\mathcal{V}(G)=\sum_{i\geq 0} r_i x^{i}
\\
$$
where $r_i$ denote the number of mutual-...
6
votes
2
answers
304
views
How can I find all simple cycles in a multigraph with edge tags?
How can I find all simple cycles of a multigraph with edge tags in Mathematica?
I tried the following, but it does not work as expected. It only returns fundamental cycles instead of all possible ...
0
votes
0
answers
76
views
How to solve the all-terminal network reliability problem in Mathematica?
I like to reproduce the algorithm(s) provided in https://arxiv.org/abs/1709.08561 to solve the all-terminal network reliability problem:
Given an undirected connected graph $G$, suppose each edge is ...
4
votes
0
answers
118
views
Highlight tagged graph
Why HighlightGraph highlights undirected tagged edges only if order of vertices agrees?
Two edges should be red but we have only one.
Tested on version 13.0.1 and ...
2
votes
1
answer
104
views
How to determine the direction of edges through a cutset in a graph?
I have the following directed graph and a cutset:
...
1
vote
0
answers
108
views
What algorithm(s) does `DeBruijnSequence` use?
A DeBruijnSequence of order $n$ on a list of length $k$ is a cyclic sequence of length in which every possible block of length $n$ taken from the list occurs ...
0
votes
0
answers
36
views
Mathematica: Factor a sum of graph terms by splitting disjoint diagrams and combining like factors
I have an expression that is a sum of graph terms. Each term is a pair {graph, coeff}, where graph is a list of edges. A single <...
4
votes
1
answer
118
views
Strange Behavior of UndirectedGraph
UndirectedGraph[g] gives an undirected graph from the directed graph g.
The document says that ...
5
votes
3
answers
275
views
How to find fundamental cycles of a directed graph?
I am trying to find the fundamental cycles of a directed graph in Mathematica. I defined my graph as follows:
...
6
votes
2
answers
377
views
Manual manipulation of graphs
I have just discovered that it is possible to manipulate vertices or edges of graphs if they are converted to Graphics.
After manipulation you can extract position ...
2
votes
2
answers
207
views
Nice planar layout of graphs
What can be done when GraphLayout -> "TutteEmbedding" produces ugly graphs?
...
2
votes
1
answer
119
views
Neighbour Preserving Graph Embedding on a Grid
Suppose I have an undirected weighted graph (example)
...
5
votes
1
answer
103
views
Restricting GraphLayout of vertices in GraphPlot3D to discrete planes along the z-axis
GraphLayout can do a lot of cool things like when we set the option to SpringElectricalEmbedding and other embeddings for ...
4
votes
2
answers
268
views
Enlarged Graph vertices are covering up edge arrows
My goal is to capture the results of brainstorming session in a graph where, for the high-level process, the vertices look like text boxes and are connected by directed edges.
I succeeded in the first ...
2
votes
3
answers
370
views
Why does importing a .dot graph file cause \l and \r to become \n?
When I import a DOT file (or a string in that format) with labels containing the exact characters \\l or \\r, they are displayed ...
2
votes
0
answers
125
views
Results of Colin de Verdière's graph invariant calculations do not correspond to the nature of the graph under study
I decided to test Colin de Verdière's graph invariant method and use it to estimate the planarity of a graph.
The materials I used:
https://en.wikipedia.org/wiki/Colin_de_Verdi%C3%A8re_graph_invariant
...
3
votes
2
answers
155
views
How can I efficiently find all cutsets of a graph based on the definition of cutset?
I want to find all cutsets of a graph based on the following definition:
A cutset is a set of edges of a connected graph G such that the removal of these edges from G reduces the rank of G by one, ...
1
vote
0
answers
81
views
Formulae of different topological indices [closed]
A topological index, also known as a connectivity index, is a type of a molecular descriptor that is calculated based on the molecular graph of a chemical compound
How to refine below code (...
1
vote
0
answers
71
views
Efficient calculation of Hosoya Index
The Hosoya Index is the number of independent edge sets (i.e., matchings) in a graph.
I have implemented it in Mathematica (based on the source code provided in ...
4
votes
1
answer
250
views
Efficient calculation of treewidth
The treewidth of an undirected graph is a very important concept in graph theory.
I have ported the python code from a related Code Golf question to Mathematica, and it has passed the test cases.
...
1
vote
1
answer
151
views
Rectangle counting in large bipartite graphs
For a bipartite graph, the local clustering coefficient of a node $v$ is the number of rectangles containing $v$ as a fraction of (something like, depending on the definition) the total number of ...
1
vote
0
answers
69
views
How to accelerat the Mathematica code calculating cover time of one graph?
The cover time of a graph is the expected time it takes a simple random walk on the graph to visit every node.
Related MSE post.
How to accelerat the Mathematica code calculating cover time of ...
2
votes
1
answer
130
views
Generate only certain number of graphs because of limited RAM
I am using the code provided in the answer for this other question. It is shown below:
...
0
votes
0
answers
87
views
ConvexHullMesh::affind error message in Mathematica V14.2 but not in V12
Using Mathematica 14.2 I am trying to run the following built in function: CommunityGraphPlot
I'm getting the following error message: ConvexHullMesh::affind
When trying to run examples provided in ...
3
votes
1
answer
135
views
Important clarification about PlanarGraphQ
By definition, a planar graph is a graph that can be represented on a plane without intersecting edges.
...
6
votes
2
answers
398
views
Semicolon indentation. Is the bug in graph functions or in front end?
Bug introduced in 13.0 or earlier and persisting through 14.2.1 or later
The following produces correct outputs.
...
2
votes
2
answers
255
views
How can we choose the numbers as shown in the figure to obtain the smallest possible final sum?
I have a graph
I have
When I go A-> B -> C->D->E->A I get the sum 23,
and
How can I find the numbers like the graph. I tried
...
5
votes
1
answer
379
views
Turning the solution from Reduce to a graph
I am trying to make a graph from an arbitrary solution from reduce so that it looks prettier and is more readable.
My question is very similar to the question How can I make the output of Reduce more ...
0
votes
0
answers
94
views
How can I efficiently list non-cyclic edge combinations in a graph?
I'm trying to find all subsets of edges in a graph that do not form a cycle.
Currently, my approach is to generate all subsets of the edge set and use AcyclicGraphQ ...
0
votes
0
answers
79
views
How can I get all cycles in a multigraph using FindCycle?
I'm trying to find all cycles in the multigraph below. However, the returned cycles seem to be only fundamental cycles.
I was expecting around 8 cycles instead.
Is this a bug, or am I missing ...
1
vote
1
answer
114
views
GraphUnion not working correctly with multiedges
GraphUnion doesn't seem to produce the correct result. The output should be four blocks connected in a chain, but it's not. This appears to be another bug in ...
1
vote
1
answer
103
views
How to split a graph by given articulation points?
Does anyone know how to split a graph based on given articulation points? Below is an example of a graph with two articulation points. The expected result after splitting would be three separate ...
2
votes
1
answer
173
views
EdgeContract in multigraph
In the following code, I expected that only the edge between vertices 0 and 1 would be removed.
...
5
votes
3
answers
380
views
Retrieving connected components from list of neighbors
I have a list of vertices (denoted by integers) with larger index that each vertex connects to, like below:
...
4
votes
0
answers
221
views
Generating random Hamiltonian cycle
I need random Hamiltonian cycles in directed graphs. I guess for me it would be OK to mean by that choosing uniformly randomly from the set of all Hamiltonian cycles. ...
2
votes
1
answer
152
views
Curved edgestyle in Graph
Is it possible to have a particular edge in a graph represented by an arc instead of a straight line? The reason is that for my particular vertex positioning one of the vertices is colinear with a ...
1
vote
2
answers
112
views
How to copy edge directions from one graph to another with different labels?
I have two graphs, g1 and g2, defined as follows:
...
2
votes
1
answer
253
views
Mathematica implementation of Mason's gain formula
Mason's gain formula (MGF) is a method for finding the transfer function of a linear signal-flow graph (SFG).
I'm trying to port the MATLAB code to Mathematica code, but the Mathematica code outputs ...
5
votes
1
answer
244
views
How to split a graph at two cut vertices?
How can I split a graph into two subgraphs, as shown in the image below, given a pair of cut vertices?
(Let's assume the user ensures that a valid pair of cut vertices is provided.)
The possible cut ...
5
votes
1
answer
291
views
Is there an algorithm/functions to detect 2-isomorphic graphs?
Are there any algorithms or functions to find 2-isomorphic graphs (second isomorphism), either built into Mathematica, IGraph, or available in other programming languages?
I've been searching, but ...