Adonai: Approximate Chromatic Number Solver

Through him, and with him, and in him (This formula emphasizes the Trinitarian nature of the liturgy).

This work builds upon The Adonai Algorithm.


The Minimum Chromatic Number (Graph Coloring) Problem

1. Problem Definition

The Minimum Chromatic Number Problem, more commonly known as the Graph Coloring Problem, is a classic problem in computer science and graph theory.

Example: A map of countries can be modeled as a graph (each country is a vertex, and an edge exists between adjacent countries). The problem of coloring the map with the fewest colors so no two adjacent countries share a color is precisely the graph coloring problem. The famous Four Color Theorem proves that χ(G) ≤ 4 for any planar graph.

2. Computational Complexity: NP-Hardness

The decision version of the problem ("Given a graph G and an integer k, is χ(G) ≤ k?") is NP-complete.

This NP-hardness implies that there is no known algorithm that can find the chromatic number of an arbitrary graph in polynomial time. Finding the exact chromatic number for large graphs is computationally intractable.

3. Approximation and Heuristics

Since finding the optimal solution is infeasible for large instances, much research focuses on approximation algorithms and heuristics.

Approximation Hardness

The problem is notoriously hard to even approximate.

Common Approximation Algorithms and Heuristics

Despite the negative approximation results, many algorithms work well in practice for many graphs, though they offer no worst-case guarantees.

  1. Greedy Coloring (and variants):

  2. DSatur (Degree of Saturation):

  3. Using a Maximum Independent Set:

  4. Advanced Methods:

4. Impact and Applications

The graph coloring problem is not just a theoretical puzzle; it has profound practical implications across numerous fields.


Problem Statement

Input: A Boolean Adjacency Matrix $M$.

Answer: Find a Minimum Chromatic Number.

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:

Chromatic Number Found (1:1, 2:1, 4:2, 3:2, 5:3): An optimal coloring is achieved by assigning color 1 to nodes 1 and 2, color 2 to nodes 3 and 4, and color 3 to node 5.


Compile and Environment

Prerequisites

Installation

pip install adonai

Execution

  1. Clone the repository:

    git clone https://github.com/frankvegadelgado/adonai.git
    cd adonai
    
  2. Run the script:

    salve -i ./benchmarks/testMatrix1
    

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

    Example Output:

    testMatrix1: Chromatic Number Found (1:1, 2:1, 4:2, 3:2, 5:3)
    

    This indicates a valid 3-coloring, meaning the graph's chromatic number is at most 3.


Chromatic Number Size

Use the -c flag to count the chromatic number:

salve -i ./benchmarks/testMatrix2 -c

Output:

testMatrix2: Chromatic Number Size 4

Command Options

Display help and options:

salve -h

Output:

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

Compute the Approximate Chromatic Number for undirected graph encoded in DIMACS format.

options:
  -h, --help            show this help message and exit
  -i INPUTFILE, --inputFile INPUTFILE
                        input file path
  -a, --approximation   enable comparison with a polynomial-time approximation approach within a factor of at most 2
  -b, --bruteForce      enable comparison with the exponential-time brute-force approach
  -c, --count           calculate the size of the chromatic number
  -v, --verbose         anable verbose output
  -l, --log             enable file logging
  --version             show program's version number and exit

Batch Execution

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

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

batch_salve -h

This will display the following help information:

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

Compute the Approximate Chromatic Number 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
  -a, --approximation   enable comparison with a polynomial-time approximation approach within a factor of at most 2
  -b, --bruteForce      enable comparison with the exponential-time brute-force approach
  -c, --count           calculate the size of the chromatic number
  -v, --verbose         anable verbose output
  -l, --log             enable file logging
  --version             show program's version number and exit

Testing Application

A command-line utility named test_salve is provided for evaluating the Algorithm using randomly generated, large sparse matrices. It supports the following options:

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

The Adonai 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)
  -a, --approximation   enable comparison with a polynomial-time approximation approach within a factor of at most 2
  -b, --bruteForce      enable comparison with the exponential-time brute-force approach
  -c, --count           calculate the size of the chromatic number
  -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

Code


Complexity

+ We present a polynomial-time algorithm that achieves an (sqrt(n) * ln(n))-approximation for the Minimum Chromatic Number problem. This provides strong evidence that P = NP by efficiently solving a computationally hard problem with near-optimal solutions.

License