2

Any function in that Graphviz which can do that? If not, any other free software that can do that?

doug
  • 69,080
  • 24
  • 165
  • 199
yeeen
  • 4,911
  • 11
  • 52
  • 73

2 Answers2

5

Given that you want to render your graphs in graphviz, i suggest using the python library, networkx, to calculate graph complement. Networkx is an excellent library for graph theoretic analysis; it also has a seamless interface with graphviz.

(Rough definition of a graph complement: imagine a graph A', which has the identical nodes as A but that has all possible edges, i.e., every node is connected to every other node; now remove from A' the edges in A; what's left is the complement of A, A')

import networkx as NX
G = NX.gnm_random_graph(10, 10)   # create a random graph w/ 10 nodes, 10 edges
G_cmpl = NX.complement(G)         # get the complement of graph 'G'

# to render it in graphviz:
NX.write_dot(G_cmpl, "somefilename.dot")
doug
  • 69,080
  • 24
  • 165
  • 199
  • This looks like what I want. But how do i install networkx using the downloaded Python Egg file? The quick download in the install.txt only says "Get NetworkX from the Python Package Index at http://pypi.python.org/pypi/networkx or install it with:: easy_install networkx and an attempt will be made to find and install an appropriate version that matches your operating system and Python version." I have installed Python btw. – yeeen Jan 17 '10 at 00:51
  • You need to install 'setuptools' in order to be able to install packages via 'eggs.' I don't know your OS, so here's the link to a step-by-step guide: http://peak.telecommunity.com/DevCenter/EasyInstall. if you don't want to install using setuptools ('eggs'), go to the Networkx repository (http://networkx.lanl.gov/download/networkx/) dll and unpack the latest version appropriate for your OS, open a shell, cd into the package's top-level directory and type at the shell prompt: 'sudo python setup.py install' (without the quotes). That will install it. – doug Jan 17 '10 at 02:49
0

Compute the complement yourself, then plot it.

Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147
  • not that I nvr thought of this, it is just that sometimes the complement is very difficult to compute, esp if u hv many nodes and edges in the original graph – yeeen Jan 15 '10 at 01:22
  • so the follow up qn is whether there is any software or online tools that can accomplish it – yeeen Jan 15 '10 at 09:27
  • Well, graphviz is a good one for plotting. How many nodes and vertices do you have? What is the input format? – Hamish Grubijan Jan 15 '10 at 15:03
  • I want an efficient sw, so u can assume quite a lot of vertices and edges in the complement graph. Input is to manually type in... – yeeen Jan 17 '10 at 00:48