Skip to main content

Salvador: Approximate Vertex Cover Solver

Current version: v0.1.3

In Loving Memory of Salvador Vega (The Grandfather I Never Knew)

This work builds upon The Salvador Algorithm.


The Minimum Vertex Cover Problem

The Minimum Vertex Cover (MVC) problem is a classic optimization problem in computer science and graph theory. It involves finding the smallest set of vertices in a graph that covers all edges, meaning at least one endpoint of every edge is included in the set.

Formal Definition

Given an undirected graph $G = (V, E)$, a vertex cover is a subset $V' \subseteq V$ such that for every edge $(u, v) \in E$, at least one of $u$ or $v$ belongs to $V'$. The MVC problem seeks the vertex cover with the smallest cardinality.

Importance and Applications

  • Theoretical Significance: MVC is a well-known NP-hard problem, central to complexity theory.
  • Practical Applications:
    • Network Security: Identifying critical nodes to disrupt connections.
    • Bioinformatics: Analyzing gene regulatory networks.
    • Wireless Sensor Networks: Optimizing sensor coverage.
  • Maximum Independent Set: The complement of a vertex cover.
  • Set Cover Problem: A generalization of MVC.

Problem Statement

Input: A Boolean Adjacency Matrix $M$.

Answer: Find a Minimum Vertex Cover.

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:

Vertex Cover Found 1, 3, 4: Nodes 1, 3, and 4 constitute an optimal solution.


Compile and Environment

Prerequisites

  • Python ≥ 3.12

Installation

pip install salvador==0.1.3

Execution

  1. Clone the repository:

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

    vega -i ./benchmarks/testMatrix1
    

    utilizing the vega command provided by Salvador to execute the Boolean adjacency matrix salvador\benchmarks\testMatrix1. The file testMatrix1 represents the example described herein. We also support .xz, .lzma, .bz2, and .bzip2 compressed text files.

    Example Output:

    testMatrix1: Vertex Cover Found 1, 3, 4
    

    This indicates nodes 1, 3, 4 form a vertex cover.


Vertex Cover Size

Use the -c flag to count the nodes in the vertex cover:

vega -i ./benchmarks/testMatrix2 -c

Output:

testMatrix2: Vertex Cover Size 5

Command Options

Display help and options:

vega -h

Output:

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

Compute the Approximate Vertex Cover 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 vertex cover
  -v, --verbose         enable 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_vega command, use the following in your terminal or command prompt:

batch_vega -h

This will display the following help information:

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

Compute the Approximate Vertex Cover 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 vertex cover
  -v, --verbose         enable verbose output
  -l, --log             enable file logging
  --version             show program's version number and exit

Testing Application

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

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

The Salvador 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 vertex cover
  -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

Reproducibility Experiments (car/)

The car/ folder contains the experiment scripts. Each script writes its results next to itself as .json and .csv files.

How to run

Recommended: run every experiment quickly, on small graphs, with one command from the car/ folder:

cd car
python run_all.py --quick

Install the package and its dependencies, then run a script from the repository root:

pip install salvador==0.1.3
python car/car_strategies.py

The scripts also run from a clone of the repository without installing the package. Every script accepts -h to list its options, --quick for a shorter run and --timeout to limit the time spent on each graph.

To run all the experiments one after another, use car/run_all.py:

python car/run_all.py --quick                          # every experiment on small graphs (much shorter)
python car/run_all.py --quick --only strategies scaling # only some experiments
python car/run_all.py --list                           # list the experiments and their quick options
python car/run_all.py                                  # every experiment in full (hours)
python car/run_all.py --skip triangle_free mechanism   # full runs except some

Each experiment writes its own result files, and car/run_all_log.txt records the time and status of each one.

What each script does

Script What it does
car_ratio.py Measures the approximation ratio on small graphs with a known optimum and on large adversarial graphs.
car_ratio_timing.py Shows where the running time of car_ratio.py goes, strategy by strategy.
car_scaling.py Measures how the running time grows with the size of the graph.
car_strategies.py Reports which of the strategies c1...c15 finds the smallest cover, and how often.
car_c11_variants.py Compares the variants of strategy c11.
car_c10_bags.py Checks the bag sizes of the dynamic program of strategy c10.
car_c0_components.py Measures strategy c0 (component amplification of the split graph before the NetworkX minimum maximal matching): both index rules against c1, tau (or a certified lower bound) and the rest of the ensemble.
car_c0_fix.py Tests the bound size(c0) <= 2 tau - r' (r' = number of components of the split graph) for the first c0, for all 24 decodings (four selection rules, three residual rules, two repairs) and for the repaired c0 of version 0.1.3 stage by stage. On graphs with a known optimum it checks the bound exactly; on the others it marks each graph certified, refuted or undecided from a certified lower bound. The paper's c0 study uses its full run, python car/car_c0_fix.py.
car_regular.py Runs regular graphs of increasing degree.
car_bipartite.py Runs bipartite graphs, where the optimum is known exactly.
car_yes_instances.py Runs YES instances of the Khot–Regev reduction from Unique Games.
car_mechanism.py Studies which proved bounds apply to each graph and why the covers are good.
car_triangle_free.py Runs triangle-free graphs.
run_all.py Runs all the scripts above, quickly (--quick) or in full.

Examples:

python car/car_ratio.py
python car/car_bipartite.py
python car/car_scaling.py --quick
python car/car_triangle_free.py --quick
python car/car_c0_fix.py                                # full c0 study (about 35 minutes)

Code

  • Python implementation by Frank Vega.

License

  • MIT License.

Metadata

Release files for salvador 0.1.3

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

Source distribution (sdist)

Source distribution for salvador 0.1.3
File Size Uploaded
salvador-0.1.3.tar.gz 71.7 kB Details

Built distribution (wheel)

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

Total release size: 144.4 kB

Release files / salvador-0.1.3.tar.gz

Download URL salvador-0.1.3.tar.gz
Size 71.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d0e87503989d31fb13915c2f7c6398d9cf4e5728d0726398703fa410a8054e47
BLAKE2b-256 checksum
How to use checksums
191f20a8c3d256e46372a89ae3795cc72da25c89c11e096e3bdf39f0f01a2b51
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 Oct 16, 2026.

Transparency log

Release files / salvador-0.1.3-py3-none-any.whl

Download URL salvador-0.1.3-py3-none-any.whl
Size 72.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d34cda5b4caa08b4d7f94fbf71b2afa67d7df541b108ebbe532169f5631a3613
BLAKE2b-256 checksum
How to use checksums
32063f6bec2247c2c50aab234a2201892ff9f653a1d9bda0bb3cbbbe68ffa689
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 Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

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