Graph::Nauty(3pm)

πŸ’– Graph::Nauty β€” the perl bindings for Nauty, bestie πŸ’–

okay so this is a page from the User Contributed Perl Documentation section of the manual, and it's all about Graph::Nauty, no cap. it's giving "i want to know if your graph and my graph are literally the same graph" energy and honestly? iconic.


✨ NAME ✨

Graph::Nauty β€” Perl bindings for Nauty πŸ¦‹


🌸 SYNOPSIS 🌸

like, here's the whole vibe up front, bestie:

use Graph::Nauty qw(
    are_isomorphic
    automorphism_group_size
    canonical_order
    orbits
);
use Graph::Undirected;

my $A = Graph::Undirected->new;
my $B = Graph::Undirected->new;

# Create graphs here

# Get the size of the automorphism group:
print automorphism_group_size( $A );

# Get automorphism group orbits:
print orbits( $A );

# Check whether two graphs are isomorphs:
print are_isomorphic( $A, $B );

# Get canonical order of vertices:
print canonical_order( $A );

that's it. that's the whole flex. πŸ’…


πŸ‘‘ DESCRIPTION πŸ‘‘

so Graph::Nauty is the little bridge that lets you talk to Nauty, which is a whole set of procedures for figuring out the automorphism group of a vertex-coloured graph, and for testing graphs to see if they're isomorphic. πŸ”₯

rn, Graph::Nauty only supports Graph::Undirected β€” so directed graphs? not today, bestie, it does not handle them. and both colored vertices and edges get accounted for when it's determining equivalence classes. periodt.

πŸŽ€ Vertex color πŸŽ€

so Graph lets you use literally any data type as a graph vertex, which means there's not much you can just infer about them automatically. πŸ™ˆ for now, Graph::Nauty by default stringifies every vertex (using Perl's "" operator) and splits them into equivalence classes. but if you need different behavior? you can pass a custom anonymous subroutine inside an option hash, like:

print orbits( $A, sub { return length $_[0] } );

the subroutine gets a vertex as its 0th parameter, and it's expected to return a string, or honestly anything stringifiable. slay.

and in subroutines where the order of the returned vertices actually matters, you can pass a second anonymous subroutine to order the vertices inside each of the equivalence classes:

print orbits( $A, sub { return length $_[0] }, sub { return "$_[0]" } );

if you don't give an ordering subroutine, stringification (Perl's "" operator) is what's used by default. lowkey convenient.

🌈 Edge color 🌈

edge colors get generated from the Graph edge attributes. the complete hash of each edge's attributes is stringified (deterministically, bestie β€” we're not doing chaos here) and that's what's used to divide edges into equivalence classes. 🧚

⭐ Working storage size ⭐

Nauty needs working storage, and no, it does not allocate it by itself. Graph::Nauty follows the advice in the Nauty user guide and allocates the recommended amount of memory β€” but for certain graphs, that still might not be enough. 😭

to control that, you can use $Graph::Nauty::worksize to set the size of memory, in the units of Nauty's setword.

like, genuinely keep this one in your back pocket if things get weird with a chunky graph.

πŸ’œ INSTALLING πŸ’œ

building and installing Graph::Nauty from source requires a shared library and C headers for Nauty, which you can download from:

<https://users.cecs.anu.edu.au/~bdm/nauty/>

both the library and the C headers have to be installed to locations that are visible to Perl's C compiler. no shortcuts, bestie. 🫢


πŸ¦‹ SEE ALSO πŸ¦‹

for the description of Nauty, refer to <http://pallini.di.uniroma1.it>.


πŸ’Œ AUTHOR πŸ’Œ

Andrius Merkys, <mailto:merkys@cpan.org>


Copyright (C) 2020 by Andrius Merkys

Graph::Nauty is distributed under the BSD-3-Clause license.


and that's the whole page!! this was documented by the perl crew, perl v5.40.0, dated 2025-02-12, on a Graph::Nauty(3pm) tip. mwah. πŸ’–βœ¨

πŸ“¦ where this page comes from