Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::BestSolution< Solution, Compare > Class Template Reference

Tracks the best solution seen so far according to a comparator. More...

#include <state_search_common.H>

Inheritance diagram for Aleph::BestSolution< Solution, Compare >:
[legend]

Public Types

using Solution_Type = Solution
 Type of stored solutions.
 
using Compare_Type = Compare
 Type of the comparison policy.
 

Public Member Functions

 BestSolution ()=default
 Build an empty incumbent tracker.
 
 BestSolution (Compare compare)
 Build a tracker with a custom comparator.
 
bool has_value () const noexcept
 Return true if an incumbent exists.
 
void clear () noexcept
 Remove the stored incumbent, if any.
 
const Solution & get () const
 Read the current incumbent.
 
Solution & get ()
 Mutable access to the current incumbent.
 
const Compare & compare () const noexcept
 Access the ordering functor used by this incumbent.
 
bool consider (const Solution &candidate)
 Consider a candidate by copy.
 
bool consider (Solution &&candidate)
 Consider a candidate by move.
 

Private Attributes

Compare compare_ = {}
 
std::optional< Solution > current_
 

Detailed Description

template<typename Solution, typename Compare = KeepFirstSolution<Solution>>
requires BinaryPredicate<Compare, Solution>
class Aleph::BestSolution< Solution, Compare >

Tracks the best solution seen so far according to a comparator.

The first candidate is always accepted. Later candidates replace the stored incumbent only if compare(candidate, incumbent) returns true.

Template Parameters
SolutionType of solution to track.
CompareBinary predicate used to order solutions.

Definition at line 458 of file state_search_common.H.

Member Typedef Documentation

◆ Compare_Type

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
using Aleph::BestSolution< Solution, Compare >::Compare_Type = Compare

Type of the comparison policy.

Definition at line 464 of file state_search_common.H.

◆ Solution_Type

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
using Aleph::BestSolution< Solution, Compare >::Solution_Type = Solution

Type of stored solutions.

Definition at line 462 of file state_search_common.H.

Constructor & Destructor Documentation

◆ BestSolution() [1/2]

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
Aleph::BestSolution< Solution, Compare >::BestSolution ( )
default

Build an empty incumbent tracker.

◆ BestSolution() [2/2]

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
Aleph::BestSolution< Solution, Compare >::BestSolution ( Compare  compare)
inlineexplicit

Build a tracker with a custom comparator.

Parameters
compareFunctor used to decide which solution is better.

Definition at line 472 of file state_search_common.H.

Member Function Documentation

◆ clear()

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
void Aleph::BestSolution< Solution, Compare >::clear ( )
inlinenoexcept

Remove the stored incumbent, if any.

Definition at line 484 of file state_search_common.H.

References Aleph::BestSolution< Solution, Compare >::current_.

◆ compare()

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
const Compare & Aleph::BestSolution< Solution, Compare >::compare ( ) const
inlinenoexcept

Access the ordering functor used by this incumbent.

Definition at line 510 of file state_search_common.H.

References Aleph::BestSolution< Solution, Compare >::compare_.

◆ consider() [1/2]

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
bool Aleph::BestSolution< Solution, Compare >::consider ( const Solution &  candidate)
inline

◆ consider() [2/2]

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
bool Aleph::BestSolution< Solution, Compare >::consider ( Solution &&  candidate)
inline

Consider a candidate by move.

Returns
true if the incumbent was updated.

Definition at line 532 of file state_search_common.H.

References Aleph::BestSolution< Solution, Compare >::compare_, Aleph::BestSolution< Solution, Compare >::current_, and Aleph::divide_and_conquer_partition_dp().

◆ get() [1/2]

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
Solution & Aleph::BestSolution< Solution, Compare >::get ( )
inline

Mutable access to the current incumbent.

Exceptions
std::runtime_errorif no incumbent has been stored yet.

Definition at line 502 of file state_search_common.H.

References ah_runtime_error_unless, and Aleph::BestSolution< Solution, Compare >::current_.

◆ get() [2/2]

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
const Solution & Aleph::BestSolution< Solution, Compare >::get ( ) const
inline

Read the current incumbent.

Exceptions
std::runtime_errorif no incumbent has been stored yet.

Definition at line 492 of file state_search_common.H.

References ah_runtime_error_unless, and Aleph::BestSolution< Solution, Compare >::current_.

Referenced by TEST().

◆ has_value()

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
bool Aleph::BestSolution< Solution, Compare >::has_value ( ) const
inlinenoexcept

Return true if an incumbent exists.

Definition at line 478 of file state_search_common.H.

References Aleph::BestSolution< Solution, Compare >::current_.

Referenced by Aleph::SearchResult< Solution, Compare >::found_solution(), and TEST().

Member Data Documentation

◆ compare_

template<typename Solution , typename Compare = KeepFirstSolution<Solution>>
Compare Aleph::BestSolution< Solution, Compare >::compare_ = {}
private

◆ current_


The documentation for this class was generated from the following file: