ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BranchAndBound.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File BranchAndBound.h --------------------------*/
3/*--------------------------------------------------------------------------*/
75/*--------------------------------------------------------------------------*/
76/*----------------------------- DEFINITIONS --------------------------------*/
77/*--------------------------------------------------------------------------*/
78
79#ifndef __ADS_BranchAndBound
80 #define __ADS_BranchAndBound
81/* self-identification: #endif constant */
82
83/*--------------------------------------------------------------------------*/
84/*------------------------------ INCLUDES ----------------------------------*/
85/*--------------------------------------------------------------------------*/
86
87#include "ADS/Contract.h"
88#include "ADS/Modification.h"
89#include "ADS/Portable.h"
90#include "ADS/Wide.h"
95
96#include <algorithm>
97#include <concepts>
98#include <cstddef>
99#include <limits>
100#include <numeric>
101#include <type_traits>
102#include <utility>
103#include <vector>
104
105/*--------------------------------------------------------------------------*/
106/*--------------------------- NAMESPACE ------------------------------------*/
107/*--------------------------------------------------------------------------*/
108
109namespace ADS
110{
111
112/*--------------------------------------------------------------------------*/
113/*---------------------------- THE INCUMBENT -------------------------------*/
114/*--------------------------------------------------------------------------*/
115
117template< class T >
119
120/*--------------------------------------------------------------------------*/
121/*------------------------------ BOUNDS ------------------------------------*/
122/*--------------------------------------------------------------------------*/
123
125enum class TspBound {
128 };
129
143template< class T >
144T spanningTreeWeight( const std::vector< std::vector< T > > & D ,
145 const Nodes & V );
146
161template< class T >
162T oneTree( const std::vector< std::vector< T > > & D , int r );
163
194template< class T >
195T tspLowerBound( const std::vector< std::vector< T > > & D , const Nodes & S ,
196 TspBound how = TspBound::BOOK );
197
198/*--------------------------------------------------------------------------*/
199/*------------------------------- BBTSP ------------------------------------*/
200/*--------------------------------------------------------------------------*/
201
232template< class T >
233std::pair< T , Nodes >
234bbTsp( const std::vector< std::vector< T > > & D , const Nodes & start = {} ,
235 TspBound how = TspBound::BOOK , long * generated = nullptr );
236
240template< class T , class O >
241std::pair< T , Nodes > bbTsp( const std::vector< std::vector< T > > & D ,
242 const Nodes & start , TspBound how ,
243 long * generated , O & o );
244
245/*--------------------------------------------------------------------------*/
246/*------------------------------ LITTLE ------------------------------------*/
247/*--------------------------------------------------------------------------*/
248
290template< class T >
291std::pair< T , Nodes > littleTsp( const std::vector< std::vector< T > > & D ,
292 long * generated = nullptr );
293
294/*--------------------------------------------------------------------------*/
295/*----------------------- CLIQUE AND KNAPSACK ------------------------------*/
296/*--------------------------------------------------------------------------*/
297
325inline std::pair< long , Nodes > maxWeightClique( const Adjacency & G ,
326 const std::vector< long > & w ,
327 long * generated = nullptr );
328
332template< class O >
333std::pair< long , Nodes > maxWeightClique( const Adjacency & G ,
334 const std::vector< long > & w ,
335 long * generated , O & o );
336
365inline std::pair< long , Nodes > knapsackBB( const std::vector< long > & p ,
366 const std::vector< long > & v ,
367 long C ,
368 long * generated = nullptr );
369
373template< class O >
374std::pair< long , Nodes > knapsackBB( const std::vector< long > & p ,
375 const std::vector< long > & v , long C ,
376 long * generated , O & o );
377
405inline std::pair< long , Nodes >
406knapsackBacktrack( const std::vector< long > & p ,
407 const std::vector< long > & v , long C ,
408 long * generated = nullptr );
409
428inline std::pair< long ,
429 Nodes > knapsackGreedy( const std::vector< long > & p ,
430 const std::vector< long > & v ,
431 long C );
432
433/*--------------------------------------------------------------------------*/
434
435} // end( namespace ADS )
436
437/*--------------------------------------------------------------------------*/
438/*-------------------------- IMPLEMENTATION --------------------------------*/
439/*--------------------------------------------------------------------------*/
440
441#include "ADS/intractable/impl/BranchAndBound.tpp"
442
443/*--------------------------------------------------------------------------*/
444
445#endif /* BranchAndBound.h included */
446
447/*--------------------------------------------------------------------------*/
448/*----------------------- End File BranchAndBound.h ------------------------*/
449/*--------------------------------------------------------------------------*/
The approximation algorithms of section 19.2 and of the exercises 19.6 and 19.8.
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The PRIORITYQUEUE [see PriorityQueue.h] on a Fibonacci heap, the structure that section 11....
The minimum spanning tree of an unoriented connected graph with weights on the edges (section 14....
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The problems in NP of chapter 18, each with its polynomial certificate, which checks a proposed solut...
The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of...
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
mod::Assigned< int, T > IncumbentChanged
the best value found so far by a search changed, the handle 0
Definition BranchAndBound.h:118
std::pair< long, Nodes > 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...
std::pair< long, Nodes > 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,...
T spanningTreeWeight(const std::vector< std::vector< T > > &D, const Nodes &V)
the weight of a minimum spanning tree of the nodes in , by the symmetric distances
std::pair< T, Nodes > 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 no...
std::pair< T, Nodes > 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 tre...
TspBound
the lower bound of a circuit that starts with
Definition BranchAndBound.h:125
std::pair< long, Nodes > 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 p...
T tspLowerBound(const std::vector< std::vector< T > > &D, const Nodes &S, TspBound how=TspBound::BOOK)
a lower bound of the circuits that start with the path , the cost of the circuit if has all the cit...
T oneTree(const std::vector< std::vector< T > > &D, int r)
the weight of a minimum 1-tree of : a minimum spanning tree of the other nodes and the two least edge...
std::pair< long, Nodes > maxWeightClique(const Adjacency &G, const std::vector< long > &w, long *generated=nullptr)
the weight and the nodes of a clique of of largest weight (MAXIMUM WEIGHT CLIQUE),...
@ ONE_TREE
the bound of the 1-tree (exercise 19.10)
Definition BranchAndBound.h:127
@ BOOK
the bound of the text, by the least edges of each city
Definition BranchAndBound.h:126
Definition ADT.h:96
std::vector< int > Nodes
a set, a path
Definition Problems.h:86
std::vector< std::vector< bool > > Adjacency
an adjacency
Definition Problems.h:83