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.
 

Private Member Functions

void considerSolution (double aValue, RESISTANCE &aFound, std::function< RESISTANCE(RESISTANCE &)> &aResultFunc)
 

Static Private Member Functions

static int uniqueCount (const RESISTANCE &aRes)
 
static bool betterCandidate (const RESISTANCE &aCand, const RESISTANCE &aBest)
 

Private Attributes

double m_target
 
double m_best_deviation = INFINITY
 
std::optional< RESISTANCEm_best_solution
 

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 46 of file resistor_substitution_utils.cpp.

Constructor & Destructor Documentation

◆ SolutionCollector()

SolutionCollector::SolutionCollector ( double  aTarget)
inline

Definition at line 54 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 66 of file resistor_substitution_utils.cpp.

References considerSolution().

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

◆ betterCandidate()

static bool SolutionCollector::betterCandidate ( const RESISTANCE aCand,
const RESISTANCE aBest 
)
inlinestaticprivate

Definition at line 125 of file resistor_substitution_utils.cpp.

References RESISTANCE::name, RESISTANCE::parts, and uniqueCount().

Referenced by considerSolution().

◆ considerSolution()

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

◆ GetBest()

RESISTANCE SolutionCollector::GetBest ( )
inline

Return the best collected combination.

Definition at line 76 of file resistor_substitution_utils.cpp.

References m_best_solution.

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

◆ uniqueCount()

static int SolutionCollector::uniqueCount ( const RESISTANCE aRes)
inlinestaticprivate

Definition at line 103 of file resistor_substitution_utils.cpp.

References std::abs(), epsilon, and RESISTANCE::parts.

Referenced by betterCandidate().

Member Data Documentation

◆ m_best_deviation

double SolutionCollector::m_best_deviation = INFINITY
private

Definition at line 140 of file resistor_substitution_utils.cpp.

Referenced by considerSolution().

◆ m_best_solution

std::optional<RESISTANCE> SolutionCollector::m_best_solution
private

Definition at line 141 of file resistor_substitution_utils.cpp.

Referenced by considerSolution(), and GetBest().

◆ m_target

double SolutionCollector::m_target
private

Definition at line 139 of file resistor_substitution_utils.cpp.

Referenced by considerSolution().


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