LineGraphCreator

Version 100520

Primary source is now
Evans, Tim; Lambiotte, Renaud (2014): LineGraphCreator. figshare. 10.6084/m9.figshare.1184430

This simple C++ code reads in a graph and creates its weighted line graph. These line graphs are defined in the paper by T.S.Evans and R.Lambiotte, Line Graphs, Link Partitions and Overlapping Communities, Phys.Rev.E 80 (2009) 016105 arXiv:0903.2181. Please cite this paper and acknowledge use of this code if you use this code.

A later paper Edge Partitions and Overlapping Communities in Complex Networks, European Physical Journal B, 77 (2010) 265–272 (arXiv:0912.4389) covers in more detail the case where one is interested in the different line graphs of a weighted graph.

This code been used successfully on an unweighted graph which produced 5.5e8 stubs in its line graph, though a special machine was used for this as it needs more than 4Gb of RAM memory. On a 4Gb machine a line graph with 4.5e7 stubs was created using this code.

This version should do all types of graph. It has been used extensively on input graphs G which are unweighted and undirected. It has only been lightly tested on weighted but undirected input graphs G. It has not been tested on directed graph input but since the weighted input graphs produce directed line graphs some relevant aspects have been tested. This is based on a java code that has had much more testing. There is an older version of the code available at a Weighted line graphs page.

Usage

To make a line graph type
linegraphcreator -i input_file -o output_file [options]
where the options are:-
-t ncreate line graph of type number n. Default is 2.
-w read the graph as a weighted one, otherwise it is unweighted.
-d read the graph as a directed one, otherwise it is undirected.
-h show this usage message.
The line graph types are (see Evans and Lambiotte, 2009)
0 Unweighted and no self loops (C of eqn 8)
1 Unweighted with self-loops (tilde{C} of footnote 2)
2 Weighted and no self loops (D of eqn 11)
3 Weighted with self-loops (E of eqn 14)

For example try

linegraphcreator -i input/BowTieinputEL.dat -o BowTieWLGoutputEL.dat -t 2

File Formats

Files have the vertices numbered from 0. Each line corresponds to one edge in the graph and has two or three entries separated by white space (e.g. using spaces, or by using a tab separated format from a spreadsheet). The first two entries are the index of the source then target vertices at the two ends of an edge. The third column is only used if graph is weighted and is the edge weight. No extra entries or lines are tolerated. In particular you must specify the input graph to be weighted (-w) if the input file has a third column or if its unweighted there must not be a third column. Note also that the number of vertices created in the graph is one more than the largest vertex index in the list. The vertices of the graph are numbered from 0 to this largest index, inclusive. If an index in this range is not listed in the input file (i.e. it has no edges) then it is created in the graph as a vertex of degree 0.

Self-loops may be created but it is not clear if the code works for these.

Multiple edges between the same two vertices may also be created but again it is not clear if the code will work properly in this case.

The output files are in the same format. The vertices of the line graph are the edges of the original graph and are again numbered from 0 in the order of the edges given in the input file for the original graph G.

Example One

For example the undirected, unweighted Bow Tie diagram (Fig.1 of Evans and Lambiotte, 2009) is given in the file input/BowTieinputEL.dat and is simply
0 1
0 2
1 2
2 3
2 4
3 4
If you type
linegraphcreator -i input/BowTieinputEL.dat -o BowTieWLGoutputEL.dat -t 2
this should produce a type 2 line graph D(G) as follows:-
0	1	1
0	2	1
1	2	0.333333
1	3	0.333333
1	4	0.333333
2	3	0.333333
2	4	0.333333
3	4	0.333333
3	5	1
4	5	1
where the first two columns are the vertices in the line graph and the last is the weight. Note that the vertices in the line graph are numbered from 0 in the order of the edges in the input file. Thus edge (0,1) in the input file for graph G is vertex 0 in the output file for D(G). Thus edge (0,1) in the input file for graph G is vertex 0 in the output file for D(G), while edge (3,4) in the input file for graph G is vertex 5 in the output file for D(G).

Example Two

A second example is the weighted undirected Bow Tie diagram given in the file input/BowTieWinputEL.dat
0 1 1
0 2 2
1 2 1
2 3 1
2 4 1
3 4 1
If you type
linegraphcreator -i input/BowTieWinputEL.dat -o BowTieW_WLGoutputEL.dat -t 2 -w
this it should produce a type 2 line graph D(G) as follows:-
0	1	1
1	0	1
0	2	1
2	0	1
1	2	0.333333
1	3	0.333333
1	4	0.333333
2	1	0.5
2	3	0.25
2	4	0.25
3	1	0.5
3	2	0.25
3	4	0.25
4	1	0.5
4	2	0.25
4	3	0.25
3	5	1
5	3	1
4	5	1
5	4	1
where the first column is the source vertex, the second is the target vertex and the last is the edge weight. Note that the vertices in the line graph are again numbered from 0 in the order of the edges in the input file. Thus edge (0,1) in the input file for graph G is vertex 0 in the output file for D(G), while edge (3,4) in the input file for graph G is vertex 5 in the output file for D(G).

Basic Compiling

You can try the following:-
g++ -o linegraphcreator TseGraph.cpp main.cpp
The TseGraph.o and main.o files can be deleted afterwards. The g++.exe depends on your compiler, here the standard gnu c++ compiler is used. Below for the intel compiler on the altix icpc is needed. This produces an executable linegraphcreator (on Windows its linegraphcreator.exe). This is run by typing ./linegraphcreator on Unix (simply linegraphcreator on Windows). with any options you require.

If you want to get more complicated, try optimising options -O2

g++ -c -O2 -o TseGraph.o TseGraph.cpp
g++ -c -O2 -o main.o main.cpp
g++ -o linegraphcreator TseGraph.o main.o

makefile

If you have make then the following makefile might work. The makefile is stored as makefileTSE but needs to be renamed to be simply makefile. Then just move to the directory with the main.cpp, TseGrapgcpp.cpp, TseGrapgcpp.h and makefile then type make. For information on make try mrbook.org/tutorials/make/.
CC=g++
CFLAGS=-c -Wall
LDFLAGS=-O2

all: linegraphcreator

linegraphcreator: main.o TseGraph.o
	$(CC) $(LDFLAGS) main.o TseGraph.o -o linegraphcreator

main.o: main.cpp
	$(CC) $(CFLAGS) main.cpp

factorial.o: factorial.cpp
	$(CC) $(CFLAGS) TseGraph.cpp

clean:
	rm -rf *o linegraphcreator

Using on the Imperial altix HPC machine

To run on the altix first compile using the following: (see axlgcmake.sh)
 module load intel-suite icpc -xP -mcmodel=large -i-dynamic -o linegraphcreator TseGraph.cpp main.cpp
Next submit a script to run this by using
qsub axlgc.sh
making a note of the job number. The script should look something like this:
#!/bin/bash
#PBS -l walltime=24:00:00
#PBS -l mem=60Gb
#PBS -l ncpus=4
#PBS -m abe
# Script to run linegraphcreator (C++) on ALTIX
#
# compile using
#module load intel-suite
#icpc -mcmodel=large -i-dynamic -o linegraphcreator TseGraph.cpp main.cpp

module load intel-suite
export NAMEROOT=IC090729stempt
export NAMEEND=inputEL.dat
cp -v ${HOME}/linegraphcreator/input/${NAMEROOT}${NAMEEND} ${TMPDIR}
echo Running ${NAMEROOT}
${HOME}/linegraphcreator/linegraphcreator  -i ${TMPDIR}/${NAMEROOT}${NAMEEND} -o ${TMPDIR}/${NAMEROOT}WLGoutputEL.dat -t 2
cp -v ${TMPDIR}/${NAMEROOT}WLG* ${HOME}/linegraphcreator/output/
Note the job number used and check progress using qstat. When finished there will be files called axlgc.sh.oNNN and axlgc.sh.eNNN for the standard output and error streams respectively, where NNN is the job number.