|
ADS
Algorithms and Data Structures
|
The branch-&-bound algorithms of section 19.3 and of the exercises 19.9 to 19.12: the enumeration of chapter 16 that skips the subtree of a sequence of choices \( S \) whose lower bound \( \mathit{lb}( S ) \) is not below the cost \( \mathit{minCost} \) of the best solution found so far. More...
#include "ADS/Contract.h"#include "ADS/Modification.h"#include "ADS/Portable.h"#include "ADS/Wide.h"#include "ADS/complexity/Problems.h"#include "ADS/graph/MinimumSpanningTree.h"#include "ADS/intractable/Approximation.h"#include "ADS/priority/FibonacciHeapPriorityQueue.h"#include <algorithm>#include <concepts>#include <cstddef>#include <limits>#include <numeric>#include <type_traits>#include <utility>#include <vector>#include "ADS/intractable/impl/BranchAndBound.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Typedefs | |
| template<class T> | |
| using | ADS::IncumbentChanged = mod::Assigned< int , T > |
| the best value found so far by a search changed, the handle 0 | |
Enumerations | |
| enum class | ADS::TspBound { ADS::TspBound::BOOK , ADS::TspBound::ONE_TREE } |
| the lower bound of a circuit that starts with \( S \) More... | |
Functions | |
| template<class T> | |
| T | ADS::spanningTreeWeight (const std::vector< std::vector< T > > &D, const Nodes &V) |
| the weight of a minimum spanning tree of the nodes in \( V \), by the symmetric distances \( D \) | |
| template<class T> | |
| T | ADS::oneTree (const std::vector< std::vector< T > > &D, int r) |
| the weight of a minimum 1-tree of \( r \): a minimum spanning tree of the other nodes and the two least edges of \( r \); each circuit is a 1-tree, so that the weight bounds the optimum from below | |
| template<class T> | |
| T | ADS::tspLowerBound (const std::vector< std::vector< T > > &D, const Nodes &S, TspBound how=TspBound::BOOK) |
| a lower bound \( \mathit{lb}( S ) \) of the circuits that start with the path \( S \), the cost of the circuit if \( S \) has all the cities or if \( n = 2 \), where the circuit through both cities is the only one | |
| template<class T> | |
| std::pair< T, Nodes > | ADS::bbTsp (const std::vector< std::vector< T > > &D, const Nodes &start={}, TspBound how=TspBound::BOOK, long *generated=nullptr) |
| the cost and a minimum circuit from 0, starting from the circuit start if not empty; the number of nodes of the tree of the choices generated, the root included, goes to *generated, if given | |
| template<class T, class O> | |
| std::pair< T, Nodes > | ADS::bbTsp (const std::vector< std::vector< T > > &D, const Nodes &start, TspBound how, long *generated, O &o) |
| bbTsp( D , start , how , generated ), each improvement of the best cost told to \( o \) as IncumbentChanged< T > | |
| template<class T> | |
| std::pair< T, Nodes > | ADS::littleTsp (const std::vector< std::vector< T > > &D, long *generated=nullptr) |
| the cost and a minimum circuit from 0, by the reduction of the matrix; the number of nodes of the tree generated goes to *generated, if given | |
| std::pair< long, Nodes > | ADS::maxWeightClique (const Adjacency &G, const std::vector< long > &w, long *generated=nullptr) |
| the weight and the nodes of a clique of \( G \) of largest weight (MAXIMUM WEIGHT CLIQUE), the weights \( w \) not negative; a set is extended by the candidates adjacent to all of it, and pruned when its weight and that of all the candidates is not above the best; the nodes generated go to *generated, if given | |
| template<class O> | |
| std::pair< long, Nodes > | ADS::maxWeightClique (const Adjacency &G, const std::vector< long > &w, long *generated, O &o) |
| maxWeightClique( G , w , generated ), each improvement of the best weight told to \( o \) as IncumbentChanged< long > | |
| std::pair< long, Nodes > | ADS::knapsackBB (const std::vector< long > &p, const std::vector< long > &v, long C, long *generated=nullptr) |
| the best profit and the objects of KNAPSACK by branch-&-bound, by places; the objects by decreasing profit per volume, each in and then out, pruned when the fractional knapsack of the rest does not beat the best; the nodes generated go to *generated, if given | |
| template<class O> | |
| std::pair< long, Nodes > | ADS::knapsackBB (const std::vector< long > &p, const std::vector< long > &v, long C, long *generated, O &o) |
| knapsackBB( p , v , C , generated ), each improvement of the best profit told to \( o \) as IncumbentChanged< long > | |
| std::pair< long, Nodes > | ADS::knapsackBacktrack (const std::vector< long > &p, const std::vector< long > &v, long C, long *generated=nullptr) |
| KNAPSACK by backtracking with the simple bound: the objects in their order, each in and then out, an object that does not fit skipped, and a node pruned when its profit plus the profits of all the objects still to decide does not beat the best; the nodes generated go to *generated. | |
| std::pair< long, Nodes > | ADS::knapsackGreedy (const std::vector< long > &p, const std::vector< long > &v, long C) |
| the greedy heuristic of KNAPSACK: the objects by decreasing profit per volume, each taken if it still fits; not optimal in general | |
The branch-&-bound algorithms of section 19.3 and of the exercises 19.9 to 19.12: the enumeration of chapter 16 that skips the subtree of a sequence of choices \( S \) whose lower bound \( \mathit{lb}( S ) \) is not below the cost \( \mathit{minCost} \) of the best solution found so far.
The worst case stays superpolynomial; the time in practice depends on the starting solution, on the rule of branch, on the bound and on the order of visit.
bbTsp() chooses the cities of the circuit one after the other from \( S[ 0 ] = 0 \), in increasing order, depth first. The bound of the text is
\[ \mathit{lb}( S ) = C_i + \left\lceil \Big( A + B + \sum_{h \notin S} D_h \Big) / 2 \right\rceil , \]
\( C_i \) the length of the path \( S[ 0 .. i ] \), \( A \) and \( B \) the least distances to \( S[ 0 ] \) and from \( S[ i ] \) of a city out of \( S \) (the text has from \( S[ 0 ] \), the same for symmetric distances), \( D_h \) the least distance into and out of \( h \) over all the cities, as in the example of the text (\( \mathit{lb} = 18 \) for \( S = 1 , 3 \) of figure 19.5). Two values of figure 19.6 do not follow from this formula, 21 for 1 2 3 and for 1 5 (it gives 19 and 20), and no rule on \( p \) and \( q \) found gives all the values of the figure; with the formula, from the circuit 1 4 3 2 5 of cost 21, the tree has 25 nodes instead of 23 (30 with no circuit to start from) and ends with the same circuit of cost 19. The bound of the 1-tree (exercise 19.10) replaces the sum by the weight of a minimum spanning tree of the cities out of \( S \), for the symmetric distances. littleTsp() (exercise 19.11, the algorithm of Little, Murty, Sweeney and Karel) branches on including or excluding an edge, the one of reduced cost 0 whose exclusion raises the bound the most, visits by least bound, and bounds by reducing the rows and the columns of the matrix of the distances to a least entry 0. maxWeightClique() (exercise 19.9) bounds by the weight of the candidates, knapsackBB() (exercise 19.12) by the fractional knapsack of chapter 14.
bbTsp(), maxWeightClique() and knapsackBB() take an observer \( o \) as a last argument too [see Modification.h], which receives IncumbentChanged< T > of the handle 0, from the old best cost (or profit) to the new one, at each improvement of the best solution found so far, before the search goes on: the costs it receives decrease strictly (the profits increase strictly), and the last one is the optimum returned, unless the circuit start given to bbTsp() is already optimal, when it receives nothing. The form with no observer runs the same search with no subject, whose events compile to nothing. littleTsp() has no such events, since it visits by least bound and the first circuit it completes is its only solution.
The contracts [see Contract.h]: the distances are square, symmetric for the bound of the 1-tree, the weights and the profits not negative and the volumes positive; each optimum returned is checked as feasible, with its cost. The operations are defined in BranchAndBound.tpp.