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.

339 questions
Filter by
Sorted by
Tagged with
11k views

How can I use Mathematica's graph functions to cheat at Boggle?

Boggle is a word game played with 16 dice and a 4x4 tray. This question is inspired by a Stack Overflow question about Boggle that I decided to solve using Mathematica. In addition to Mathematica, I ...
2k views

How can I conveniently call igraph from Mathematica?

Mathematica has lots of functions for working with graphs and networks, but there are still some functionality holes that are provided by other packages. Also, due to the nature of graph theory, ...
788 views

How can I remove B -> A from a list if A -> B is in the list?

I have a list of transformations like this: list = {"A" -> "B", "B" -> "A", "C" -> "D"} As this is used to plot an undirected graph with ...
4k views

Automatically generating a dependency graph of an arbitrary Mathematica function?

Has anyone written a function to pull the function dependencies of a function? That is, it would be nice to have a function that returns a list of function dependencies as a set of rules, terminating ...
437 views

Issues adding properties to multigraph

Bug persisting through 12.0 Unsupported Functionality (loosely, a bug) Mathematica (as of 11.0.1 for Mac OS X x86 (64-bit) (September 21, 2016)) does not support multi-graph where edge properties ...
3k views

Generating graphs interactively (GUI)

I want to create graphs interactively using a GUI. I thought of using a ClickPane[] environment. The code I have (in part borrowed from the Documentation) works ...
1k views

How to obtain the cell-adjacency graph of a mesh?

In addition to the accepted answer, see also the answer by Chip Hurst. This functionality is built in, but not documented. Given an arbitrary mesh region, how can I efficiently obtain the graph ...
463 views

Graph: Coloring parallel edges individually

CODE: Graph[{Style[0 -> 1, Red], Style[0 -> 1, {Blue, Dashed}]}] This Mathematica code will make both lines solid Red, since they belong to the same two ...
6k views

How to get graph layout that reflects edge weights?

My heart soared to discover that Mathematica 8 offers support for specifying a weighted adjacency matrix in WeightedAdjacencyGraph. But it seems that, regardless of the weights between edges, the ...
7k views

Finding all shortest paths between two vertices

The built-in FindShortestPath and GraphDistance functions find the shortest path between two particular vertices in a graph. I ...
8k views

Solving the Travelling Salesman Problem

I've been trying to find some kind of mathematical computer software to solve the Travelling Salesman Problem. The Excel Solver is able to do it, but I've noticed there is a built-in function in ...
765 views

Can TreeForm be displayed “sideways”?

One recurrent problem I'm having with displays generated with TreeForm is that the expressions to be so displayed often at least one level with many (> 20) nodes at,...
831 views

How to get all Perfect or Near-Perfect Matchings of a graph

I have found the Perfect Matching's definition in Wiki. A perfect matching (a.k.a. 1-factor) is a matching which matches all vertices of the graph. That is, every vertex of the graph is incident ...
359 views

Is there something wrong with VertexConnectivity

Note: this is fixed in version 10. As I noticed in the documentation VertexConnectivity is defined as the following The vertex connectivity of a graph $g$ is ...
3k views

Cycles of length N in a graph

If I have an undirected graph represented with an adjacency matrix, how can I find all the subgraphs which are a cycle of length N? I don't really know the math nor the programming language well, so ...
10k views

How to generate random directed acyclic graphs?

How to programmatically build random directed acyclic graphs (DAG)? I know about the AcyclicGraphQ predicate and the ...
757 views

Transform an expression into a graph that can be plotted with TreeGraph (not TreeForm)

I would like to plot an expression (like TreeForm does), but using the new TreeGraph functionality. ...
573 views

How to generate a Graph from a picture of a graph?

I have a picture like this I can get this graph's vertexes ...
601 views

Determining whether two $k$-chromatic graphs are isomorphic (respecting vertex coloration)

Consider the case where I have two $k$-chromatic graphs $G_1$ and $G_2$, i.e. two graphs where individual vertices can be colored with one of a set of $k$ total colors, and I would like to determine ...
483 views

Bug introduced in 10.0 and persisting through 12.0 TransitiveReductionGraph is new in 10.0. In Mathematica 10.0 and 10.1, according to the documentation of ...
4k views

Finding a percolation path

I would like to examine percolation on a random lattice. To be exact, I wish to find the minimum length of a 'bond' needed such that the leftmost site can be connected to the rightmost site. Here is ...
7k views

How to play with Facebook data inside Mathematica?

I saw this post from Wolfram here and I would like to know how to import facebook data into Mathematica.
2k views

Graph from binary matrix (not adjacency) respecting the original matrix positions

I have a binary matrix. My objective is to connect every close (without "jump") elements with value equal to 1, but I must keep the point positions, just like it's shown at the image. Can somebody ...
4k views

How to plot planar graphs as such?

A planar graph is a graph that can be drawn in the plane such that no two edges cross. For example, the graph ...
2k views

Finding face vertices from the face adjacency graph

I have a question about face adjacency graphs. Suppose that I have an adjacency matrix ...
2k views

Graph vs. GraphPlot

What is the difference (in purpose) between Graph and GraphPlot? Which function is bested suited to which tasks? Background: I ...
807 views

Import and Plot Git Commit History

What might be the easiest to import and plot all commit history for a github project? I'm looking for something similar to the following.
4k views

Creating a graph with variable size of vertices and variable thickness of edges

I'm trying to create a graph to represent transitions between different states of a system. I would like to represent the time the systems spent in a state with the size of the vertex and the ...
2k views

How to speed up Minimum Spanning Tree algorithm?

How to speed up MST algorithm? I work with graphs and I have adopted Prim's algorithm for my needs, from here. The graphs which I use are very dense (number of vertexes: $V=500$ and every vertex is ...
1k views

How to add new nodes to an existing graph with fixed (coordinates) nodes?

I'm ultimately trying to create a directed graph with some of the nodes in fixed positions and the other nodes placed around them in "acceptable" positions. It's better if I ask the question by ...
421 views

Cases[data,Colon[key,_]] vs. Cases[data,key:_] toward XPath, XQuery

Exploring methods to index and search tree-structured key:value pairs via named-entity index (key paths) as opposed to Position-based indexing. Using Rule as ...
968 views

Drawing a graph with vertex avoiding edges? (Handling vertices that must be colinear?)

I'd like to draw something like the following graph: ...
250 views

How to connect some separate components with shortest total length line

Maybe this question is too hard. So I try to make a simple version to research. Simulating a simple graph than that post. ...
8k views

Trying to visualize the Collatz conjecture

I happen to have this collatz collatz[x_, y_] := If[x == 3*y || x == 2*y + 1 || y == 3*x || y == 2*x + 2, 2, 0] So i want a visual 3D adjacency graph of my ...
31k views

Finding all simple paths between two vertices in a graph

There are built-in methods to find a shortest path between two vertices in a graph, and the question on finding all shortest paths between two vertices has gathered quite a bit of attention. A path ...
14k views

Custom arrow shaft

Inspired by Sjoerd C. de Vries' nice answer to this question, and the desire to pimp a Graph I did with Mathematica recently I would like to know if there are ways to customize the arrow's shaft ...
2k views

How can I replace bi-directional DirectedEdge pairs in a Graph with a single UndirectedEdge?

The Cayley graphs produced by Mathematica 8.0's CayleyGraph function represent actions that are their own inverses in an unconventional way: rather than using a ...
2k views

How to find all vertices reachable from a start vertex following directed edges?

How to find all vertices reachable from a given start vertex following directed edges, in a cyclic directed graph given as ...
2k views

Label multiple edges between same vertices

I have a simple graph with multiple edges between two vertices, say: Graph[{ Labeled[a -> b, "A"], Labeled[a -> b, "B"] }] Unfortunately, Mathematica ...
2k views

Simple algorithm to find cycles in edge list

I have the edge list of an undirected graph which consists of disjoint "cycles" only. Example: {{1, 2}, {2, 3}, {3, 4}, {4, 1}, {5, 6}, {6, 7}, {7, 5}} Each ...
2k views

How to generate all Feynman diagrams with Mathematica?

I'm using the words "Feynman diagrams" for indexing purposes, but the question is in fact purely graph-theoretic. Given a list n={n1,n2,...} of non-negative ...
3k views

Finding elementary cycles of (directed) graphs

I need to enumerate all the simple cycles (i.e. elementary cycles where no vertex is repeated other than the starting) of a graph which has both directed and undirected edges, where we can treat the ...
516 views

Converting expressions to “edges” for use in TreePlot, Graph

This question is similar to this: Nested list to graph. How to "flatten" an arbitrary expression, eg expr = a[b[c, d[e][f], g], h] to a list of key-value pairs ...
247 views

Get or set vertex properties for all graph vertices at once

I am looking for a way to either get or set a vertex property for all vertices of the graph at once. The two functions will be: ...
1k views

How can I display a multigraph with different colored edges?

I'm new to Mathematica(version 9) and I'm trying to display a multigraph with different colored edges. Here's my code so far: ...
414 views

Preserving labels when using graph functions

I am finding that some functions that accept a graph and return a transformed graph lose all the vertex and edge labels of the graph being transformed. For example, when I define a graph like this: <...
213 views

Which are the standard graph properties?

Graph objects can have different kinds of "properties": vertex properties edge properties graph properties Each of these can be standard ones, such as ...
253 views

How to add a list of vectors (lists) to a directed graph as an edge weight?

Why does following command not work in Mathematica 11.2? ...