Solve the Triangle-Free Problem for an undirected graph encoded in DIMACS format.
Project description
Aegypti: Triangle-Free Solver
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
- Go to the package directory to use the benchmarks:
git clone https://github.com/frankvegadelgado/finlay.git
cd finlay
- 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 [-a] [-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
-v, --verbose anable 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 [-a] [-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
-v, --verbose anable 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] [-a] [-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
-w, --write write the generated random matrix to a file in the current directory
-v, --verbose anable 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.
Code
- Python code by Frank Vega.
License
- MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aegypti-0.4.0.tar.gz.
File metadata
- Download URL: aegypti-0.4.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f7b9f599ed1b3fd9234315e254cf94c23a87ca9dd1bde0253b9eaf1522ed84c
|
|
| MD5 |
790de47a11b12b45bafd1d7d58ec4b76
|
|
| BLAKE2b-256 |
1fc071f665bbe13254fd4d5686e6e15a5a042274ec7d4ec6ab4481e982b21715
|
Provenance
The following attestation bundles were made for aegypti-0.4.0.tar.gz:
Publisher:
publish.yml on frankvegadelgado/finlay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aegypti-0.4.0.tar.gz -
Subject digest:
5f7b9f599ed1b3fd9234315e254cf94c23a87ca9dd1bde0253b9eaf1522ed84c - Sigstore transparency entry: 1239236373
- Sigstore integration time:
-
Permalink:
frankvegadelgado/finlay@8f55f7d453ac916a94ac5c79d36257e6a5e0b3d2 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/frankvegadelgado
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8f55f7d453ac916a94ac5c79d36257e6a5e0b3d2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aegypti-0.4.0-py3-none-any.whl.
File metadata
- Download URL: aegypti-0.4.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7894bd0b9c46538f46082a29986290af239eaff4e68e3b50b9920eed89346ab
|
|
| MD5 |
e3cbdf04ba73e8aa453a2fae0f25ffa7
|
|
| BLAKE2b-256 |
f815a845e5533e1393b9b70b66004de250d9483689d85205bd76c3172094a8a8
|
Provenance
The following attestation bundles were made for aegypti-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on frankvegadelgado/finlay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aegypti-0.4.0-py3-none-any.whl -
Subject digest:
b7894bd0b9c46538f46082a29986290af239eaff4e68e3b50b9920eed89346ab - Sigstore transparency entry: 1239236374
- Sigstore integration time:
-
Permalink:
frankvegadelgado/finlay@8f55f7d453ac916a94ac5c79d36257e6a5e0b3d2 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/frankvegadelgado
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8f55f7d453ac916a94ac5c79d36257e6a5e0b3d2 -
Trigger Event:
release
-
Statement type: