Skip to main content

Aegypti: Triangle-Free Solver

Honoring the Memory of Carlos Juan Finlay (Pioneer in the research of yellow fever)

This work builds upon The Aegypti Algorithm.


Triangle-Free Problem

The Triangle-Free problem is a fundamental decision problem in graph theory. Given an undirected graph, the problem asks whether it's possible to determine if the graph contains no triangles (cycles of length 3). In other words, it checks if there exists a configuration where no three vertices are connected by edges that form a closed triangle.

This problem is important for various reasons:

  • Graph Analysis: It's a basic building block for more complex graph algorithms and has applications in social network analysis, web graph analysis, and other domains.
  • Computational Complexity: It serves as a benchmark problem in the study of efficient algorithms for graph properties. While the naive approach has a time complexity of $O(n^3)$, there are more efficient algorithms with subcubic complexity.

Understanding the Triangle-Free problem is essential for anyone working with graphs and graph algorithms.

Problem Statement

Input: A Boolean Adjacency Matrix $M$.

Question: Does $M$ contain no triangles?

Answer: True / False

Example Instance: 5 x 5 matrix

c1 c2 c3 c4 c5
r1 0 0 1 0 1
r2 0 0 0 1 0
r3 1 0 0 0 1
r4 0 1 0 0 0
r5 1 0 1 0 0

The input for undirected graph is typically provided in DIMACS format. In this way, the previous adjacency matrix is represented in a text file using the following string representation:

p edge 5 4
e 1 3
e 1 5
e 2 4
e 3 5

This represents a 5x5 matrix in DIMACS format such that each edge $(v,w)$ appears exactly once in the input file and is not repeated as $(w,v)$. In this format, every edge appears in the form of

e W V

where the fields W and V specify the endpoints of the edge while the lower-case character e signifies that this is an edge descriptor line.

Example Solution:

Triangle Found (1, 3, 5): In Rows 3 & 5 and Columns 1 & 3

Compile and Environment

Install Python >=3.12.

Install Aegypti's Library and its Dependencies with:

pip install aegypti

Execute

  1. Go to the package directory to use the benchmarks:
git clone https://github.com/frankvegadelgado/finlay.git
cd finlay
  1. Execute the script:
triangle -i .\benchmarks\testMatrix1

utilizing the triangle command provided by Aegypti's Library to execute the Boolean adjacency matrix finlay\benchmarks\testMatrix1. The file testMatrix1 represents the example described herein. We also support .xz, .lzma, .bz2, and .bzip2 compressed text files.

The console output will display:

Smart Algorithm for testMatrix1: Triangle Found (1, 3, 5)

which implies that the Boolean adjacency matrix finlay\benchmarks\testMatrix1 contains a triangle combining the nodes (1, 3, 5).


Command Options

To display the help message and available options, run the following command in your terminal:

triangle -h

This will output:

usage: triangle [-h] -i INPUTFILE [-b] [-c] [-v] [-l] [--version]

Solve the Triangle-Free Problem for an undirected graph encoded in DIMACS format.

options:
  -h, --help            show this help message and exit
  -i INPUTFILE, --inputFile INPUTFILE
                        input file path
  -b, --bruteForce      compare with a brute-force approach using matrix multiplication
  -c, --combinatorial   compare with the classical Chiba-Nishizeki O(n + m^{3/2}) adjacency-intersection baseline
  -v, --verbose         enable verbose output
  -l, --log             enable file logging
  --version             show program's version number and exit

This output describes all available options.

Batch Execution

Batch execution allows you to solve multiple graphs within a directory consecutively.

To view available command-line options for the batch_triangle command, use the following in your terminal or command prompt:

batch_triangle -h

This will display the following help information:

usage: batch_triangle [-h] -i INPUTDIRECTORY [-b] [-c] [-v] [-l] [--version]

Solve the Triangle-Free Problem for all undirected graphs encoded in DIMACS format and stored in a directory.

options:
  -h, --help            show this help message and exit
  -i INPUTDIRECTORY, --inputDirectory INPUTDIRECTORY
                        Input directory path
  -b, --bruteForce      compare with a brute-force approach using matrix multiplication
  -c, --combinatorial   compare with the classical Chiba-Nishizeki O(n + m^{3/2}) adjacency-intersection baseline
  -v, --verbose         enable verbose output
  -l, --log             enable file logging
  --version             show program's version number and exit

The Finlay Testing Application

A command-line tool, test_triangle, has been developed for testing algorithms on randomly generated, large sparse matrices. It accepts the following options:

usage: test_triangle [-h] -d DIMENSION [-n NUM_TESTS] [-s SPARSITY] [-b] [-c] [-w] [-v] [-l] [--version]

The Finlay Testing Application using randomly generated, large sparse matrices.

options:
  -h, --help            show this help message and exit
  -d DIMENSION, --dimension DIMENSION
                        an integer specifying the dimensions of the square matrices
  -n NUM_TESTS, --num_tests NUM_TESTS
                        an integer specifying the number of tests to run
  -s SPARSITY, --sparsity SPARSITY
                        sparsity of the matrices (0.0 for dense, close to 1.0 for very sparse)
  -b, --bruteForce      compare with a brute-force approach using matrix multiplication
  -c, --combinatorial   compare with the classical Chiba-Nishizeki O(n + m^{3/2}) adjacency-intersection baseline
  -w, --write           write the generated random matrix to a file in the current directory
  -v, --verbose         enable verbose output
  -l, --log             enable file logging
  --version             show program's version number and exit

This tool is designed to benchmark algorithms for sparse matrix operations.

It generates random square matrices with configurable dimensions (-d), sparsity levels (-s), and number of tests (-n). While a comparison with a brute-force matrix multiplication approach is available, it's recommended to avoid this for large datasets due to performance limitations. Additionally, the generated matrix can be written to the current directory (-w), and verbose output or file logging can be enabled with the (-v) or (-l) flag, respectively, to record test results.


Car Experiment

The car/ directory contains a reproducible comparison experiment that runs four triangle-detection routines against an independent exact triangle oracle. find_triangle_coordinates is run in both of its modes:

Subject Function Notes
Aegypti-safe find_triangle_coordinates(graph, fallback=True) Unconditionally complete; falls back to Chiba–Nishizeki when the dense branch is inconclusive (O(n + m^{3/2}) worst case).
Aegypti-fast find_triangle_coordinates(graph, fallback=False) Uniform O(n^2) one-sided certifier; the dense branch may return None on a triangle-containing graph. Default mode.
Chiba–Nishizeki find_triangle_chiba_nishizeki(graph) Exact, O(n + m^{3/2}).
Matrix multiplication is_triangle_free_brute_force(sparse_matrix) Reference baseline.

car/car_experiment.py builds a deterministic benchmark (~12,000 instances, fixed seed) spanning both regimes of the Aegypti dispatch — sparse (m ≤ ⌈n^{4/3}⌉) and dense (m > ⌈n^{4/3}⌉). It combines random/structured families (sparse and dense Erdős–Rényi, triangle-free bipartite, planted-triangle, planted-clique, structured), adversarial dense small-clique families (complete tripartite ω=3, complete 4-partite ω=4, balanced bipartite + one edge ω=3) that stress the fast dense branch, and an exhaustive sweep of all graphs on ≤ 7 vertices (Graph Atlas). Each instance is scored against an exact neighbourhood-intersection oracle; every witness is checked to be a genuine triangle; and for dense instances the Hvala-cover diagnostics (|C|, |V∖C|, ω(G), |C|/OPT, fallback flag) are recorded.

Run it from the repository root:

python car/car_experiment.py            # full suite
python car/car_experiment.py --quick    # smaller, faster sweep

It writes car_experiment.json, car_summary.csv, car_by_instance.csv, and a human-readable CAR_REPORT.md into the car/ folder. The key column aegypti_fast_miss flags any instance where the oracle finds a triangle but the fast dense branch returns none — the empirical content of the Hvala independent-set hypothesis. Aegypti-safe converts every such case into a correct answer through its fallback. (If the installed package predates the fallback parameter, both variants reduce to the default call.)


Code

  • Python code by Frank Vega.

License

  • MIT.

Release files for aegypti 0.4.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aegypti 0.4.6
File Size Uploaded
aegypti-0.4.6.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aegypti 0.4.6
File Interpreter ABI Platform
aegypti-0.4.6-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / aegypti-0.4.6.tar.gz

Download URL aegypti-0.4.6.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
76e3d0aec1f3dd72b9c96a50fab3eaeeae0e6a1d053df772ba4b9a8adbbe3ab0
BLAKE2b-256 checksum
How to use checksums
d8e9165570f77afcfa961407bf3ec6201aacdc72921cccb328fca8823976b58b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / aegypti-0.4.6-py3-none-any.whl

Download URL aegypti-0.4.6-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ac85e4f04c35527582e63a7090875b7df4a42c37a8e6ee69743605ae2e25d66
BLAKE2b-256 checksum
How to use checksums
ea03237569f11bb8468857706ee4cbb1d0f3b289132f6598aa9ac61383825c51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

This release

0.4.6 This release

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page