KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SolutionCollector Class Reference

Helper class that collects solutions and keeps one with the best deviation. More...

Public Member Functions

 SolutionCollector (double aTarget)
 
void Add2RLookupResults (std::pair< RESISTANCE &, RESISTANCE & > aResults, std::function< double(double)> aValueFunc, std::function< RESISTANCE(RESISTANCE &)> aResultFunc)
 Add two solutions, based on single 2R buffer lookup, to the collector.
 
RESISTANCE GetBest ()
 Return the best collected combination, running the corresponding result_func.
 

Private Member Functions

void addSolution (double aValue, RESISTANCE *aFound, std::function< RESISTANCE(RESISTANCE &)> &aResultFunc)
 Add single solution to the collector.
 

Private Attributes

double m_target
 
double m_best_deviation = INFINITY
 
RESISTANCEm_best_found_resistance = nullptr
 
std::function< RESISTANCE(RESISTANCE &)> m_best_result_func
 

Detailed Description

Helper class that collects solutions and keeps one with the best deviation.

In order to avoid performing costly string operations too frequently, they are postponed until the very end, when we know the best combination.

Definition at line 45 of file resistor_substitution_utils.cpp.

Constructor & Destructor Documentation

◆ SolutionCollector()

SolutionCollector::SolutionCollector ( double  aTarget)
inline

Definition at line 53 of file resistor_substitution_utils.cpp.

Member Function Documentation

◆ Add2RLookupResults()

void SolutionCollector::Add2RLookupResults ( std::pair< RESISTANCE &, RESISTANCE & >  aResults,
std::function< double(double)>  aValueFunc,
std::function< RESISTANCE(RESISTANCE &)>  aResultFunc 
)
inline

Add two solutions, based on single 2R buffer lookup, to the collector.

Parameters
aResultsare the resistances found in 2R buffer
aValueFunctransforms value from aResults into final value of the combination
aResultFunctransforms RESISTANCE instance from aResults into final instance

Definition at line 62 of file resistor_substitution_utils.cpp.

References addSolution().

Referenced by RES_EQUIV_CALC::calculate2RSolution(), RES_EQUIV_CALC::calculate3RSolution(), and RES_EQUIV_CALC::calculate4RSolution().

◆ addSolution()

void SolutionCollector::addSolution ( double  aValue,
RESISTANCE aFound,
std::function< RESISTANCE(RESISTANCE &)> &  aResultFunc 
)
inlineprivate

Add single solution to the collector.

Parameters
aValueis a value of the combination in Ohms
aFoundis the corresponding RESISTANCE found in 2R buffer
aResultFuncis a function calculating final result (RESISTANCE instance) for this combination

Definition at line 90 of file resistor_substitution_utils.cpp.

References std::abs(), m_best_deviation, m_best_found_resistance, m_best_result_func, and m_target.

Referenced by Add2RLookupResults().

◆ GetBest()

RESISTANCE SolutionCollector::GetBest ( )
inline

Return the best collected combination, running the corresponding result_func.

Definition at line 73 of file resistor_substitution_utils.cpp.

References m_best_found_resistance, and m_best_result_func.

Referenced by RES_EQUIV_CALC::calculate2RSolution(), RES_EQUIV_CALC::calculate3RSolution(), and RES_EQUIV_CALC::calculate4RSolution().

Member Data Documentation

◆ m_best_deviation

double SolutionCollector::m_best_deviation = INFINITY
private

Definition at line 103 of file resistor_substitution_utils.cpp.

Referenced by addSolution().

◆ m_best_found_resistance

RESISTANCE* SolutionCollector::m_best_found_resistance = nullptr
private

Definition at line 104 of file resistor_substitution_utils.cpp.

Referenced by addSolution(), and GetBest().

◆ m_best_result_func

std::function<RESISTANCE( RESISTANCE& )> SolutionCollector::m_best_result_func
private

Definition at line 105 of file resistor_substitution_utils.cpp.

Referenced by addSolution(), and GetBest().

◆ m_target

double SolutionCollector::m_target
private

Definition at line 102 of file resistor_substitution_utils.cpp.

Referenced by addSolution().


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