ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Approximation.h File Reference

The approximation algorithms of section 19.2 and of the exercises 19.6 and 19.8. More...

#include "ADS/Contract.h"
#include "ADS/complexity/Problems.h"
#include "ADS/graph/MinimumSpanningTree.h"
#include <algorithm>
#include <cstddef>
#include <limits>
#include <numeric>
#include <utility>
#include <vector>
#include "ADS/intractable/impl/Approximation.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Functions

std::vector< int > ADS::firstFit (const std::vector< long > &A, long k, bool decreasing=false)
 the box of each object, the first one with room for it (ff), the objects in the order given or, if decreasing, in decreasing order of volume (ffd); the boxes are \( 0 , 1 , \ldots \)
template<class T>
T ADS::tourCost (const std::vector< std::vector< T > > &D, const Nodes &S)
 the cost \( \sum_i D[ S[ i ] ][ S[ ( i + 1 ) \bmod n ] ] \) of the circuit \( S \) of the distances \( D \)
template<class T>
Nodes ADS::deltaTsp (const std::vector< std::vector< T > > &D)
 the circuit of the nodes of a minimum spanning tree of the complete graph of the symmetric distances \( D \) in preorder from 0, the children by increasing name: at most twice the optimum if \( D \) is triangular
std::vector< std::vector< long > > ADS::tspGap (const Adjacency &G, long s)
 the distances of Theorem 19.2: 1 on the edges of \( G \), \( s n \) elsewhere; their optimum is \( n \) if \( G \) has a Hamiltonian circuit and more than \( s n \) otherwise
std::pair< long, Nodes > ADS::apSubsetSum (const std::vector< long > &A, long k, int h)
 the sum, at most \( k \), and the places of \( A \) of the best set found from the sets of at most \( h \) elements, \( \epsilon = 1 / ( h + 1 ) \); the sets of (1) in the order of the text, by size and then lexicographically on \( A \) in decreasing order
std::pair< long, Nodes > ADS::knapsackApprox (const std::vector< long > &p, const std::vector< long > &v, long C, double eps)
 the best profit and the objects of an \( \epsilon \)-approximation of KNAPSACK, profits \( p \) and volumes \( v \) within \( C \), by the rounded profits
Nodes ADS::vertexCoverApprox (const Adjacency &G)
 both ends of each edge \( [ u , v ] \), \( u < v \), whose ends are both out of \( S \), at most twice a minimum vertex cover; \( O( n^2 ) \) on the adjacency matrix

Detailed description

The approximation algorithms of section 19.2 and of the exercises 19.6 and 19.8.

An absolute approximation gives a feasible \( x' \) with \( | c( x' ) - c( x^* ) | / | c( x^* ) | \le e \), \( e \) a constant of the algorithm; an \( \epsilon \)-approximation takes \( \epsilon \) in input, in a time polynomial in the size and in general exponential in \( 1 / \epsilon \).

  • firstFit(), ff and, on the volumes in decreasing order, ffd for BIN PACKING: no two boxes are filled at most half, so that \( N < 2 N^* \);
  • deltaTsp() for the salesman with the triangle inequality: the nodes of a minimum spanning tree in preorder, the tree walked twice with the cities already visited skipped, at most twice the optimum (the bound is reached by the two concentric polygons of figure 19.3);
  • tspGap(): the distances of Theorem 19.2, 1 on the edges of \( G \) and \( s n \) elsewhere, so that an approximation within \( s \) would decide HAMILTONIAN CIRCUIT;
  • apSubsetSum(), the \( \epsilon \)-approximation of the optimization SUBSET SUM with \( \epsilon = 1 / ( h + 1 ) \): each set of at most \( h \) elements, completed greedily on the elements in decreasing order, \( O( h n^{h+1} ) \);
  • vertexCoverApprox(), the two ends of each edge not yet covered, a matching whose ends are at most twice a minimum cover (exercise 19.6);
  • knapsackApprox(), an \( \epsilon \)-approximation of KNAPSACK in time polynomial in \( n \) and \( 1 / \epsilon \) (exercise 19.8): the profits divided by \( K = \epsilon p_{\max} / n \) and rounded down, and the least volume of each rounded profit by dynamic programming, at least \( ( 1 - \epsilon ) \) times the optimum in \( O( n^3 / \epsilon ) \).

The contracts [see Contract.h]: the volumes, the profits and the sums are not negative, the distances square and symmetric, and the triangle inequality that the bound of deltaTsp() rests on is an audit, \( O( n^3 ) \); each solution returned is checked as feasible. The operations are defined in Approximation.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 19.2 and exercises 19.6, 19.8, https://algoritmicamente.it/materiali/libro/capitoli/cap19.pdf
D. S. Johnson, A. Demers, J. D. Ullman, M. R. Garey, R. L. Graham, Worst-case performance bounds for simple one-dimensional packing algorithms, SIAM Journal on Computing 3(4), 299-325, 1974, doi:10.1137/0203025
D. J. Rosenkrantz, R. E. Stearns, P. M. Lewis, An analysis of several heuristics for the traveling salesman problem, SIAM Journal on Computing 6(3), 563-581, 1977, doi:10.1137/0206041
O. H. Ibarra, C. E. Kim, Fast approximation algorithms for the knapsack and sum of subset problems, Journal of the ACM 22(4), 463-468, 1975, doi:10.1145/321906.321909
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa