|
ADS
Algorithms and Data Structures
|
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 | |
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 \).
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.