2

Here it is: I want to draw a big graph, say 50 vertices and ~200 edges. I'm getting the edges from the output of GAP, a programme for computational algebra. As it is, I have no idea what the graph will look like, but I can ask the programme to print pairs of integers or whatever. For instance:

1 -- 2,
1 -- 3,
1 -- 31,
1 -- 32,
1 -- 33,
1 -- 34,
1 -- 35,
1 -- 36,
1 -- 37,
1 -- 38,
1 -- 39,
1 -- 40,
1 -- 41,
1 -- 42,
2 -- 3,
2 -- 31,
2 -- 32,
2 -- 33,
2 -- 34,
2 -- 35,
2 -- 36,
2 -- 37,
2 -- 38,
2 -- 39,
2 -- 40,
2 -- 41,
2 -- 42,
3 -- 31,
3 -- 32,
3 -- 33,
3 -- 34,
3 -- 35,
3 -- 36,
3 -- 37,
3 -- 38,
3 -- 39,
3 -- 40,
3 -- 41,
3 -- 42,
4 -- 6,
4 -- 9,
4 -- 37,
4 -- 38,
4 -- 39,
5 -- 8,
5 -- 11,
5 -- 37,
5 -- 38,
5 -- 39,
6 -- 9,
6 -- 37,
6 -- 38,
6 -- 39,
7 -- 10,
7 -- 12,
7 -- 37,
7 -- 38,
7 -- 39,
8 -- 11,
8 -- 37,
8 -- 38,
8 -- 39,
9 -- 37,
9 -- 38,
9 -- 39,
10 -- 12,
10 -- 37,
10 -- 38,
10 -- 39,
11 -- 37,
11 -- 38,
11 -- 39,
12 -- 37,
12 -- 38,
12 -- 39,
13 -- 15,
13 -- 18,
13 -- 34,
13 -- 35,
13 -- 36,
14 -- 17,
14 -- 20,
14 -- 34,
14 -- 35,
14 -- 36,
15 -- 18,
15 -- 34,
15 -- 35,
15 -- 36,
16 -- 19,
16 -- 21,
16 -- 34,
16 -- 35,
16 -- 36,
17 -- 20,
17 -- 34,
17 -- 35,
17 -- 36,
18 -- 34,
18 -- 35,
18 -- 36,
19 -- 21,
19 -- 34,
19 -- 35,
19 -- 36,
20 -- 34,
20 -- 35,
20 -- 36,
21 -- 34,
21 -- 35,
21 -- 36,
22 -- 24,
22 -- 27,
22 -- 40,
22 -- 41,
22 -- 42,
23 -- 26,
23 -- 29,
23 -- 40,
23 -- 41,
23 -- 42,
24 -- 27,
24 -- 40,
24 -- 41,
24 -- 42,
25 -- 28,
25 -- 30,
25 -- 40,
25 -- 41,
25 -- 42,
26 -- 29,
26 -- 40,
26 -- 41,
26 -- 42,
27 -- 40,
27 -- 41,
27 -- 42,
28 -- 30,
28 -- 40,
28 -- 41,
28 -- 42,
29 -- 40,
29 -- 41,
29 -- 42,
30 -- 40,
30 -- 41,
30 -- 42,
31 -- 32,
31 -- 33,
32 -- 33,
34 -- 35,
34 -- 36,
35 -- 36,
37 -- 38,
37 -- 39,
38 -- 39,
40 -- 41,
40 -- 42,
41 -- 42,

and I want to create a graph (in the combinatorial sense) having vertices 1,2,... and edges drawn according to the pairs printed. Since I'll be getting a huge list, is there some method that will allow me to automatically enter this list with copy-paste into some code and have the graph drawn for me? I can obviously change what GAP prints, e.g. if instead of 1 2 we need (1,2) or some other string with relevant information.

I have zero knowledge of tikz.

Update: using the code suggested, I get the following graph:

enter image description here

Any suggestions how to better draw this graph would be welcome (the messy one in the middle is the complete graph on 6 vertices).

the_fox
  • 547
  • If you can cook up a small (but still realistic) example dataset we can fiddle with it but this is not a math site so what you mean by graph is not so familiar to (some of) us. Paint drawings are also more than welcome ;) – percusse Feb 17 '15 at 22:10
  • The meaning of the word graph is the same as Petersen graph, for instance, although I don't know if mine will end up looking regular like the Petersen graph. – the_fox Feb 17 '15 at 22:22
  • 1
    Sage includes GAP and has various algorithms for drawing graphs which can be used by sagetex. I have mentioned some of this (drawing Petersen's graph) in my answer to this question. – DJP Feb 17 '15 at 22:23
  • I need time to look carefully at your answer there, but just a quick question: can sage (or sage.tex) automatically deduce from the data what the connected components are and draw them "separately" in some sense (but still as one graph)? – the_fox Feb 17 '15 at 22:32
  • So we are supposed to know what Petersen graph is then? Is it too difficult what happens to these numbers in terms of the resulting image? You have two columns of data. It can't be that complicated – percusse Feb 17 '15 at 22:37
  • Sage can determine whether a graph is connected but I don't know if it will automatically draw the components separately. – DJP Feb 17 '15 at 22:39
  • Regarding the Petersen graph, I have no idea whether you are supposed to know what it is, but you are supposed to look it up if the term "graph" I used is not clear. In case your argument is that I should have provided a link to save time, I simply don't know how to do that, – the_fox Feb 17 '15 at 22:58
  • 1
    Finding a good (i.e. useful for humans) visual representation of a large unknown graph is a hard problem. You might want to consider using a visualization tool as a preliminary step, so you have an idea of what you want. Perhaps gephi (http://gephi.github.io/) or something like it. (I don't know that particular one - just found it with google.) – Ethan Bolker Feb 18 '15 at 14:13
  • I guess one can always put the vertices on a circle in a regular polygon configuration and draw the edges to obtain the graph as a subgraph of K_n. Here, however, the problem is simple. One needs only draw K_6 in the centre and just one "branch", then put the other two by rotation. – the_fox Feb 18 '15 at 15:14
  • The merit of the approach exhibited in the answer (and the reason for my original question) is that with zero effort you get a first idea what a good visualisation of the graph might be. Imagine trying to do this by hand... – the_fox Feb 18 '15 at 15:19
  • Seen the update. Can you use the PGF/OGDF interface? The algorithm SpringEmbedderKK may help you. – Astrinus Feb 18 '15 at 19:59

1 Answers1

5
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{force}

\begin{document}
\tikz [rounded corners]
\graph [spring layout, node distance=2cm]
{
1 -- 2,
1 -- 3,
1 -- 31,
1 -- 32,
1 -- 33,
2 -- 3,
32 -- 33,
33 -- 31
};

\end{document}

Needs to be compiled with LuaLaTeX. More details on PGF manual, page 369 and 421.

enter image description here

egreg
  • 1,121,712
Astrinus
  • 1,809
  • 10
  • 28