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

Collector that stores accepted solutions in an Aleph list. More...

#include <state_search_common.H>

Collaboration diagram for Aleph::SearchSolutionCollector< Solution >:
[legend]

Public Types

using Solution_Type = Solution
 Type of collected solutions.
 
using Container_Type = DynList< Solution >
 Internal container type.
 

Public Member Functions

 SearchSolutionCollector ()=default
 Build a collector with no limit.
 
 SearchSolutionCollector (const size_t max_solutions)
 Build a collector that stops after max_solutions.
 
 SearchSolutionCollector (const SearchSolutionCollector &other)=default
 Copy the solutions and the limit of another collector.
 
 SearchSolutionCollector (SearchSolutionCollector &&other) noexcept
 Take the solutions of another collector, which is left empty, with the same limit.
 
SearchSolutionCollector & operator= (const SearchSolutionCollector &other)=default
 Copy the solutions and the limit of another collector.
 
SearchSolutionCollector & operator= (SearchSolutionCollector &&other) noexcept
 Exchange this collector with another, which is left with the previous solutions and limit of this one.
 
void swap (SearchSolutionCollector &other) noexcept
 Exchange in O(1) the solutions and the limits of this collector and another.
 
bool operator() (const Solution &solution)
 Append one solution and report whether enumeration should continue.
 
void clear () noexcept
 Remove all collected solutions.
 
size_t size () const noexcept
 Number of collected solutions.
 
bool is_empty () const noexcept
 Return true if no solution has been collected.
 
const Container_Type & solutions () const noexcept
 Access the collected solutions.
 
Container_Type & solutions () noexcept
 Mutable access to the collected solutions.
 

Private Attributes

Container_Type solutions_
 
size_t count_ = 0
 
size_t limit_ = Search_Unlimited
 

Detailed Description

template<typename Solution>
class Aleph::SearchSolutionCollector< Solution >

Collector that stores accepted solutions in an Aleph list.

This is a small adapter for DFS/backtracking enumeration. It appends each accepted solution to an internal DynList and can optionally stop after a user-specified number of collected solutions.

Template Parameters
SolutionType of solution to collect.

Definition at line 386 of file state_search_common.H.

Member Typedef Documentation

◆ Container_Type

template<typename Solution >
using Aleph::SearchSolutionCollector< Solution >::Container_Type = DynList<Solution>

Internal container type.

Definition at line 392 of file state_search_common.H.

◆ Solution_Type

template<typename Solution >
using Aleph::SearchSolutionCollector< Solution >::Solution_Type = Solution

Type of collected solutions.

Definition at line 390 of file state_search_common.H.

Constructor & Destructor Documentation

◆ SearchSolutionCollector() [1/4]

template<typename Solution >
Aleph::SearchSolutionCollector< Solution >::SearchSolutionCollector ( )
default

Build a collector with no limit.

◆ SearchSolutionCollector() [2/4]

template<typename Solution >
Aleph::SearchSolutionCollector< Solution >::SearchSolutionCollector ( const size_t  max_solutions)
inlineexplicit

Build a collector that stops after max_solutions.

Parameters
max_solutionsMaximum number of solutions to store.

Definition at line 400 of file state_search_common.H.

References ah_invalid_argument_if, and Aleph::SearchSolutionCollector< Solution >::limit_.

◆ SearchSolutionCollector() [3/4]

template<typename Solution >
Aleph::SearchSolutionCollector< Solution >::SearchSolutionCollector ( const SearchSolutionCollector< Solution > &  other)
default

Copy the solutions and the limit of another collector.

Parameters
[in]othercollector to copy.
Exceptions
std::bad_allocif the solutions cannot be copied.

◆ SearchSolutionCollector() [4/4]

template<typename Solution >
Aleph::SearchSolutionCollector< Solution >::SearchSolutionCollector ( SearchSolutionCollector< Solution > &&  other)
inlinenoexcept

Take the solutions of another collector, which is left empty, with the same limit.

The implicit move took the list but copied the count: the moved-from collector then reported solutions that it no longer had, and asked to stop at the first new one once the count had reached the limit.

Parameters
[in,out]othercollector to move from.
Note
Complexity: O(1).

Definition at line 422 of file state_search_common.H.

Member Function Documentation

◆ clear()

template<typename Solution >
void Aleph::SearchSolutionCollector< Solution >::clear ( )
inlinenoexcept

◆ is_empty()

template<typename Solution >
bool Aleph::SearchSolutionCollector< Solution >::is_empty ( ) const
inlinenoexcept

Return true if no solution has been collected.

Definition at line 479 of file state_search_common.H.

References Aleph::SearchSolutionCollector< Solution >::count_.

Referenced by Moved_From_Case< Collector >::is_empty(), TEST(), and Moved_From_Case< Collector >::use().

◆ operator()()

template<typename Solution >
bool Aleph::SearchSolutionCollector< Solution >::operator() ( const Solution &  solution)
inline

◆ operator=() [1/2]

template<typename Solution >
SearchSolutionCollector & Aleph::SearchSolutionCollector< Solution >::operator= ( const SearchSolutionCollector< Solution > &  other)
default

Copy the solutions and the limit of another collector.

Parameters
[in]othercollector to copy.
Returns
this collector.
Exceptions
std::bad_allocif the solutions cannot be copied.

◆ operator=() [2/2]

template<typename Solution >
SearchSolutionCollector & Aleph::SearchSolutionCollector< Solution >::operator= ( SearchSolutionCollector< Solution > &&  other)
inlinenoexcept

Exchange this collector with another, which is left with the previous solutions and limit of this one.

Parameters
[in,out]othercollector to move from.
Returns
this collector.
Note
Complexity: O(1).

Definition at line 440 of file state_search_common.H.

References Aleph::SearchSolutionCollector< Solution >::swap().

◆ size()

template<typename Solution >
size_t Aleph::SearchSolutionCollector< Solution >::size ( ) const
inlinenoexcept

◆ solutions() [1/2]

template<typename Solution >
const Container_Type & Aleph::SearchSolutionCollector< Solution >::solutions ( ) const
inlinenoexcept

◆ solutions() [2/2]

template<typename Solution >
Container_Type & Aleph::SearchSolutionCollector< Solution >::solutions ( )
inlinenoexcept

Mutable access to the collected solutions.

Definition at line 491 of file state_search_common.H.

References Aleph::SearchSolutionCollector< Solution >::solutions_.

◆ swap()

template<typename Solution >
void Aleph::SearchSolutionCollector< Solution >::swap ( SearchSolutionCollector< Solution > &  other)
inlinenoexcept

Exchange in O(1) the solutions and the limits of this collector and another.

Parameters
[in,out]othercollector to exchange with.

Definition at line 450 of file state_search_common.H.

References Aleph::SearchSolutionCollector< Solution >::count_, Aleph::SearchSolutionCollector< Solution >::limit_, Aleph::SearchSolutionCollector< Solution >::solutions_, and Aleph::DynList< T >::swap().

Referenced by Aleph::SearchSolutionCollector< Solution >::operator=().

Member Data Documentation

◆ count_

◆ limit_

◆ solutions_


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