|
ADS
Algorithms and Data Structures
|
The heuristics of section 19.4 and of the exercises 19.13 and 19.16 to 19.19: feasible solutions, neither optimal nor approximate, greedy or by local search. More...
#include "ADS/Contract.h"#include "ADS/complexity/Problems.h"#include "ADS/graph/MinimumSpanningTree.h"#include "ADS/intractable/Approximation.h"#include "ADS/mfset/MFSet.h"#include "ADS/string/Alignment.h"#include <algorithm>#include <cstddef>#include <cstdlib>#include <numeric>#include <set>#include <string>#include <utility>#include <vector>#include "ADS/intractable/impl/Heuristics.tpp"Go to the source code of this file.
Classes | |
| class | ADS::Buckets |
| the structure with buckets of exercise 19.17: for \( k = 0 , 1 \) the nodes by the number \( h \) of their edges to \( V_k \), bucket( k , h ), its size dim( k , h ), and the least and largest bucket not empty; a node leaves a bucket in \( O( 1 ) \) by its place in it More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T> | |
| std::pair< std::vector< std::pair< int, int > >, Nodes > | ADS::greedyTsp (const std::vector< std::vector< T > > &D) |
| the edges chosen, in the order of insertion, the last one closing the chain, and the circuit from 0, for the symmetric distances \( D \) of \( n \ge 3 \) cities | |
| Nodes | ADS::twoOptMove (Nodes pi, int i, int j) |
| the circuit of \( I_2( \pi ) \) without the edges \( ( \pi[ i ] , \pi[ i + 1 ] ) \) and \( ( \pi[ j ] , \pi[ j + 1 ] ) \), \( 0 \le i < j < n \), not consecutive: the stretch \( \pi[ i + 1 .. j ] \) reversed | |
| template<class T> | |
| Nodes | ADS::twoOpt (const std::vector< std::vector< T > > &D, Nodes pi, std::vector< T > *trace=nullptr) |
| the local search on \( I_2 \) from \( \pi \), for the symmetric distances \( D \), taking the best circuit of the neighborhood while it improves; the costs of the circuits visited go to *trace, if given | |
| long | ADS::kOptNeighbors (int n, int k) |
| the size of \( I_k( \pi ) \) on \( n \ge 3 \) nodes: the circuits that share exactly \( n - k \) edges with \( \pi \), by enumeration of all the circuits, \( O( n! ) \) | |
| long | ADS::kOptNeighbours (int n, int k) |
| the former name of kOptNeighbors(), kept for the code that uses it | |
| std::vector< int > | ADS::partitionLocalSearch (const std::vector< long > &A, std::vector< int > side) |
| the side, 0 or 1, of each element of \( A \), by the local search from side that moves an element or swaps two while the difference of the sums decreases, the best move first; \( O( n^2 ) \) each step | |
| std::vector< int > | ADS::minMaxGreedy (const Adjacency &G, int a, int b) |
| the side of each node of \( G \), \( n \) even, from \( a \) in \( V_0 \) and \( b \) in \( V_1 \) (the min-max-greedy of the book) | |
| int | ADS::cutSize (const Adjacency &G, const std::vector< int > &side) |
| the number of the edges across the two sides | |
| int | ADS::overlap (const std::string &a, const std::string &b) |
| the length of the longest suffix of \( a \) that is a prefix of \( b \), at most \( \min\{ |a| , |b| \} \): the whole of \( b \) if \( a \) ends with it, 0 if either is empty | |
| std::string | ADS::greedySuperstring (const std::vector< std::string > &P) |
| a common superstring of \( P \), by the greedy on the overlaps: the oriented edges \( ( i , j ) \) by decreasing overlap, each added if \( \mathit{out}[ i ] \) and \( \mathit{in}[ j ] \) are 0 and \( i , j \) are apart, and the path joined; the strings contained in another are dropped first | |
| std::pair< int, std::vector< std::pair< std::string, std::string > > > | ADS::starAlignment (const std::vector< std::string > &P) |
| the star alignment: the center \( h \), the string with the largest sum of the global scores against the others, and its global alignment with each string, the center against itself included; \( O( k^2 n^2 ) \) | |
| std::vector< int > | ADS::dsatur (const Adjacency &G) |
| the coloring by saturation degree: the color, from 0, of each node of \( G \), colored one at a time with the least color not on its neighbors, the next node the one with most distinct colors among its neighbors, then with most neighbors colored, then the first; \( O( n^3 ) \) | |
The heuristics of section 19.4 and of the exercises 19.13 and 19.16 to 19.19: feasible solutions, neither optimal nor approximate, greedy or by local search.
The contracts [see Contract.h]: the distances are square and symmetric, the graphs unoriented, the circuits permutations; each heuristic checks that its result is feasible, not that it is good, and the structure with buckets keeps its invariant at level 3. The operations are defined in Heuristics.tpp.