### Open Pynauty Local HTML Documentation
Source: https://github.com/pdobsan/pynauty/blob/main/README.md
Command to open the locally installed HTML documentation for pynauty in a web browser. This provides detailed information and examples for the library.
```bash
/pynauty/docs/html/index.html
```
--------------------------------
### Import Pynauty Module
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Demonstrates how to import all functions and classes from the pynauty module for interactive use.
```python
from pynauty import *
```
--------------------------------
### Install Pynauty Python Package
Source: https://github.com/pdobsan/pynauty/blob/main/README.md
Instructions to install or upgrade the pynauty library using pip. This command will attempt to use pre-built binary wheels if available for the system, otherwise, it will automatically attempt a local build.
```bash
pip install --upgrade pynauty
```
--------------------------------
### Retrieve Pynauty Package Version
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Shows how to obtain the installed version of the pynauty package using the `Version()` function, useful for reproducibility.
```python
print('Computed by', Version())
```
--------------------------------
### Build and Install Thread-Safe pynauty Libraries
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
These `make` commands facilitate the creation and installation of thread-safe versions of the pynauty libraries, enabling their use in multi-threaded applications.
```shell
make TLSlibs
```
```shell
make TLSinstall
```
--------------------------------
### Example b/x Sequence for Graph Encoding
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/formats.txt
Illustrates the b/x sequence derived from a bit stream, showing how groups of 1 and k bits are interpreted to form a sequence of (bit, value) pairs, which then map to graph edges. This example demonstrates the internal representation logic for graph structures.
```Text
1 000 1 000 0 001 1 110 0 101 1 111
This is the b/x sequence 1,0 1,0 0,1 1,6 0,5 1,7.
The 1,7 at the end is just padding.
The remaining parts give the edges 0-1 0-2 1-2 5-6.
```
--------------------------------
### Create Graph Incrementally
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Illustrates building a Graph object by first initializing it with a number of vertices, then adding connections vertex by vertex using the `connect_vertex` method.
```python
g = Graph(5)
g.connect_vertex(0, [1, 2, 3])
g.connect_vertex(2, [1, 3, 4])
g.connect_vertex(4, [3])
print(g)
```
--------------------------------
### Pynauty Module API Reference
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Reference documentation for the pynauty module, including its main Graph class and core functions for graph manipulation and analysis.
```APIDOC
Module: pynauty
Classes:
Graph:
Description: Represents a graph with vertices, edges, and optional vertex coloring. Supports directed/undirected graphs, loops, but no multiple edges.
Constructor:
Graph(number_of_vertices: int, directed: bool = False, adjacency_dict: dict = None, vertex_coloring: list = None)
Methods:
connect_vertex(u: int, neighbors: list)
Description: Connects vertex u to a list of neighbors.
set_vertex_coloring(coloring: list[set])
Description: Sets the vertex coloring for the graph.
copy()
Description: Returns a copy of the graph.
Functions:
autgrp(graph: Graph) -> tuple
Description: Computes the automorphism group of a given graph.
isomorphic(graph1: Graph, graph2: Graph) -> bool
Description: Tests if two graphs are isomorphic.
certificate(graph: Graph) -> any
Description: Computes a canonical certificate for a graph.
canon_label(graph: Graph) -> Graph
Description: Computes a canonically labeled version of the graph.
delete_random_edge(graph: Graph) -> tuple
Description: Deletes a random edge from the graph. Returns the deleted edge (u, v).
Version() -> str
Description: Returns the version string of the pynauty package.
```
--------------------------------
### Digraph6 Encoding Example for a Directed Graph
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/formats.txt
Provides a step-by-step example of encoding a specific directed graph with 5 vertices and defined edges into the digraph6 format. It illustrates the conversion of the adjacency matrix into a bit vector, calculation of N(n) and R(x) values, and the final byte sequence representation.
```Text
Suppose n=5 and G has edges 0->2, 0->4, 3->1 and 3->4.
x = 00101 00000 00000 01001 00000
Then N(n) = 68 and
R(x) = R(00101 00000 00000 01001 00000) = 73 63 65 79 63.
So, the graph is 38 68 73 63 65 79 63.
```
--------------------------------
### Create Graph with Adjacency Dictionary
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Shows how to construct a Graph object in a single step by providing the number of vertices, directed flag, and a complete adjacency dictionary to the constructor.
```python
g = Graph(number_of_vertices=5, directed=False,
adjacency_dict = {
0: [1, 2, 3],
2: [1, 3, 4],
4: [3],
},
)
```
--------------------------------
### APIDOC: Get Orbits of Stabilizer
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Explains functions for obtaining orbits relative to a partial base, with considerations for existing internal bases and dynamic structure modification. It highlights the format of the returned orbit data and important caveats regarding data validity and correctness due to the randomized algorithm.
```APIDOC
getorbits(fix, nfix, gp, &gens, n)
- If fix[0..nfix-1] is a prefix of the partial base held internally, existing orbits are returned immediately.
- Otherwise, the Schreier structure is modified to use the partial base fix[0..nfix-1], keeping as much information as possible, then expandschreier() is called and the orbits are returned.
- The function value points to an int array containing the orbits in nauty format.
- Correctness is not guaranteed due to randomized algorithm, but the partition returned is guaranteed to be finer than the true orbits partition.
getorbitsmin(fix, nfix, gp, &gens, &orbits, cell, ncell, n)
- If the basis elements fix[0..nfix-1] are minimal in their orbits, returns nfix and sets *orbits.
- If fix[i] is seen to be not minimal for some i <= nfix-1, returns i and sets *orbits for fix[0..i-1].
- Otherwise, filters until schreierfails failures, or until cell[0..ncell-1] is a subset of an orbit (if cell is not NULL).
Note: For both getorbits() and getorbitsmin(), the orbits vector whose address is returned MUST NOT BE MODIFIED by the calling program.
Note: The pointer will remain valid until getorbits(), getorbitsmin(), pruneset() or grouporder() is called for a base that is neither a prefix nor an extension of this base.
```
--------------------------------
### Run Pynauty Test Suites
Source: https://github.com/pdobsan/pynauty/blob/main/README.md
Commands to execute the test suites for pynauty. The first command runs a minimal set of tests, while the second set of commands installs pytest and then runs the full test suite, ensuring binary compatibility.
```bash
python /pynauty/tests/test_minimal.py
```
```bash
pip install pytest
python -m pytest /pynauty
```
--------------------------------
### Apply Vertex Coloring and Compute Automorphism Group
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Demonstrates how applying a vertex coloring to a graph using `set_vertex_coloring` can restrict the possible automorphisms, leading to a different automorphism group.
```python
g.set_vertex_coloring([set([3])])
print(g)
autgrp(g)
```
--------------------------------
### Set LC_ALL Environment Variable for C Collation
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
To ensure consistent sort order (plain byte order, C collation) for utilities like `shortg` and to avoid potential issues with standard Unix utilities such as `sort`, `uniq`, `comm`, and `join`, it is recommended to set the `LC_ALL` environment variable to 'C'. This ensures that string comparisons follow the C standard, which is a simple byte-by-byte comparison. Examples are provided for bash and tcsh shells.
```bash
export LC_ALL=C
```
```tcsh
setenv LC_ALL C
```
--------------------------------
### Modify Graph and Recompute Automorphism Group
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Illustrates modifying an existing graph by adding a new edge using `connect_vertex` and then recomputing its automorphism group to observe the changes.
```python
g.connect_vertex(1, [3])
print(g)
autgrp(g)
```
--------------------------------
### Copy Graph and Delete Random Edge
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Shows how to create a copy of a graph using `copy()` and then modify the copied graph by deleting a random edge using `delete_random_edge`. This is often a precursor to isomorphism testing.
```python
a = Graph(number_of_vertices=13, directed=False,
adjacency_dict = {
0: [6, 7, 8, 9],
1: [6, 7, 8, 11],
2: [7, 8, 10, 12],
3: [7, 9, 11, 12],
4: [8, 10, 11, 12],
5: [9, 10, 11, 12],
6: [0, 1, 9, 10],
7: [0, 1, 2, 3],
8: [0, 1, 2, 4],
9: [0, 3, 5, 6],
10: [2, 4, 5, 6],
11: [1, 3, 4, 5],
12: [2, 3, 4, 5]
},
vertex_coloring = []
)
print(a)
b = a.copy()
delete_random_edge(b)
print(b)
```
--------------------------------
### Get Number of Stored Generators (pynauty)
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Returns the count of generators currently stored within the group structure. This function provides a quick way to ascertain the number of active generators.
```APIDOC
schreier_gens(gens)
- Return the number of stored generators.
```
--------------------------------
### Compute Graph Automorphism Group
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
Demonstrates how to use the `autgrp` function to calculate the automorphism group of a given graph. The function returns a tuple containing permutations, group size, and other related information.
```python
autgrp(g)
```
--------------------------------
### Partial Graph Data Structure Definition in Python
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
This snippet shows a fragment of a Python dictionary-like structure, likely representing graph adjacency lists, followed by the initialization of an empty list for vertex coloring. It appears to be part of a larger graph definition or input for a graph algorithm in the pynauty library context.
```python
8: [0, 1, 2, 4],
9: [0, 5, 6],
10: [2, 4, 5, 6],
11: [1, 3, 4, 5],
12: [2, 3, 4, 5],
},
vertex_coloring = [
],
)
```
--------------------------------
### Check Graph Isomorphism with pynauty in Python
Source: https://github.com/pdobsan/pynauty/blob/main/docs/source/guide.rst
This snippet demonstrates an interactive session where the `isomorphic` function, likely from the pynauty library, is called with two graph objects, `a` and `b`. The output `False` indicates that the two graphs are not isomorphic.
```python
In [12]: isomorphic(a,b)
Out[12]: False
```
--------------------------------
### Nauty 2.5: Dreadnaut Command Updates
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Details new and extended commands for the dreadnaut interactive tool, including support for sparse nauty, Traces, and improved input/output handling.
```APIDOC
Sparse nauty and Traces now incorporated.
New commands: A, G, F, FF, sr, O, OO, P, PP, S, V.
w command: Now in units of 2*m.
Command-line: Can run commands using -o.
M command: Extended; now applies to i as well as x.
Implement ANSI controls: If requested.
File names for > and <: Can be given in "..." to allow spaces.
```
--------------------------------
### genspecialg: Generate Named Special Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `genspecialg` tool now includes a `-X` option, allowing users to generate one of 126 predefined named graphs. A list of available graphs can be accessed using `--Xhelp`.
```Shell
genspecialg -X
genspecialg --Xhelp
```
--------------------------------
### genspecialg: Generate Complete Multipartite Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-m#,#,...` option generates complete multipartite graphs based on the specified partition sizes.
```Shell
genspecialg -m#,#,...
```
--------------------------------
### Nauty 2.6: Dreadnaut Command Refinements
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Describes further enhancements to dreadnaut commands in nauty 2.6, focusing on control-C handling, output flushing, and command parsing.
```APIDOC
dreadnaut now catches control-C: When nauty or Traces is running, uses global variable nauty_kill_request.
New command "vv": To display sorted degree sequence.
New command "r&": To relabel according to the partition.
New command "->>": To flush the output.
New command "B": To turn on output flushing at the end of every command. Command "-B" turns it off (default off).
Command with short arguments: Must be all on one line. Most errors cause the rest of the input line to be skipped.
"R" command: Now preserves the colouring.
```
--------------------------------
### Download Pynauty Source Distribution
Source: https://github.com/pdobsan/pynauty/blob/main/README.md
Command to download the pynauty source distribution from PyPi. This source distribution includes the Nauty2_8_8 source code, which is required for manual compilation.
```bash
pip download --no-binary pynauty pynauty
```
--------------------------------
### shortg: Memory Allocation for Sorting with -Z
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `shortg` tool now provides the `-Z` switch to pass memory allocation options (like `-S`) to the underlying sort program. Valid arguments include numbers followed by K, M, G, or %. This can significantly speed up large tasks if ample memory is available.
```Shell
shortg -Z 10G
shortg -Z 50%
```
--------------------------------
### addptg: Generalized -j and New -e Options
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `addptg` tool's `-j` option has been generalized, and a new `-e` option has been added. More details are available via `addptg --help`.
```Shell
addptg -j
addptg -e
addptg --help
```
--------------------------------
### APIDOC: Initialize a New Group
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Documents the `newgroup` function, which is used to create the necessary data structures for a trivial group of a specified degree. It offers flexibility to either initialize with a new set of generators or reuse existing ones.
```APIDOC
newgroup(&gp, &gens, n)
- Creates the two structures needed for a trivial group of degree n.
- If &gens == NULL, it creates the schreier structure only, enabling a previous set of generators to be used to initialise a new group.
```
--------------------------------
### New C Procedures in `gutil1.c`
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `gutil1.c` file introduces two new C procedures: `numcomponents` for counting components in undirected graphs, and `sources_sinks` for counting sources and sinks in digraphs. These functions provide fundamental graph property analysis capabilities.
```C
// gutil1.c new procedures:
int numcomponents(graph *g, int m, int n); // for counting components of an undirected graph
void sources_sinks(graph *g, int m, int n, int *sources, int *sinks); // for counting sources and sinks in digraphs
```
--------------------------------
### assembleg: Updated -u Option and Summary
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `assembleg` tool has an updated `-u` option and a changed summary line.
```Shell
assembleg -u
```
--------------------------------
### Nauty 2.5: New Macros and Procedures
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Details new macros defined in nauty.h and new procedures introduced in nauty 2.5, providing simplified interfaces for graph operations.
```APIDOC
New macros defined in nauty.h:
COUNTER_FMT
PRINT_COUNTER
SETWORDSNEEDED
ADDONEARC
ADDONEEDGE
EMPTYGRAPH
New procedures:
densenauty() (in naugraph.c): Simplified dense graph interface.
sparsenauty() (in nausparse.c): Simplified sparse graph interface.
writegroupsize() (in nautil.c): Writes two-part group size.
copy_sg() (in nausparse.c): Makes a copy of a sparse graph.
Note: densenauty() and sparsenauty() are now the recommended ways to call nauty from a program.
```
--------------------------------
### genktreeg: New k-tree Generator
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Introduces `genktreeg`, a new tool specifically designed for generating k-trees.
```APIDOC
genktreeg: New generator for k-trees.
```
--------------------------------
### genspecialg: Generate Wheel Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-w#` option generates a wheel graph with a specified number of spokes.
```Shell
genspecialg -w#
```
--------------------------------
### Nauty Utility `multig` `vcolg` Output Integration
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `multig` utility now includes a new option, `-V`, which enables it to read the `-T` output from `vcolg`. This integration streamlines workflows involving graph coloring and multi-graph operations. Additionally, the output code for `multig` has been optimized for faster performance.
```APIDOC
multig new option:
-V: reads the -T output of vcolg.
```
--------------------------------
### Dump Schreier Structures to File (pynauty)
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Writes a complete description of the group's internal Schreier structures to the specified file pointer. This is useful for debugging or persistent storage of the group's state.
```APIDOC
dumpschreier(FILE* f, gp, gens, n);
- Write to file f a complete description of the structures.
```
--------------------------------
### Nauty Utility `vcolg` Enhanced Coloring Options
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `vcolg` utility has been improved with new options that allow bounding the number of vertices of each color and bounding the vertex degrees for each color. These additions provide more granular control over graph coloring constraints. The output code has also been made faster.
```APIDOC
vcolg new options:
Bounding the number of vertices of each colour.
Bounding the vertex degrees for each colour.
```
--------------------------------
### Force Local Compilation of Pynauty
Source: https://github.com/pdobsan/pynauty/blob/main/README.md
Command to explicitly force pip to build the pynauty extension module from source locally, even if pre-built binary wheels are available. This is useful for development or specific environment requirements.
```bash
pip install --no-binary pynauty pynauty
```
--------------------------------
### Performance Improvement: genbg for Trees
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `genbg` tool has received performance optimizations, making it faster when generating trees.
```APIDOC
genbg: Improved performance for tree generation.
```
--------------------------------
### Nauty 2.5: Utility Enhancements
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Summarizes updates to existing nauty utilities like listg, labelg, countg/pickg, genrang, genbg, directg, and shortg, adding new features and formats.
```APIDOC
listg: Add -b (Bliss format), -G (GRAPE format), -y/-Y (dotty format), -H (HCP format).
labelg: Add -t (Traces) and -i16 (refinvar).
countg/pickg: Add -m (vertices of min degree), -M (vertices of max degree), -H (induced cycles), -K (number of maximal independent sets).
genrang: Add -t (tree).
genbg: Add -A (antichain); makefile can also make genbgL for larger sizes.
directg: Add PROCESS feature.
shortg: Add -S (use sparse nauty), -t (use traces), i16 (refinvar).
```
--------------------------------
### Nauty Utility `genrang` Markov Chain Option
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `genrang` utility introduces a new option, `-M#`, to be used in conjunction with `-d` for pseudo-random regular graphs. This option runs a Markov chain for `#*n` steps, aiming to produce a more uniform distribution of graphs than `-d` alone by approaching a uniform limit distribution.
```APIDOC
genrang option:
-M#: used with -d (pseudo-random regular graphs).
Runs a Markov chain for #*n steps for more uniform distribution.
```
--------------------------------
### C Declarations for Schreier Structures
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Essential C declarations for including the Schreier header file and defining pointers to the main Schreier structure and the stored generators, which are fundamental for interacting with the library.
```C
#include "schreier.h"
schreier *gp; /* This will point to the Schreier structure */
permnode *gens; /* This will point to the stored generators */
```
--------------------------------
### New C Procedures in `naututil.c` and Multi-Word Set Support
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `naututil.c` file introduces `settolist()` and `listtoset()` for converting between sets and lists of integers. Additionally, several existing functions (`nextelement`, `permset`, `setsize`, `setinter`, `settolist`, `listtoset`) now support multi-word sets, even when Nauty is compiled with `MAXN=WORDSIZE`, enhancing flexibility for larger sets.
```C
// naututil.c new procedures:
void settolist(); // converts a set into a list of integers
void listtoset(); // converts a list of integers into a set
// Multi-word set support:
// Functions nextelement(), permset(), setsize(), setinter(), settolist() and listtoset()
// now work for multi-word sets even if nauty is compiled with MAXN=WORDSIZE.
```
--------------------------------
### countg/pickg: Count Pentagons
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-P` option in `countg`/`pickg` now allows counting pentagons, applicable only to undirected graphs.
```Shell
countg/pickg -P
```
--------------------------------
### Nauty 2.6: Core Library Enhancements
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Highlights core library updates in nauty 2.6, including a new user hook, increased vertex limit, and leveraging modern processor instructions for performance.
```APIDOC
nauty has an extra hook: usercanonproc().
Maximum number of vertices: Now 2 billion.
Modern processor instructions: Configuration script now looks for and attempts to use POPCNT and CLZ* if possible.
```
--------------------------------
### Nauty 2.5: Core Library Enhancements
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Overview of fundamental changes in nauty 2.5, including Traces integration, thread-safety, build system improvements, type system revisions, and performance optimizations.
```APIDOC
Add Traces: Main files traces.h and traces.c, with changes to dreadnaut.c and nausparse.c.
Allow thread-safe storage: If requested by configure --enable-tls and available.
Makefile now creates static libraries: e.g., nauty.a, in addition to object files.
Remove old types: permutation, nvector, np2vector, shortish are now int.
Add schreier.h, schreier.c: Optional use of random Schreier method in nauty; not optional in Traces.
Add large-file support: No longer a 4GB limit on files on 32-bit systems.
Use gcc extensions: Like __builtin_clz() if available and not disabled by configure --disable-clz.
Use FIRSTBITNZ: Instead of FIRSTBIT if argument is certain to be nonzero.
Options structure: New boolean field 'schreier'.
```
--------------------------------
### Nauty 2.5: Header and Structure Updates
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Describes changes to sparsegraph.h, sparsegraph.c, gtools.h, and gtools.c, including type changes for large graph support and corrected definitions.
```APIDOC
sparsegraph fields: nde and *v changed type from int to size_t to allow more than 2^31 edges on 64-bit hardware.
sparsegraph.h and sparsegraph.c:
Corrected definition of SG_DECL.
Added DEFAULTOPTIONS_SPARSEDIGRAPH.
Added comparelab_tr(), testcanlab_tr(), updatecan_tr() for Traces.
gtools.h and gtools.c:
gtools.h now made from gtools-h.in by configure.
Updated G6LEN() to work for larger graphs.
Use large-file functions fseeko(), ftello() if possible.
Most tools now use random number generator in naurng.c instead of rng.c.
gutils.h, gutil1.c and gutil2.c:
New procedures: maxcliques(), indpathcount1(), indcyclecount1(), indcyclecount().
Invariants:
Corrected getbigcells(), making small changes to invariants celltrips, cellquins and refinvar.
```
--------------------------------
### Pynauty Graph Creation and Automorphism Group Calculation
Source: https://github.com/pdobsan/pynauty/blob/main/README.md
Demonstrates interactive usage of the pynauty library to create a graph, connect vertices, print its representation, calculate its automorphism group, and apply vertex coloring to observe changes in the automorphism group. It showcases how graph modifications affect the automorphism group.
```python
>>> from pynauty import *
>>> g = Graph(5)
>>> g.connect_vertex(0, [1, 2, 3])
>>> g.connect_vertex(2, [1, 3, 4])
>>> g.connect_vertex(4, [3])
>>> print(g)
Graph(number_of_vertices=5, directed=False,
adjacency_dict = {
0: [1, 2, 3],
2: [1, 3, 4],
4: [3],
},
vertex_coloring = [
],
)
>>> autgrp(g)
([[3, 4, 2, 0, 1]], 2.0, 0, [0, 1, 2, 0, 1], 3)
>>>
>>> g.connect_vertex(1, [3])
>>> autgrp(g)
([[0, 1, 3, 2, 4], [1, 0, 2, 3, 4]], 4.0, 0, [0, 0, 2, 2, 4], 3)
>>>
>>> g.set_vertex_coloring([set([3])])
>>> print(g)
Graph(number_of_vertices=5, directed=False,
adjacency_dict = {
0: [1, 2, 3],
1: [3],
2: [1, 3, 4],
4: [3],
},
vertex_coloring = [
set([3]),
set([0, 1, 2, 4]),
],
)
>>> autgrp(g)
([[1, 0, 2, 3, 4]], 2.0, 0, [0, 0, 2, 3, 4], 4)
```
--------------------------------
### genspecialg: Generate Antiprism Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-a#` option generates an antiprism graph with a specified number of vertices. For prisms, use `-G-2,#`.
```Shell
genspecialg -a#
```
--------------------------------
### Nauty Utility `countg`/`pickg` New Options
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
This section details new command-line options added to the `countg` and `pickg` utilities since version 2.7. These options allow for counting specific graph properties like 2-cycles, non-edges, independent sets of size 3, sources, sinks, 4-cycles, and diamonds. Options can be separated by commas, e.g., `--e,ee`.
```APIDOC
countg/pickg options:
-LL: 2-cycles (of digraphs)
-ee: non-edges (including non-loops for digraphs)
-TT: independent sets of size 3
-x: sources
-xx: sinks
-W: 4-cycles (undirected only so far)
-WW: diamonds (4-cycles with diagonal), only undirected
```
--------------------------------
### countneg: Efficient Graph Counting by Edges/Vertices
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Introduces `countneg`, a new utility designed for faster and more space-efficient counting of graphs based on their number of edges and/or vertices. It is an alternative to `countg` for this specific purpose, though it lacks some advanced features like incremental sparse6 input.
```APIDOC
countneg:
Purpose: New utility for counting graphs by number of edges and/or vertices.
Features:
- Faster and more space-efficient than countg for this purpose.
- Does not support incremental sparse6 input or options like -p, -f.
```
--------------------------------
### genspecialg: Generate Moebius Ladder Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-l#` option generates a Moebius ladder graph with a specified number of vertices.
```Shell
genspecialg -l#
```
--------------------------------
### Nauty 2.5: Introduction of New Utilities
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Introduces new standalone utilities added in nauty 2.5 for graph relabeling, line graph computation, subdivision graphs, and edge orientation.
```APIDOC
ranlabg: Randomly relabel graphs.
linegraphg: Compute linegraphs.
subdivideg: Compute subdivision graphs.
watercluster2: Orient edges of graphs (by Gunnar Brinkmann).
```
--------------------------------
### Nauty Utility `directg` Acyclic Orientation Option
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `directg` utility now features a new option, `-a`, specifically for generating acyclic orientations of graphs. This enhances its capabilities for directed graph manipulation.
```APIDOC
directg new option:
-a: for acyclic orientations.
```
--------------------------------
### genspecialg: Generate Triangular Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-L#` option generates a triangular graph L(K_#).
```Shell
genspecialg -L#
```
--------------------------------
### Find Permutation in Circular List (pynauty)
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Searches a circular list of `permnode` structures for a permutation identical to the given integer array `p`. It returns a pointer to the matching `permnode` if found, otherwise it returns NULL.
```APIDOC
permnode *findpermutation(permnode *gens, int *p, int n)
- return a pointer to the permnode in the circular list which
is identical to p, if it exists. Otherwise return NULL.
```
--------------------------------
### New C Procedures in `gutil2.c`
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `gutil2.c` file adds three new C procedures: `digoncount` to count 2-cycles in digraphs, `numind3sets1` for counting independent sets of size 3 (currently for `n <= WORDSIZE`), and `numsquares` for counting 4-cycles in undirected graphs. These expand the library's graph enumeration capabilities.
```C
// gutil2.c new procedures:
int digoncount(graph *g, int m, int n); // counts 2-cycles in a digraph
int numind3sets1(graph *g, int n); // counts independent sets of size 3 (for n <= WORDSIZE)
int numsquares(graph *g, int m, int n); // counts 4-cycles in undirected graphs
```
--------------------------------
### genrang: Generate Pseudo-Random Regular Loop-Free Digraphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `genrang` tool, when used with options `-d` and `-z`, can now generate pseudo-random regular loop-free digraphs.
```Shell
genrang -d -z
```
--------------------------------
### Nauty Utility `listg` Signless Laplacian Option
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `listg` utility now includes a new option, `-S`, which can be used in conjunction with `-M` or `-W` to write the signless Laplacian of the graph. This provides additional graph property output capabilities.
```APIDOC
listg option:
-S: used with -M or -W to write the signless Laplacian.
```
--------------------------------
### genspecialg: Generate Antiregular Graphs
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-A#` option generates an antiregular graph with a specified number of vertices.
```Shell
genspecialg -A#
```
--------------------------------
### countg/pickg: Renamed Options -ii and -jj
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The options `-I` and `-J` in `countg`/`pickg` have been replaced by `-ii` and `-jj` to accommodate future features.
```APIDOC
countg/pickg options:
-ii: Replaces -I
-jj: Replaces -J
```
--------------------------------
### Estimate Group Order (pynauty)
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Estimates the size of the group using a base or base-less-one approach based on fixed elements. The function takes pointers for group size components (grpsize1 as double, grpsize2 as int) and returns a probabilistic product of orbit sizes, which is correct with some probability.
```APIDOC
grouporder(fix, nfix, gp, &gens, &grpsize1, &grpsize2, n);
- Make an estimate of the group size using the base or
base-less-one fix[0..nfix-1]. grpsize1 is double and
grpsize2 is int, as in nauty.h. The value returned is
the product of the orbit sizes at each level times the
largest orbit size at the end. Correct with some
probability.
```
--------------------------------
### Incremental Sparse6 Format Specification
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/formats.txt
Details the incremental sparse6 format, an extension to the standard sparse6 format designed for efficient representation of graphs that are similar to a previously defined graph. It specifies the byte encoding, required delimiters, and how edges represent symmetric differences from the preceding graph.
```APIDOC
Each graph occupies one text line. Except for the first character
and end-of-line characters, each byte has the form 63+x, where
0 <= x <= 63. The byte encodes the six bits of x.
The encoded graph consists of:
(1) The character ';'.
(2) A list of edges.
(3) end-of-line
This cannot appear as the first graph in a file. The number of vertices
is taken to be equal to the number of vertices in the previous graph.
The list of edges specifies the symmetric difference of this graph and
the previous graph. It is encoded exactly the same as part (3) of
sparse6 format.
Loops are supported, but not multiple edges.
```
--------------------------------
### countg/pickg: Chromatic Number and Index Selection
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
New options `-N` and `-NN` in `countg`/`pickg` allow selection based on chromatic number and chromatic index, respectively. `-A` selects by class (chromatic index - maximum degree + 1). Loops add 1 to vertex degree in this context. Supports up to WORDSIZE colours.
```APIDOC
countg/pickg options:
-N: Select by chromatic number
-NN: Select by chromatic index
-A: Select by class (chromatic index - maximum degree + 1)
Note: Loops add 1 to vertex degree. Max WORDSIZE colours allowed.
```
--------------------------------
### Bug Fix: stronglyconnected() in gutils2.c
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
A bug causing crashes in the `stronglyconnected()` function within `gutils2.c`, used by `pickg`/`countg -C`, due to an uninitialized variable has been fixed.
```C
/* Fix for uninitialized variable in stronglyconnected() */
// Used by pickg/countg -C
```
--------------------------------
### countg/pickg: Connectivity and Edge-Connectivity Selection
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Options `-G` and `-GG` enable selection based on connectivity and edge-connectivity, respectively. Digraphs are supported, with connectivity defined as n-1 for K_n or minimum vertex separator size. 1-connectivity is equivalent to strong connectivity. The older `-c` switch remains for undirected graphs.
```APIDOC
countg/pickg options:
-G: Select by connectivity
-GG: Select by edge-connectivity
-c: (old) Select by connectivity for undirected graphs (2 means 2 or more)
```
--------------------------------
### APIDOC: Finishing and Cleanup Operations
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Covers functions for the final stages of group manipulation and memory management. This includes deleting redundant generators, freeing the primary Schreier and generator structures, and optionally releasing all dynamic memory allocated by the Schreier code.
```APIDOC
deleteunmarked(&gens)
- Deletes some redundant generators, guaranteeing those left generate the group.
- This invalidates the Schreier structure, so call freeschreier(&gp, NULL) afterwards.
freeschreier(&gp, &gens)
- Frees these two structures.
- Do this before using (gp,gens) for another group.
schreier_freedyn()
- Frees all the dynamic memory allocated by the Schreier code.
- This is optional since the same dynamic memory will be reused.
```
--------------------------------
### Fixes for gentreeg and gentourng
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Corrected output for `gentreeg` with n=2 and fixed a table shift. Also notes a specific usage of `gentourng`.
```Shell
gentourng -c 2
```
--------------------------------
### Nauty Utility `gentreeg` Enhancements
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `gentreeg` utility now supports generating forests within a specified range of vertices. A new option, `-i`, has been added to exclude vertices of degree 2. The output for `n=1` with `diameter > 0` has also been corrected.
```APIDOC
gentreeg enhancements:
Allows a range of number of vertices.
Example: forests on 15 vertices with no isolated vertices:
gentreeg 2:15 | assembleg -n15cL
New option -i: no vertices of degree 2.
```
--------------------------------
### Random Number Generator Update (Marsaglia 64-bit)
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Don Knuth's 30-bit random number generator has been replaced by George Marsaglia's 64-bit generator. The interface remains similar, but seeds and values are now `unsigned long long`. A new function `ran_init_2(seed1, seed2)` allows 128-bit initialization. The old generator is still available in `naurng_knuth.[hc]`.
```C
/* Old Knuth 30-bit RNG replaced by Marsaglia 64-bit RNG */
unsigned long long seed, value;
void ran_init(unsigned long long seed);
void ran_init_2(unsigned long long seed1, unsigned long long seed2);
unsigned long long ran_next();
// Old generator still available:
// naurng_knuth.h
// naurng_knuth.c
```
--------------------------------
### genspecialg: Generate Extended Hypercubes
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-Q#,#` option extends the hypercube generation (`-Q#`). The second parameter, if provided, specifies the Hamming distance that defines edges, defaulting to 1.
```Shell
genspecialg -Q#,#
genspecialg -Q#
```
--------------------------------
### APIDOC: Add Permutations and Generators
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/schreier.txt
Describes three functions for incorporating permutations into the group's generator set or Schreier structure. These functions vary in how they update the Schreier structure and their guarantees regarding the uniqueness or utility of the added generator.
```APIDOC
addpermutation(&gens, p, n)
- Adds p to the stored generators without updating the Schreier structure.
addgenerator(&gp, &gens, p, n)
- Filters p through the Schreier structure, adding p or an equivalent generator if it is not found to be in the group already.
- Returns FALSE if p was found to be in the group and useless, otherwise TRUE.
condaddgenerator(&gp, &gens, p, n)
- Same as addgenerator() except that it guarantees to never add a generator which is identical to a previous generator.
- Might not notice if it is in the group generated by the previous generators.
```
--------------------------------
### New C Procedure in `gtnauty.c`
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `gtnauty.c` file now includes a new C procedure, `breakcellwt()`. This function is designed to split a cell based on weights assigned to its vertices, offering more advanced partitioning capabilities.
```C
// gtnauty.c new procedure:
void breakcellwt(); // splits a cell according to weights on the vertices
```
--------------------------------
### countg/pickg: Boolean Sort Key Variants
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
New boolean variants for sort keys allow filtering based on properties like k-colourability (`--N#`), k-edge colourability (`--NN#`), k-connectivity (`--G#`), and k-edge connectivity (`--GG#`).
```Shell
countg/pickg options:
--N#: #-colourable (chromatic number <= #)
--NN#: #-edge colourable
--G#: #-connected (connectivity >= #)
--GG#: #-edge connected
```
--------------------------------
### Bit Vector Encoding for Graph Formats
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/formats.txt
This section details the method for representing a bit vector of length 'k' as a string of bytes. It involves padding the vector to a multiple of 6 bits, splitting it into 6-bit groups, and then converting each group into a byte by adding 63 to its big-endian binary value.
```APIDOC
Bit vector x of length k:
(1) Pad on the right with 0 to make the length a multiple of 6.
Example: 1000101100011100 -> 100010110001110000
(2) Split into groups of 6 bits each.
Example: 100010 110001 110000
(3) Add 63 to each group, considering them as bigendian binary numbers.
Example: 97 112 111
Result: Stored one byte per value.
R(x): Representation of x as a string of bytes.
```
--------------------------------
### ransubg: Random Subgraph/Subdigraph Extraction
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
Introduces `ransubg`, a new utility for extracting random subgraphs or subdigraphs from an input graph. It also supports generating random orientations.
```APIDOC
ransubg: New tool to extract random subgraph/subdigraph from input graph.
Supports random orientations.
```
--------------------------------
### countg/pickg: Determine k-tree Property
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/changes24-28.txt
The `-kk` option determines the `k` for which a graph is a k-tree, returning 0 if not a k-tree. For complete graphs, it's tabulated as an n-tree but matches both n-1 and n.
```Shell
countg/pickg -kk
```
--------------------------------
### Digraph6 Format Specification
Source: https://github.com/pdobsan/pynauty/blob/main/src/nauty2_8_8/formats.txt
Describes the digraph6 format for representing simple directed graphs, including its supported data types, optional header, standard file extension, and the core encoding method which uses an adjacency matrix converted into a bit vector.
```APIDOC
Data type:
simple directed graphs (allowing loops) of order 0 to 68719476735.
Optional Header:
>>digraph6<< (without end of line!)
File name extension:
.d6
One graph:
Suppose G has n vertices. Write the adjacency matrix of G
as a bit vector x of length n^2, row by row.
Then the graph is represented as '&' N(n) R(x).
The character '&' (decimal 38) appears as the first character.
```