What are the pros and cons of using built-in Graph/GraphPlot (and related) types vs. types in the Combinatorica package?
2 Answers
You should always use the built-in Graph
unless there is a specific reason to use Combinatorica instead.
Valid reasons to use Combinatorica could be:
- Working with very old code, originally written for Combinatorica
- The need for an algorithm that is neither available as a built-in, nor in any supported package. (There are still a few of these, e.g.
ListGraphs
). Update: The IGraph/M package now provides replacements for many of such Combinatorica functions. As forListGraphs
, I suggest using thegeng
tool from the Nauty suite. It's output format, Graph6, can be read directly by Mathematica. - You are learning about graph theory and combinatorics from the Combinatorica Book
Problems when using Combinatorica:
- Not supported anymore. There will be inconvenient conflicts with built-in symbols. See here for how to make this less painful. Minor compatibility problems with recent Mathematica versions could happen.
- The documentation is lacking. The expectation is that you would buy the Combinatorica Book.
- Performance is not great. All functions are implemented purely in Mathematica. (On the upside: you can read the source code, and the algorithms/implementations are explained in the Combinatorica Book.) Because of this is not suitable for "network science" type applications. It is meant for (mathematical) graph theory.
Here's the guide on replacing Combinatorica with builtin functionality:
The GraphUtilities`
package contains the ToCombinatoricaGraph
function which can convert a built-in Graph
expression to a Combinatorica`Graph
, in case you need some algorithms from Combinatorica.
A for GraphPlot
, it is purely for visualization, and almost all of its functionality is already built into Graph
.
I guess it also depends on your data. In my work, I do use the Laplacian for my research which can be, in principle, related to the adjacency matrix. In order to "visualize" my network I use the following:
GraphPlot[LaplacianMatrix]
Since I don't want to do an additional transformation Laplacian -> Adjacency Matrix
(it takes time), I never use Graph
as well as Combinatorica`
for such stuff.
-
$\begingroup$ I wouldn't say that
GraphPlot
supports Laplacian matrices. Instead, it simply ignores signs, self-loops and multi-edges by default. You could doSimpleGraph@AdjacencyGraph@Abs[lm]
instead, or definelaplacianGraph = SimpleGraph @* AdjacencyGraph @* Abs
. $\endgroup$– SzabolcsCommented May 2, 2018 at 10:09
System
graph objects. But as @R.M. indicates, it's better not to rely upon a deprecated package. $\endgroup$Graph
is a built-in type introduced in version 8. Since it's built-in, it can be quite efficient (at least in theory). It is clearly meant to replace all Combinatorica-related functionality because some of it conflicts with Combinatorica and now there is a warning message when loading Combinatorica. However, not all Combinatorica functions have a built-in equivalent (yet?) and there are still some bugs to be ironed out (I'm really hoping v9 will bring lots of improvement). To sum up: if you don't have the Combinatorica book, useGraph
(the future) and fall back to C'ca when needed. $\endgroup$Graph
does.GraphPlot
can plot multigraphs, whileGraph
can't represent them.GraphPlot
produces very similar layouts toGraph
, but it's not always equivalent, and I still useGraphPlot
on occasion. Some people (me included) don't like the Property API introduced withGraph
as it's not functional, and you need to keep in mind thatGraph
is an atomic type that can only be accessed indirectly through this API. (It's not like other Mma expressions.) $\endgroup$