1#ifndef FSTSEARCHEXHAUSTIVE_H
2#define FSTSEARCHEXHAUSTIVE_H
107template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
110 typedef Search<RETURNTYPE,DIMTYPE,SUBSET,CRITERION>
parent;
119 notify(
"Search_Exhaustive constructor.");
125 virtual bool search(
const DIMTYPE target_d, RETURNTYPE &result,
const PSubset sub,
const PCriterion crit, std::ostream& os=std::cout)
override;
127 virtual std::ostream&
print(std::ostream& os)
const override {
128 os <<
"Exhaustive search [";
129 if(
_engine->is_threaded()) os <<
"Search_Exhaustive(threads="<<
_engine->get_max_threads()<<
")";
130 else os <<
"Search_Exhaustive()";
138template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
142 notify(
"Search_Exhaustive::search().");
146 const DIMTYPE n=sub->get_n();
153 sos <<
"---------------------------------------" << std::endl;
154 sos <<
"Starting " << *
this << std::endl;
155 sos <<
"with Criterion: " << *crit << std::endl;
156 if(target_d==0) sos <<
"Subset size to be optimized." << std::endl;
else sos <<
"Target subset size set to: " << target_d << std::endl;
157 sos << std::endl << std::flush;
163 DIMTYPE cardinality=1;
164 if(target_d>0) {cardinality=target_d; t_to=target_d;}
165 bool generate_first=
true;
166 bool generator_failed=
false;
167 PSubset gen_sub(
new SUBSET(n));
168 typename EVALUATORENGINE::Generator generator=[&gen_sub,&cardinality,&generate_first,&generator_failed,t_to](SUBSET &cand)->
bool {
171 if(cardinality>t_to)
return false;
172 gen_sub->deselect_all();
173 if(!gen_sub->getFirstCandidateSubset(cardinality,
false)) {generator_failed=
true;
return false;}
174 generate_first=
false;
175 cand.stateless_copy(*gen_sub);
178 if(gen_sub->getNextCandidateSubset()) {cand.stateless_copy(*gen_sub);
return true;}
189 std::ostream *pos=&os;
192 on_best=[
this,psw,pos](
const int ,
const unsigned long long ,
const RETURNTYPE val,
const PSubset &bsub) {
194 sos <<
"new MAXCRIT="<<val<<
", " << *bsub << std::endl << *psw << std::endl << std::endl << std::flush;
200 if(generator_failed || !found)
return false;
204 sos <<
"......................................." << std::endl;
205 if(
_engine->is_threaded()) sos <<
"Search_Exhaustive_Threaded() search finished. " << swatch << std::endl;
206 else sos <<
"Search_Exhaustive() search finished. " << swatch << std::endl;
207 sos <<
"Search result: "<< std::endl << *sub << std::endl <<
"Criterion value: " << result << std::endl << std::endl << std::flush;
Abstract candidate-evaluation strategy: the seam through which one search algorithm body evaluates ca...
Implements sequential in-line evaluation of a criterion on a set of subset candidates.
Implements sequential in-line evaluation of a criterion on a set of subset candidates.
Definition candidate_evaluator_sequential.hpp:62
Abstract candidate-evaluation strategy (sequential-inline vs. thread-pooled).
Definition candidate_evaluator.hpp:86
std::function< bool(SUBSET &)> Generator
fills sub with the next candidate, returns false when no candidate remains (in the threaded implement...
Definition candidate_evaluator.hpp:92
std::function< bool(const RETURNTYPE, const PSubset &, const RETURNTYPE, const PSubset &)> BetterPredicate
returns true if (value,subset) is better than (best value,best subset) - encodes per-search tie-break...
Definition candidate_evaluator.hpp:99
std::function< void(const int, const unsigned long long, const RETURNTYPE, const PSubset &)> BestCallback
Definition candidate_evaluator.hpp:97
Implements exhaustive (optimal) search yielding optimal feature subset with respect to chosen criteri...
Definition search_exhaustive.hpp:108
virtual std::ostream & print(std::ostream &os) const override
writes a human-readable identification of the search and its configuration; base default writes nothi...
Definition search_exhaustive.hpp:127
PEvaluatorEngine _engine
the injected candidate-evaluation engine (defaults to sequential)
Definition search_exhaustive.hpp:135
std::shared_ptr< EVALUATORENGINE > PEvaluatorEngine
shared pointer to the evaluation engine
Definition search_exhaustive.hpp:114
std::shared_ptr< CRITERION > PCriterion
shared pointer to the criterion being optimized
Definition search_exhaustive.hpp:111
Search_Exhaustive(PEvaluatorEngine engine=PEvaluatorEngine())
Constructs the search with the given candidate-evaluation engine; a default-constructed engine falls ...
Definition search_exhaustive.hpp:117
std::shared_ptr< SUBSET > PSubset
shared pointer to a feature subset
Definition search_exhaustive.hpp:112
virtual bool search(const DIMTYPE target_d, RETURNTYPE &result, const PSubset sub, const PCriterion crit, std::ostream &os=std::cout) override
evaluates every subset of the requested size (every subset of any size from 1 to n if target_d==0) an...
Definition search_exhaustive.hpp:139
Candidate_Evaluator< RETURNTYPE, DIMTYPE, SUBSET, CRITERION > EVALUATORENGINE
the candidate-evaluation engine type (sequential or threaded)
Definition search_exhaustive.hpp:113
Search< RETURNTYPE, DIMTYPE, SUBSET, CRITERION > parent
base class: the generic search interface
Definition search_exhaustive.hpp:110
bool output_normal() const
true unless output detail is SILENT
Definition search.hpp:159
void report(std::ostream &os, const msgbuf &m) const
delivers one pre-formatted progress message: to the observer if attached, otherwise as syncout text t...
Definition search.hpp:170
bool result_tracker_active() const
true if a result tracker was assigned via enable_result_tracking() and not since disabled
Definition search.hpp:155
OutputDetail get_output_detail() const
the currently configured output detail level
Definition search.hpp:158
std::shared_ptr< Result_Tracker< RETURNTYPE, SUBSET > > PResultTracker
shared pointer to the result tracker enabled via enable_result_tracking()
Definition search.hpp:128
PResultTracker _tracker
the assigned result tracker, or null (see enable_result_tracking()/result_tracker_active())
Definition search.hpp:179
void report_solution(std::ostream &os, const RETURNTYPE value, const SUBSET &sub, const msgbuf &m) const
like report(), for sites announcing a new (sub-)solution; fires on_solution instead
Definition search.hpp:175
Simple stopwatch to measure run time of search algorithms.
Definition stopwatch.hpp:92
Message accumulator for Search::report() - collects one progress message exactly as an std::ostringst...
Definition search.hpp:87
FST4 specific error passing class.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
Defines interface for classes that enable collecting multiple results.
Defines interface for search method implementations.
Simple tool to measure run time.